Re: 2.6.17-rc5-mm1

From: Christoph Lameter
Date: Tue Jun 06 2006 - 14:04:10 EST


On Tue, 6 Jun 2006, Martin Schwidefsky wrote:

> swp_type(pte_to_swp_entry(swp_entry_to_pte(swp_entry(~0UL,0))))
> evaluates to 31 for s390. The idea has been that the creation of a swap
> entry with ~0UL as the type should mask off all bits that can not be
> represented in a swap entry. Convert it back and you have the maximum
> number of swap devices. That should be true for all architectures.

It evaluates to 31 it seems for all platforms. Could we replace this
expression with MAX_SWAPFILES? While we at it get rid of the "type"
variable because we are usually using pointers to swap_info.

Note that there is still another similar check in there for an arch
specific test of the number of pages available per swap device.


Index: linux-2.6.17-rc5-mm2/mm/swapfile.c
===================================================================
--- linux-2.6.17-rc5-mm2.orig/mm/swapfile.c 2006-06-01 10:03:07.127259731 -0700
+++ linux-2.6.17-rc5-mm2/mm/swapfile.c 2006-06-06 10:50:09.692165312 -0700
@@ -1363,12 +1363,11 @@ __initcall(procswaps_init);
*/
asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
{
- struct swap_info_struct * p;
+ struct swap_info_struct *p,*q;
char *name = NULL;
struct block_device *bdev = NULL;
struct file *swap_file = NULL;
struct address_space *mapping;
- unsigned int type;
int i, prev;
int error;
static int least_priority;
@@ -1387,29 +1386,19 @@ asmlinkage long sys_swapon(const char __
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
spin_lock(&swap_lock);
- p = swap_info;
- for (type = 0 ; type < nr_swapfiles ; type++,p++)
+
+ for (p = swap_info; p < swap_info + nr_swapfiles; p++)
if (!(p->flags & SWP_USED))
break;
error = -EPERM;
- /*
- * Test if adding another swap device is possible. There are
- * two limiting factors: 1) the number of bits for the swap
- * type swp_entry_t definition and 2) the number of bits for
- * the swap type in the swap ptes as defined by the different
- * architectures. To honor both limitations a swap entry
- * with swap offset 0 and swap type ~0UL is created, encoded
- * to a swap pte, decoded to a swp_entry_t again and finally
- * the swap type part is extracted. This will mask all bits
- * from the initial ~0UL that can't be encoded in either the
- * swp_entry_t or the architecture definition of a swap pte.
- */
- if (type > swp_type(pte_to_swp_entry(swp_entry_to_pte(swp_entry(~0UL,0))))) {
+
+ if (p == swap_info + MAX_SWAPFILES) {
spin_unlock(&swap_lock);
goto out;
}
- if (type >= nr_swapfiles)
- nr_swapfiles = type+1;
+ if (p >= swap_info + nr_swapfiles)
+ nr_swapfiles++;
+
INIT_LIST_HEAD(&p->extent_list);
p->flags = SWP_USED;
p->swap_file = NULL;
@@ -1445,10 +1434,9 @@ asmlinkage long sys_swapon(const char __
inode = mapping->host;

error = -EBUSY;
- for (i = 0; i < nr_swapfiles; i++) {
- struct swap_info_struct *q = &swap_info[i];
+ for (q = swap_info; q < swap_info + nr_swapfiles; q++) {

- if (i == type || !q->swap_file)
+ if (q == p || !q->swap_file)
continue;
if (mapping == q->swap_file->f_mapping)
goto bad_swap;




-
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/