kde Digest, Vol 115, Issue 5

Duncan 1i5t5.duncan at cox.net
Sat Oct 13 02:59:07 BST 2012


杜秀涛 posted on Fri, 12 Oct 2012 23:19:03 +0800 as excerpted:

> And I have faced another problem, I runs "swapon -s", it shows me like
> this:
> Filename Type Size Used Priority
> /dev/sdb2 partition 1048572 0 -1

> Is that OK? 0 used, -1 as priority! seems like it didn't take effects?
> could the swap partition speed up my system?

See the swapon (8) manpage, but particularly the swapon (2) manpage, also 
the mount (8) and fstab (5) manpages tho they don't say a lot about it.

If you don't specifically set a priority, the system starts with a low 
priority (that -1), with additional swap devices added as ever lower 
priority.

Higher priority swap is used first, so what those defaults mean is that 
the first swap on the system gets used until it's full, before a second 
swap device.

However, you can set swap priority arbitrarily (using the mount-options 
field in fstab, for instance), *AND*, for those users with many storage 
devices (I was running a 4-disk md/RAID on my home system for awhile, and 
used this feature after I discovered it, thus my knowledge of the subject 
=:^), if you set the same priority for multiple swap devices, the kernel 
will automatically round-robin swap to them all at the same time, 
basically RAID-0/striped swap!  THis can be MUCH faster than swap on an 
individual device, especially for spinning rust when the rest of system 
storage if on the same devices is RAID-1 (mirrored), thus giving the 
kernel some scheduling flexibility so it route storage access to a device 
that's not busy swapping, as each write head can be doing something 
different, and the kernel is actually surprisingly good at such multi-
task scheduling so it's more efficient than people might at first 
expect.. =:^)

So basically what I did when I had the RAID was setup something like 5 GB 
of swap on each device.  (I had 8 gigs of RAM, and early hibernate 
functionality could only work with half of that, as it paged in to half 
of RAM, then switched to the resume kernel.  Hibernate could only use one 
of the stripes, so 5 gig each gave me a bit of extra room for that 4 gig 
hibernate image.)

Then the entries in fstab appeared like this:

LABEL=swap0	swap	swap	priority=100	0 0
LABEL=swap1	swap	swap	priority=100	0 0
LABEL=swap2	swap	swap	priority=100	0 0
LABEL=swap3	swap	swap	priority=100	0 0


Each of those was a swap partition of 5 gigs, on a different device from 
the others (soomething like /dev/sd[abcd]4), with priority set equal for 
all of them so the kernel would stripe across them.

It worked quite well.  Unfortunately that system was old (late 2003 
vintage), and died this summer, bulging/popped caps on the mobo! =:^(

Oh well, it was fun for the years I had it, and when I get some money 
together, I'll probably run raid again.  But memory is cheaper now and my 
new system has 16 gig, so I don't really need swap these days... except 
for hibernate of course (tho the new system suspends to RAM real well, 
but won't hibernate for some reason I haven't tracked down yet... exactly 
opposite the old system, which would hibernate but not suspend to RAM).

So long story short, -1 swap priority is simply the (low) default the 
kernel uses if you've not specifically set a priority, and 0 used means 
you're not using it presently.  (A second swap device would go in as -2 
or some such, if you didn't set the priority manually.)

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.


More information about the kde mailing list