Gentoo Archives: gentoo-user

From: Jim <Jim@×××××××××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] anyone having apache2 memory issues
Date: Sat, 01 Apr 2006 20:19:54
Message-Id: 1143922309.11529.12.camel@keelie.localdomain
In Reply to: [gentoo-user] anyone having apache2 memory issues by Alan Bailward
1 On Fri, 2006-03-31 at 20:50 -0800, Alan Bailward wrote:
2 > Hey all. I recently swapped my apache 1.3 site (personal blog, albums,
3 > etc) over to apache 2 (stable) and all seemed to go well. However
4 > lately I've been having a lot of out of memory issues on the server.
5 > Even when memory is still available
6 <snip>
7
8 What output do you get from: top -b -n 1
9
10 For example, here is my apache output:
11
12 jim@keelie$ top -b -n 1
13 top - 11:48:06 up 2 days, 15:11, 2 users, load average: 0.00, 0.03,
14 0.04
15 Tasks: 88 total, 2 running, 86 sleeping, 0 stopped, 0 zombie
16 Cpu(s): 7.4% us, 5.0% sy, 0.0% ni, 86.2% id, 0.8% wa, 0.0% hi,
17 0.5% si
18 Mem: 2010484k total, 1678576k used, 331908k free, 264884k buffers
19 Swap: 522104k total, 136k used, 521968k free, 945556k cached
20
21 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22 15536 root 16 0 56784 10m 4864 S 0.0 0.6 0:00.16 apache2
23 16374 apache 16 0 57188 9816 3108 S 0.0 0.5 0:00.10 apache2
24 6481 apache 15 0 57172 9780 3100 S 0.0 0.5 0:00.02 apache2
25
26 Go through top and see what is sucking up your memory. Or you can use
27 gnome-system-monitor, which I like better.
28
29 Here is a little program I tossed together to free that cached memory.
30 Just run it and specify an amount of memory in MB. Do not run this as
31 root, a normal user is fine.
32
33
34 I have 2 GB and after running VMWare I run:
35
36 mem 1200
37
38 Which frees all that cached memory that VMWare sucked up. If you have <
39 1 GB, you should turn swap off before you run this, otherwise you might
40 just be allocating memory from swap and defeat the purpose.
41
42 Before you run the program, look at the output of free to see how much
43 you should try to free. For example,
44
45 jim@keelie$ free -m
46 total used free shared buffers cached
47 Mem: 1963 1643 319 0 258 923
48 -/+ buffers/cache: 461 1502
49 Swap: 509 0 509
50
51 I have 923 MB sitting in cache. So if I run:
52
53 jim@keelie$ mem 1200
54 allocating: 1200MB bytes of memory
55 allocated: 1258291200MB bytes of memory
56 freed 1258291200MB bytes of memory
57
58 I now have 1.2 GB free:
59
60 jim@keelie$ free -m
61 total used free shared buffers cached
62 Mem: 1963 715 1248 0 45 307
63 -/+ buffers/cache: 362 1600
64 Swap: 509 0 509
65
66 To compile the program, just do:
67 You can replace $CFLAGS with whatever you like, for example -O3.
68
69 jim@keelie$ gcc $CFLAGS -o mem mem.c
70 jim@keelie$ sudo cp mem /usr/bin
71
72
73
74 -------- BEGIN CUT --------
75 #include <stdlib.h>
76 #include <stdio.h>
77
78 int main(int argc, char* argv[])
79 {
80 char* ptr = 0;
81 int i = 0;
82 int size = 0;
83
84 if (argc != 2)
85 {
86 printf("Usage: %s SIZE\nwhere SIZE is the size of "
87 "memory to allocate in MB\n", argv[0]);
88 return 1;
89 }
90
91 /* get the size in MB from the command line */
92 size = atoi(argv[1]);
93
94 printf("allocating: %iMB bytes of memory\n", size);
95 ptr = (char*)malloc(1024 * 1024 * size);
96
97 if (ptr)
98 {
99 printf("allocated: %iMB bytes of memory\n", (1024 * 1024 * size));
100 for (i=0; i<(1024 * 1024 * size); i++)
101 {
102 ptr[i]=1;
103 }
104 free(ptr);
105 printf("freed %iMB bytes of memory\n", (1024 * 1024 * size));
106 }
107 else
108 printf("failed to allocate %iMB bytes of memory\n",
109 (1024 * 1024 * size));
110
111 return 0;
112 }
113 -------- END CUT --------
114
115 You might want to try:
116
117 # mem 225
118
119 Jim
120 --
121 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
122 I'm a geek, but I don't get it. 36-24-36 = -24. What's the significance?
123 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
124 Florida, USA, Earth, Solar System, Milky Way
125
126 --
127 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] anyone having apache2 memory issues Alexander Skwar <listen@×××××××××××××××.name>