Is swap really needed when RAM's aplenty
Bryn M. Reeves
bmr at redhat.com
Thu Aug 19 14:36:05 UTC 2010
On 08/19/2010 03:22 PM, Michael Hennebry wrote:
> On Thu, 19 Aug 2010, Gregory Hosler wrote:
>> If the memory gets fragged and the kernel wants to defrag, e.g. for a memory
>> request from an application, in order to defrag any "dirty" data portions (those
>> pages that have been written to), the kernel *requires* there to be swap.
>> Otherwise there is no place to write the dirty pages out, in order to read them
>> in elsewhere.
> I didn't realize that memory could get fragged.
> I'd thought that one reason for virtual memory
> was allowing pages to be renumbered at will,
> the kernel's will, of course.
Virtual memory allows us to present a simple, linear address space to
running processes even though the physical memory backing it may be
highly non-contiguous (or not even present).
Unfortunately someone still has to manage the pool of available physical
memory pages ("page frames") and it is possible for this space to become
fragmented over time as repeated allocation/deallocation cycles create
"holes" in the available memory.
The kernel implements the buddy algorithm in the page allocator to try
to minimize external fragmentation but some workloads can still lead to
a lot of pages on the low-order free lists and no larger blocks to
satisfy bigger requests.
Forcing everything out to swap and then pulling it back in is one crude
way of forcing a level of de-fragmentation. There was some discussion on
linux-mm.org of implementing novel de-fragmentation and fragmentation
avoidance techniques a while back but I'm not sure where those
initiatives are at the moment.
More information about the users