Sizing your swap space (part 1)

May 14, 2007

The amount of memory that a program needs in order to actually get some work done is called its Resident Set Size (RSS). The total amount of virtual memory a program uses is called various things; ps uses VSZ (Virtual Size, presumably), for example.

The premise of paging things out to your swap space is that most programs don't need to use all of their memory all of the time; their RSS will be smaller than their VSZ. The difference can be pushed out to swap space in order to free up little-used pages to make room for another program's RSS.

(This is a simplification; not all of the inactive pages have to be pushed out to swap, since some of them are backed by files instead.)

So the simple answer is that your desired swap size is more or less the difference between the total virtual memory size of all of your programs and their total RSS, plus some margin for error. This gives you enough room to push all of the unproductive pages out of RAM to free it up for more productive uses.

(This does assume that your total RSS usage fits into your RAM, but if it doesn't you have bigger problems: you're trying to do too much for your machine and it's going to be thrashing to death.)

Unfortunately, modern operating systems don't really make it very easy to compute useful numbers for the amount of system-wide virtual memory that might need to be swapped out and the total system-wide RSS. While you can mostly get figures for individual processes, summing them all together will overcount shared pages, and these days (with shared libraries and the like) there are a fair amount of them.

Written on 14 May 2007.
« Unix folklore: your swap should be twice your RAM
Sizing your swap space (part 2) »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon May 14 22:02:27 2007
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.