1

Linux noob here. I have a 256MB VPS on Ubuntu 11.04 server and when I run "free -m" the result shows all memory being used (including the second line re: buffers/cache). I found this very strange, considering I only have 5 Apache processes running each chewing up about 20MB each. MYSQL is taking up 30MB. To my knowledge, and according to "top", I have no other memory hogs operating.

Settings that may be relevant:

PHP memory_limit = 32M
MYSQL key_buffer = 16M
Prefork MPM Maxclients = 10

So when I reviewed these settings, I naturally thought maxclients was too high, so I tried switching it to 5. Now not only does my memory still show as being 100% used, my website loads much, much slower, despite not getting any traffic aside from mine at the moment. I don't understand this. I thought a single Apache process handles all requests from a client received within the "KeepAliveTimeout" window, which I've set to 2 seconds. With my initial config. of 10 maxclients, my page load times are around .3ms, so a single process should handle that no problem, correct?

So next I went to an extreme level of 1 for maxclients. My memory is still at 100% usage and my site loads painfully slow. I'm a noob at a complete loss here. According to the many tutorials I've read on basic server setup, I should be good to go.

Help! Please!

Edit:
             total       used       free     shared    buffers     cached
Mem:           256        256          0          0          0          0
-/+ buffers/cache:        256          0
Swap:            0          0          0
Rilindo
  • 5,058
  • 5
  • 26
  • 46
user101570
  • 67
  • 7

2 Answers2

2

That is because Linux uses most of the memory as cache and returns parts of it as needed to any application you run.

So don't panic. You're fine. Change the MaxClients back to the defaults.

EDIT: it looks like you are running on OpenVZ. See David Schwartz response below.

Rilindo
  • 5,058
  • 5
  • 26
  • 46
  • Yes, but as I stated in my post, free -m is showing it all used in the second row (buffers/cache). Also, this doesn't explain why lowering the max clients hurts load times so considerably considering I'm currently the only client. I'm panicing! :) – user101570 Nov 25 '11 at 02:53
  • 1
    It might be help if you were to actually past the output of the free -m in your post. – Rilindo Nov 25 '11 at 02:55
  • And BTW, when you reduce your max clients, you reduce the number of requests you can pull for a specific web page. So if you have a web page with images and other individual files, request for those files will be queued up. That is probably why your site got very slow. – Rilindo Nov 25 '11 at 02:58
  • So Rilindo, I am wrong in my understanding that a single Apache process handles all requests for a given client within the window set by KeepAliveTimeout? I thought the whole point was to avoid having separate processes serving different requests to the same client for a given page load. – user101570 Nov 25 '11 at 03:01
1

You have no swap, which makes it very hard for the OS to conserve physical memory. Basically, it has no place to put data that will likely never be accessed but that it cannot prove will never be accessed. So it has no choice but to keep it in RAM.

Consider, for example, a service that starts when your server launches but that is never, ever accessed. It may link to a library that gets relocated. That relocation dirties code pages in memory. On startup, it will likely allocate some memory and modify its contents. With swap, after the service doesn't run for a long time, or when memory is tight, those pages can be evicted from memory and stored in swap. (Most likely never to be retrieved, but the kernel can't risk that -- consider a service like ssh!)

With no swap, the kernel has no way to evict dirty pages, even if they haven't been accessed for days. So precious physical memory gets filled with useless junk.

Update: Apparently, this is an artifact of OpenVZ. There is swap, and the memory numbers you are seeing are meaningless. Your performance problems may or may not be due to anything under your control.

David Schwartz
  • 31,215
  • 2
  • 53
  • 82
  • I noticed that too. So after doing some research, it looks like OP is on OpenVZ, which apparently does not show/support swap in the guest: http://forum.proxmox.com/threads/5883-How-to-monitor-OpenVZ-swap-memory-usage-under-proxmox – Rilindo Nov 25 '11 at 14:56
  • And from our own site: http://serverfault.com/questions/107764/centos-adding-swap-file-failed - note the comment from epic9x. – Rilindo Nov 25 '11 at 15:03
  • Even when I reboot, memory use goes straight to 100%. I've yet to see it below 100%. What would you recommend I do David? Should I look for a different VPS with Xen-based servers? I don't like the idea of not having any swap, and not being able to tell how much memory my system is using. How can I configure my server to avoid using too much RAM if I can't tell how much RAM is actually used? – user101570 Nov 25 '11 at 16:07
  • Ahh, yeah, OpenVZ doesn't give you an OS. Just a jail in which you can run processes. The output of `free` is basically meaningless. Essentially, the same problem I described in my answer is happening, but by design and in a place where you can't do anything about it. – David Schwartz Nov 25 '11 at 20:35