Hi,
Last week I was looking for a swap-space (mini) HOWTO and
didn't find one, so I threw one together quickly. It's at
http://www.xenotime.net/linux/swap-mini-howto.txt
(Yeah, I know that this isn't a tough subject, but sometimes
people need something like this.)
I'm sure that it has some things that need to be corrected,
so if any of you could send such corrections to me, I'd
appreciate it.
Anyone have suggestions for where this should/could live,
like tldp.org or kernelnewbies.org etc.?
(other than where it is :)
Thanks,
--
~Randy
On Fri, Nov 01, 2002 at 03:58:27PM -0800, Randy.Dunlap wrote:
>
> Hi,
>
> Last week I was looking for a swap-space (mini) HOWTO and
> didn't find one, so I threw one together quickly. It's at
> http://www.xenotime.net/linux/swap-mini-howto.txt
> (Yeah, I know that this isn't a tough subject, but sometimes
> people need something like this.)
I could have sworn I've seen one of these before..
> I'm sure that it has some things that need to be corrected,
> so if any of you could send such corrections to me, I'd
> appreciate it.
Might be nice to mention that using multiple swap partitions
on different disks will 'stripe' requests across disks a-la-raid0
Dave
--
| Dave Jones. http://www.codemonkey.org.uk
On Fri, Nov 01, 2002 at 03:58:27PM -0800, Randy.Dunlap wrote:
> http://www.xenotime.net/linux/swap-mini-howto.txt
Maybe either refer to 'man mkswap' or add a sentence
about versions. (If you boot both 2.0 and 2.2 then
use mkswap -v0 to get swap space also 2.0 can use.)
Andries
On Sat, 2 Nov 2002, Dave Jones wrote:
| On Fri, Nov 01, 2002 at 03:58:27PM -0800, Randy.Dunlap wrote:
| >
| > Hi,
| >
| > Last week I was looking for a swap-space (mini) HOWTO and
| > didn't find one, so I threw one together quickly. It's at
| > http://www.xenotime.net/linux/swap-mini-howto.txt
| > (Yeah, I know that this isn't a tough subject, but sometimes
| > people need something like this.)
|
| I could have sworn I've seen one of these before..
I expected to find one, but I searched and searched...
| > I'm sure that it has some things that need to be corrected,
| > so if any of you could send such corrections to me, I'd
| > appreciate it.
|
| Might be nice to mention that using multiple swap partitions
| on different disks will 'stripe' requests across disks a-la-raid0
Yep, will do.
--
~Randy
On Sat, 2 Nov 2002, Andries Brouwer wrote:
| On Fri, Nov 01, 2002 at 03:58:27PM -0800, Randy.Dunlap wrote:
|
| > http://www.xenotime.net/linux/swap-mini-howto.txt
|
| Maybe either refer to 'man mkswap' or add a sentence
| about versions. (If you boot both 2.0 and 2.2 then
| use mkswap -v0 to get swap space also 2.0 can use.)
Will do.
BTW, my current (maybe outdated?) mkswap.8 page says:
Presently, Linux allows 8 swap areas. The areas in use
can be seen in the file /proc/swaps (since 2.1.25).
However, the current (2.5) source code supports 32 swap areas.
I don't know when this was changed...
--
~Randy
Dave Jones wrote:
>
> Might be nice to mention that using multiple swap partitions
> on different disks will 'stripe' requests across disks a-la-raid0
>
Yup.
Something I'd like to point out here: in 2.4 and earlier, swapfiles
are less robust than swap devices - the need to go and read metadata
from the filesystem made them prone to oom deadlocks allocating pages
and buffer_heads with which to perform the swapout.
That has changed in 2.5. Swapping onto a regular file has no
disadvantage wrt swapping onto a block device. The kernel does
not need to allocate any memory at all to get a swapcache page
onto disk.
Which is interesting. Because swapfiles are much easier to administer,
and much easier to stripe. Adding, removing and resizing is simplified.
Distributors of 2.6-based kernels could consider doing away with
swapdevs altogether.
If you have two disks then it is very sensible to create a swapfile on
each one and to perform an equal-priority stripe between them. This
will give the best raw swap IO bandwidth. But it could cause additional
seeking between swap and regular file data.
Dedicating an entire disk to swap will obviously reduce the seeking
problem.
But really, if your application is dependent on swap performance, you
need more RAM. Swap should be viewed as a lightweight background
optimisation to make unused pages available for other work, rather
than as a cure for an underprovisioned machine.
On Fri, 1 Nov 2002, Randy.Dunlap wrote:
>
> Anyone have suggestions for where this should/could live,
> like tldp.org or kernelnewbies.org etc.?
> (other than where it is :)
The Linux Documentation Project (http://www.linuxdoc.org) is probably one of the
best places. They gather all howto/mini-howto they can find.
Nicolas
In article <[email protected]> you wrote:
> I'm sure that it has some things that need to be corrected,
You say that linux needs swap=ram and old linux needs swap=2xram which is
not true. There is no "need" for swap size (like in BSD where you need to
have at least as much swap as you have ram).
If your system is doing a lot of memory intense work you may need swap space
up to dozents of gigabyte :)
Normally it is enough to have 1-2 times of your ram, if you have a normal
128-1gb system.
Swap usage can be monitored with the "free" command.
> Anyone have suggestions for where this should/could live,
> like tldp.org or kernelnewbies.org etc.?
> (other than where it is :)
i would suggest you send it to the LDP (tldp.org) cause they will be
mirrored everywhere.
Greetings
Bernd
Andrew Morton wrote:
>Something I'd like to point out here: in 2.4 and earlier, swapfiles
>are less robust than swap devices - the need to go and read metadata
>from the filesystem made them prone to oom deadlocks allocating pages
>and buffer_heads with which to perform the swapout.
>
>That has changed in 2.5. Swapping onto a regular file has no
>disadvantage wrt swapping onto a block device. The kernel does
>not need to allocate any memory at all to get a swapcache page
>onto disk.
>
>Which is interesting. Because swapfiles are much easier to administer,
>and much easier to stripe. Adding, removing and resizing is simplified.
>Distributors of 2.6-based kernels could consider doing away with
>swapdevs altogether.
>
>
That said, I would like to again point out that using sparse swapfiles
should still be discouraged. It may be supported, but it's much better
for system performance and stability, IMO, if the sysadmin makes certain
all swapfiles are 100% allocated before they are mentioned to the swap
subsystem.
Jeff
Jeff Garzik wrote:
>
> ...
> That said, I would like to again point out that using sparse swapfiles
> should still be discouraged. It may be supported, but it's much better
> for system performance and stability, IMO, if the sysadmin makes certain
> all swapfiles are 100% allocated before they are mentioned to the swap
> subsystem.
>
That got stamped out. swapon will fail if the file isn't fully
instantiated on disk:
static int setup_swap_extents(struct swap_info_struct *sis)
{
...
block = bmap(inode, probe_block + block_in_page);
if (block == 0)
goto bad_bmap;
...
bad_bmap:
printk(KERN_ERR "swapon: swapfile has holes\n");
ret = -EINVAL;
}
On Fri, Nov 01, 2002 at 04:25:33PM -0800, Randy.Dunlap wrote:
> BTW, my current (maybe outdated?) mkswap.8 page says:
> Presently, Linux allows 8 swap areas. The areas in use
> can be seen in the file /proc/swaps (since 2.1.25).
>
> However, the current (2.5) source code supports 32 swap areas.
> I don't know when this was changed...
It was changed in 2.4.10.
Andries
Andrew Morton wrote:
> Something I'd like to point out here: in 2.4 and earlier, swapfiles
> are less robust than swap devices - the need to go and read metadata
> from the filesystem made them prone to oom deadlocks allocating pages
> and buffer_heads with which to perform the swapout.
>
> That has changed in 2.5. Swapping onto a regular file has no
> disadvantage wrt swapping onto a block device. The kernel does
> not need to allocate any memory at all to get a swapcache page
> onto disk.
>
> Which is interesting. Because swapfiles are much easier to
> administer,
> and much easier to stripe. Adding, removing and resizing is
> simplified.
> Distributors of 2.6-based kernels could consider doing away with
> swapdevs altogether.
Additionally, using a swapfile allows you to share swapspace with other
OSes.
This can be rather handy on a multibooting laptop with a small
harddrive.
I've done this successfully on a laptop multibooting RedHat 8.0 and
Windows XP. The procedure is quite simple:
- Set up the Windows swapfile on a FAT32 partition, it will preallocate
the file as pagefile.sys (up to the minimum size that you specify).
- Make sure the FAT32 partition gets mounted in /etc/fstab.
- mkswap the pagefile.sys file in the Linux bootscripts before
swapfiles are turned on (Windows will trash the Linux swap signature).
- Fortunately Windows will gladly use a swapfile trashed by Linux, so
there's no need to backup and restore any Windows swapfile headers.
One unfortunate disadvantage is that Windows hibernation to disk cannot
be used, since it assumes the contents of the pagefile are unmodified
when you resume.
Does anyone know if NTFS-TNG in 2.5 is robust enough to mount Windows XP
partitions and allow overwriting of existing files such as pagefile.sys?
If that is the case, the procedure is even easier because you can
eliminate the FAT32 partition and simply mount the main Windows XP
installation partition.
Troels
Hi!
> That has changed in 2.5. Swapping onto a regular file has no
> disadvantage wrt swapping onto a block device. The kernel does
> not need to allocate any memory at all to get a swapcache page
> onto disk.
>
> Which is interesting. Because swapfiles are much easier to administer,
> and much easier to stripe. Adding, removing and resizing is simplified.
> Distributors of 2.6-based kernels could consider doing away with
> swapdevs altogether.
Well, you can swsusp to partition. You can't swsusp to a file, as that
is very hard to do.
Pavel
--
When do you have heart between your knees?
On Sat, 2 Nov 2002, Pavel Machek wrote:
> > That has changed in 2.5. Swapping onto a regular file has no
> > disadvantage wrt swapping onto a block device. The kernel does
> > not need to allocate any memory at all to get a swapcache page
> > onto disk.
>
> Well, you can swsusp to partition. You can't swsusp to a file, as that
> is very hard to do.
Why is it very hard to do ?
For the swap layer, swap to a partition or to a file is the
same thing.
Does swsusp rely on restoring memory from the swap partition
before mounting the root filesystem or is there more behind
your objection ?
regards,
Rik
--
Bravely reimplemented by the knights who say "NIH".
http://www.surriel.com/ http://distro.conectiva.com/
Current spamtrap: <a href=mailto:"[email protected]">[email protected]</a>
Hi!
> > > That has changed in 2.5. Swapping onto a regular file has no
> > > disadvantage wrt swapping onto a block device. The kernel does
> > > not need to allocate any memory at all to get a swapcache page
> > > onto disk.
> >
> > Well, you can swsusp to partition. You can't swsusp to a file, as that
> > is very hard to do.
>
> Why is it very hard to do ?
>
> For the swap layer, swap to a partition or to a file is the
> same thing.
>
> Does swsusp rely on restoring memory from the swap partition
> before mounting the root filesystem or is there more behind
> your objection ?
Yep, I rely on that.
[Even read-only mount of ext3 might cause journal replay, which means
data corruption. If there's real-read-only mode, resume-from-file
might be doable.
Pavel
--
Casualities in World Trade Center: ~3k dead inside the building,
cryptography in U.S.A. and free speech in Czech Republic.
Andrew Morton wrote:
>That got stamped out. swapon will fail if the file isn't fully
>instantiated on disk:
>
>
>static int setup_swap_extents(struct swap_info_struct *sis)
>{
> ...
> block = bmap(inode, probe_block + block_in_page);
> if (block == 0)
> goto bad_bmap;
> ...
>
>bad_bmap:
> printk(KERN_ERR "swapon: swapfile has holes\n");
> ret = -EINVAL;
>}
>
>
I am in further awe of you.
Jeff
Hi!
I translated this doc to Hungarian language. You can read the translated
doc this url:
http://www.hup.hu/modules.php?name=News&file=article&sid=1976
Cheers,
trey
-----------------------------------
Micsk? G?bor
Compaq Accredited Platform Specialist, System Engineer (APS, ASE)
Szint?zis Computer Rendszerh?z Kft.
H-9021 Gyor, Tihanyi ?rp?d ?t. 2.
Tel: +36-96-502-216
Fax: +36-96-318-658
E-mail: [email protected]
Hi Troels,
> Does anyone know if NTFS-TNG in 2.5 is robust enough to mount Windows XP
> partitions and allow overwriting of existing files such as pagefile.sys?
Yes, this shouldn't be a problem.
Anton has successfully tested overwriting normal files (not compressed,
sparse or encrypted). This is possible with either write or mmap.
Cheers,
FlatCap (Rich)
[email protected]
Hi,
I've updated the swap-space-mini-howto based on feedback
from several people here. The updated version is again at:
http://www.xenotime.net/linux/swap-mini-howto.txt
Thanks for all of the comments. More are still welcome.
--
~Randy
Hi Randy,
I thought that it might be possible that the folks who might need this
swap mini-howto might not be the folks who understand terms like "memory
pressure" and "dirty" memory. Have a look at the below and use or don't
use whatever you want. I also included a bit on features and a little
more on priorities.
I also am curious about this sentence:
"Block size in swap space is assumed to be the CPU architecture's
page size."
What should a user be aware of with regard to this info?
Introduction
Linux uses swap space as "extra" or "virtual" memory. When most of
the system's real memory is in use, and there is a need for more,
some data will be moved into swap to free real RAM memory for use by
applications. This is called swapping out. When the data that is
in swap needs to be used it is swapped back in from swap space. The
rate at which data is swapped to and from one or more swap spaces
can be monitored with the vmstat command's swap-in (si) and swap-out
(so) columns.
Linux kernel code and data is not swappable and is never moved to swap.
User code never needs to be written to swap space because it already
exists on disk and can be read in from there if it is required again.
User data can be written to swap space and read back in when needed.
Features
Managing swap with Linux is very easy and flexible compared to most of
proprietary operating systems. Linux's swap spaces can be turned on and
off without a reboot and even while they are in use!
Logical Volumes can be used as swap devices.
Version 0 swap space format is no longer supported in 2.5+.
Swap spaces can be given different priorities, (man 2 swapon) that
determine how the swap spaces will be used. Higher priority swap spaces
will be exhausted first and swap spaces with equal priorities will be
striped. The Priority can be specified at swap space activation with
the swapon command or in the /etc/fstab file.
/dev/hda2 none swap pri=5,defaults 0 0
/dev/hde2 none swap pri=5,defaults 0 0
Regards,
Shane