Swapping to a large sparse file

Chris Murphy lists at colorremedies.com
Sat Jan 17 22:52:13 UTC 2015


On Fri, Jan 16, 2015 at 7:22 PM, jd1008 <jd1008 at gmail.com> wrote:
>
> On 01/16/2015 07:11 PM, John Morris wrote:
>>
>> On Fri, 2015-01-16 at 14:26 -0700, jd1008 wrote:
>>
>>> In older "traditional" practices, swap space was normally
>>> about twice the ram size. Today, with some systems having
>>> 64 and even 128GB and even larger RAM, it becomes interesting
>>> how big swap space should be. Where is the cutoff for performance?
>>> Paging in and out 128GB memory space could prove to be itself a
>>> performance bottleneck on very busy or memory bound servers.
>>
>> My advice is don't bother unless you know you need it.  I find 512MB or
>> 1GB to be plenty of swap.  You need some swap just so the system can
>> ditch memory that was used once to initialize code but isn't accessed
>> again and other similar things that can be safely tossed to swap and
>> forgot about.  But if the system is actually swapping hundreds of
>> megabytes in and out you will quickly be in a world of pain.  Plus most
>> of the time when that sort of memory pressure hits it is a runaway
>> process that the OOM killer will eventually take out and having a lot of
>> swap only increases how long you suffer with an almost totally
>> unresponsive machine until that happens.  If you are swapping and it
>> isn't a runaway process or an exception to process a one off huge
>> dataset it is a sign you need to bite the bullet and get more ram.  If
>> you know you are going to need a lot of swap to get through some script
>> you banged out that allocates memory like mad, just add an extra
>> swapfile on a temporary basis and drop it when you are done.  You are
>> allowed to have multiple swap files, partitions or any combination of
>> them within sensible limits.
>>
>>
> Well, I need at least 8GB of swap if I want to hibernate, and often
> I need to hibernate so I can let an important app continue where
> it left off (apps that do not depend on an internet continuous connection)
>

Does hibernation (suspend to disk) even work with a swapfile? It seems
to depend on the root file system becoming available, so that
/etc/fstab can state what/where the hibernation file is located. But
for a loop mounted swap file, in addition the loop needs to be setup
first. Before that time the swap device doesn't exist. So this seems
difficult.

If you want to hibernate you need 1x RAM at least. The installer
(specifically python-blivet) has laptop hibernation specific code to
create a swap partition that's 2x RAM. This code doesn't get used by
default in Fedora.

So if you need to hibernate I think you're best off with a swap
partition that's 2x RAM. It's suggested it might work with less than
that, but the recommendation is to account for the possibility some
swap is in use at the time the computer hibernates, so it needs enough
space to hold what was use for swap and all of RAM.


-- 
Chris Murphy


More information about the users mailing list