Re: Swap on loop device on tmpfs locks up machine

From: Hugh Dickins
Date: Sun Sep 28 2008 - 11:18:51 EST


On Fri, 26 Sep 2008, Vegard Nossum wrote:
>
> It turns out that swap over loop device on tmpfs will lock up the
> machine. That is, all programs become blocked, but I can still do
> things like switch VT consoles.
>
> To reproduce (as root):
>
> mount -t tmpfs tmpfs /mnt
> dd if=/dev/zero of=/mnt/disk
> swapoff -a
> losetup -f /mnt/disk
> mkswap /dev/loop0 # replace loop0 with actual loop device
> swapon /dev/loop0
> <memory hog, like continuous malloc()>
>
> I'm not sure it's really a very good idea to do this in the first
> place, but should something give a warning or prevent a user from
> doing it?

It's just a "don't do that" in my opinion, and it doesn't seem
to have caused much trouble for sysadmins down the years.

It's good to have a loop driver that can make regular files look
like block devices, and it's good to have that working on tmpfs;
and I'm glad that trying to swapon a tmpfs file directly just
happens to fail because tmpfs doesn't support bmap().

But I don't think it's worth adding in some "valid for swap" call
to block devices, and saying no when loop or when loop over tmpfs.
Trying to swap to loop over tmpfs is a particularly clear example
of something that will end badly - unless the tmpfs file is locked
in memory? haven't tried that - but I wouldn't recommend swapping
to loop over anything (it interposes levels between swap and device
which just increase the likelihood of hang).

Just don't do that.

Hugh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/