Re: mkswap & swapon

Andries.Brouwer@cwi.nl
Fri, 20 Feb 1998 01:38:04 +0100 (MET)


1. swapon

People complain to me that under recent kernels it is
possible to do "swapon foo" on the same file twice,
and twice some amount is added to the available swap.

No, this is not a bug in the swapon which I maintain;
it is a kernel bug present in 2.1.87 but not in 2.0.33.

I wondered how to fix it but was not sure how to express
the property of not being in use under the 2.1.* regime.
In the good old days, testing i_count = 1 would suffice.
Today, testing d_count = 1 is not enough, because two
names can refer to the same file, and
ln foo bar; swapon foo; swapon bar
would succeed incorrectly.
On the other hand, testing i_count = 1 is no good either.
Indeed, i_count has become next to meaningless: there can
always be dentries that refer to the inode. Thus,
ln foo bar; swapon foo
would fail because two dentries refer to the inode of foo.

How does one express that a file is not in use?

(In case anyone answers, cc to aeb@cwi.nl; I do not read linux-kernel.)

2. Re: mkswap

matti.aarnio@tele.fi wrote on Thu Feb 19 23:25:36 1998:

>> I just noticed that I can do
>> mkswap foo; swapon foo
>> which fails, ("Unable to find swap-space signature"), while
>> mkswap foo; sync; swapon foo
>> succeeds. This is a kernel bug.

> ... diagnostics of it being a "bug" in
> the kernel is somewhat inappropriate. Lets call it
> "feature"; file-io uses buffer-cache, while swapping
> does direct uncached io from disk to the memory pages.

Yes, but this is a bug, unrelated to swapping: the swapping
has not started yet, and the kernel has to read the first page
to check the swap signature, and does not find that, while
it was written already.
This may be construed as a POSIX violation.

(And other forms of aliasing are bugs as well, although
perhaps difficult to avoid without heavy penalty in efficiency.)

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu