You are not logged in.

#1 2011-01-21 16:50:29

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

How does swap work in a webserver scenario?

Here's the scenario:

I have server with 1GB ram, 1GB swap. It is running a number of php-processes, each occupying between 153MB-164MB of VIRT. Now sometimes, memory usage rises for some reason and it looks like one of the new (or existing?) php-processes is moved to swap, equaling to around 160MB of swap being used, roughly the size of one of the VIRT's.

The questions i have are:

1) How can i know if this is a php-process being moved?

2) How or when is it removed from swap again? For instance, right now memory usage is back to normal for a while (460MB/1000MB), but the same 160MB of swap seems to be used regardless. You'd say this isn't very efficient in terms of performance? There might be a timeout or something before a php-thread is closed, but what if this is actually an active website, which means it will keep being used indefinitely?


ᶘ ᵒᴥᵒᶅ

Offline

#2 2011-01-21 20:13:43

toofishes
Developer
From: Chicago, IL
Registered: 2006-06-06
Posts: 602
Website

Re: How does swap work in a webserver scenario?

First, VIRT is not the number you should be looking at, that is not at all indicative of actual memory usage. Use RES instead, with the caveat that a process that has been (partially) swapped out will have that amount subtracted. VIRT includes all sorts of things- the actual executables, shared libraries, etc. that are shared among all the programs on your system. Every PHP process is using the same libraries and executable, so you can't fairly count this stuff in every single process.

Your questions:
1) Use /proc/, namely the /proc/<pid>/smaps files. If you see anything other than "Swap:                  0 kB" in one of these files, one of the mappings of the process has been swapped out. I've wrote a tool to parse this stuff; they are probably out there as well.
2) If it is used, it comes back into memory. You are paying too much attention to what the kernel is good at- it doesn't *move* it back, it copies it back and leaves it in swap. That way, if it needs to get swapped out again and it hasn't changed, it doesn't have to write to disk at all.

Offline

#3 2011-01-23 12:17:46

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: How does swap work in a webserver scenario?

Missed this one, oops. Thanks toofishes that really helps, i'm going to look out for (or try to write) a script that compares those /proc/pid entries.


ᶘ ᵒᴥᵒᶅ

Offline

Board footer

Powered by FluxBB