Swap Questions (includes possible bug) - swapfile.c / swap.c

Joseph Pranevich (knight@baltimore.wwaves.com)
Tue, 11 May 1999 11:16:19 -0400 (EDT)


Hello,

I've been gradually sifting my way through the kernel source and I have a
few minor questions about memory management. There seems to be some
inconsistencies in the way we handle swap files and I am also not able to
make sense out of certain portions of code. Could you help me to
understand this?

1) swap.c : page clustering?

I was taking a look at the page clustering code and noticed that the code
has been made specific to memory size.

/* Use a smaller cluster for memory <16MB or <32MB */
if (num_physpages < ((16 * 1024 * 1024) >> PAGE_SHIFT))
page_cluster = 2;
else if (num_physpages < ((32 * 1024 * 1024) >> PAGE_SHIFT))
page_cluster = 3;
else
page_cluster = 4;

This is fine, but wouldn't it make sense to generalize this, or is the
benifit not as great with larger amounts of ram?

I'm thinking something along the lines of:

int memory_megs = num_physpages / (1024 * 1024 * 8) /*
Actually, groups of eight megs */

while (memory_megs) {
memory_megs = memory_megs >> 1;
exponent++;
}

if (exponent > 2)
page_cluster = exponent;
else
page_cluster = 2;

I'm not actually sure that code is right, but it gets the idea across (I
just wrote it on the fly...)

2) swapfile.c : sys_swapon() question 1

I'm unable to figure out exactly what this code is supposed to be doing.
Can someone help me out here? I don't understand why we set the blocksize
twice or what the funniness is with "filp"

p->swap_device = swap_dentry->d_inode->i_rdev;
set_blocksize(p->swap_device, PAGE_SIZE);

filp.f_dentry = swap_dentry;
filp.f_mode = 3; /* read write */
error = blkdev_open(swap_dentry->d_inode, &filp);
if (error)
goto bad_swap_2;
set_blocksize(p->swap_device, PAGE_SIZE);

3) swapfile.c : sys_swapon() question 2

We don't seem to be very consistant when we handle swap files of the two
different swap formats.

If the swapfile is swap format 1, we never check to make sure that the
swap file has more bad pages than MAX_SWAP_BADPAGES despite the fact that
we could have added a counter in the previous loop. Instead, we wait until
after we are out of the switch and only return an error if there are no
good pages.

case 2 does this:

error = -EINVAL;
if (swap_header->info.nr_badpages > MAX_SWAP_BADPAGES)
goto bad_swap;

And (outside the switch) we do this:

if (!nr_good_pages) {
printk(KERN_WARNING "Empty swap-file\n");
error = -EINVAL;
goto bad_swap;
}

If we already check MAX_SWAP_BADPAGES like we probably should, then there
will be no need for this second check anyway.

4) swapfile.c : sys_swapon() question 3

I have another code question. I can't figure out what the following code
does:

if (p->max >= SWP_OFFSET(SWP_ENTRY(0,~0UL)))
goto bad_swap;

Can anyone help me with this one?

I do apologise for the many questions, I'm just trying to get a feel for
the swapping subsystem. I apologise if this is already documented
someplace.

Joe

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