3

I have a Centos 7 with a swap of 256 MB. I have at least 1GB o free RAM memory all the time and my CPU never gets over 60% of usage. But anytime I check the swap use it's using about 200 MB! My Swappiness is 30 and everything is running smoothly. But I am really curious what is going on with this Centos.

I am running LAMP on it and just that, nothing fancy. So, how do I get rid of this swap high usage? Is it possible to check who/what app is writing/reading from it?

As requested, free -m output:

              total        used        free      shared  buff/cache   available
Mem:           1991         171        1684           2         134        1771
Swap:           255         239          16

I discovered that Apache is swapping A LOT. I have many free memory, so why is it swapping? Check the image below.

image from http://tinypic.com/view.php?pic=r23kh2&s=8#.Vfr74PlViko

SO didnt allow me to post the image so i posted it in the link above.

  • free edit your question and show free -m output – c4f4t0r Sep 17 '15 at 17:11
  • Some pages may have been swapped out at an earlier time where memory usage was higher. If the swapped out pages have not been accessed since then, there is no reason to swap them in again. – kasperd Sep 17 '15 at 17:26
  • Around 10MB per apache process would suggest to me you are running prefork and likely mod_php or similar scripting languages behind it. This is normal for Apache if you are using php. You may be able to reduce the usage by optimizing your code. You can also reduce the average memory usage by reducing the MaxRequestsPerChild, but that may also reduce the performance of your server. – Aaron Sep 17 '15 at 17:47
  • why are you so concerned about space usage? As long as you are not seeing much disk activity due to thrashing, there is not much to worry about. Look at the si/so columns of thevmstat 10 output over time. If numbers remain at <1000 per 10s interval, you should simply leave it alone. Also, 8M worth of pages swapped out is not all that much for a process with 350 MB of virtual address space. – the-wabbit Sep 17 '15 at 17:59
  • I believe this is a learning experience for Gil to understand how and why swap is being utilized on their system, so they can rationalize decisions around capacity planning and determine risks or likelihood of OOM. Perhaps they are perfectly safe in their current configuration, but they would like to make an informed decision. – Aaron Sep 17 '15 at 18:53
-1

In short, this is normal behavior and beneficial to you. You have more memory for future I/O, while you probably would never ever use those pages from swap.

This is quite excellently answered here

It is a common misconception that a swap partition would somehow slow down your system. Not having a swap partition does not mean that the kernel won't evict pages from memory, it just means that the kernel has fewer choices in regards to which pages to evict.

| improve this answer | |
-1

This is where I would start

I will edit as we find out more about your system. I would post as a comment, but the formatting won't work.

What is using swap swap_usage.txt

Get actual (or close to actual) memory usage of each daemon py_mem.txt

You should also make note of any tmpfs filesystems that have old files in them. That is backed by swap and will swap out if you don't access the files.

[update] Based on your edit, around 10MB per apache process would suggest to me you are running prefork and likely mod_php or similar scripting languages behind it. This is common though not ideal for Apache if you are using php. You may be able to reduce the usage by optimizing your code. You can also reduce the average memory usage by reducing the MaxRequestsPerChild, but that may also reduce the performance of your server.

| improve this answer | |
  • Is it safe to me run your codes on a productio server? – Gil Sep 17 '15 at 17:42
  • 2
    You should always review a script and understand it before you run it on any system, dev or prod. If you do not feel comfortable then test it on a destructable/temporary throw away system first. I am meerly providing tools to answer your question instead of telling you not to worry about it. :-) – Aaron Sep 17 '15 at 17:43
  • 1
    @Gil they are not exactly his codes. py_mem is a small OSS project which has been around for years: github.com/pixelb/ps_mem – the-wabbit Sep 17 '15 at 17:46
  • Yes, I prefer to put snippets on my own server so that I can remove the liniks from the source and destination side as needed. Think pastebin, but my own. – Aaron Sep 17 '15 at 17:48
  • You are right @Aaron :) I am using prefork. Despite having lots of free memory apache is still swaping. I have 2GB of RAM, my average process uses 30MB, and I am using MaxRequestWorkers = 56. Is it good? Is there a problem with this value that I should change? – Gil Sep 17 '15 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.