Re: Does linux locks swap file?

Ion Badulescu (
Thu, 30 Jan 1997 10:10:54 -0500 (EST)

On Thu, 30 Jan 1997, Andrew Walker wrote:

> So the file sticks around until the last time its closed, even though
> no directory entry points to it. That's fine and dandy - that's the way
> it should be, but if its true then how come somebody claimed that removing
> the swap file crashed the system :-(

I've no idea. I tried it myself, and the space the swapfile occupies stays
in use, no crash, no problem (with one exception though, you can't

One catch: I tried it on a ext2 partition; if the code for others fs's is
broken, it might actually free the space even though the file is still
"open" - but then the fs code needs to be corrected, not the swapon code.

> A mandatory lock would be pretty useless too if we're talking about
> deleting the swap file. The mandatory lock will stop other processes
> from opening the file and scribbling in our swap space, but will do
> nothing to guard against deletion.

Actually, it's writing to the file that causes problems. As for deletion..
I guess we could mark it as immutable when it's in use; that should avoid
most of the (accidental) problems.


  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.