On 4/17/15 1:25 PM, Christian Gough wrote:
Here are our competing theories of why we are swapping as much as 10-15GB with 6GB-10GB of free memory:
How are you determining that you're swapping? How are you measuring 'free memory'?
1.) maintenance_work_mem and work_mem are set too high causing postgres to allocate too much memory
There's not much that uses maintenance_work_mem. (AUTO)VACUUM, CREATE INDEX... I think that's it. Also, I believe it's internally limited to 1G.
As for work_mem, it's hard to say. As your math shows, if *every* connection suddenly allocated a full work_mem then you'd be in trouble. But that would be a pretty extreme situation. Even though a backend can actually have multiple work_mem consuming operations in use at once, so it could theoretically use several times work_mem, in reality I think it's very rare for every backend to use even a fraction of work_mem.
But, there's no need to theorize here; work_mem will be reported as allocated to each backend and will not be considered free memory by the OS.
2.) The 6GB - 10GB of free memory observed during swapping is postgresql's shared buffer
If anything, I'd expect the OS to avoid swapping a shared memory segment (if not flat-out refuse to swap it).
Shared memory certainly shouldn't be counted as free either. The only tricky bit here is many OSes will report shared memory as part of the memory footprint *for each backend*. So if you have 170 backends and 8GB shared buffers, it could look like you're using 13.6TB of memory (which you're obviously not).
3.) Linux filesystem caching is tuned incorrectly, maybe SSD related?
Possibly, though I don't think it'd be SSD related...
4.) This is a NUMA related issue similar to the Mysql Swap Insanity issue:
Since you have that turned off, I don't think so. -- Jim Nasby, Data Architect, Blue Treble Consulting Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance