Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 6848
b: refs/heads/master
c: 53092a7
h: refs/heads/master
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Sep 5, 2005
1 parent 079764d commit 1ffa845
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 11d31886dbcb61039ed3789e583d21c6e70960fd
refs/heads/master: 53092a7402f227151a681b0c92ec8598c5618b1a
1 change: 0 additions & 1 deletion trunk/include/linux/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ struct swap_info_struct {
struct file *swap_file;
struct block_device *bdev;
struct list_head extent_list;
int nr_extents;
struct swap_extent *curr_swap_extent;
unsigned old_block_size;
unsigned short * swap_map;
Expand Down
44 changes: 30 additions & 14 deletions trunk/mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ static void destroy_swap_extents(struct swap_info_struct *sis)
list_del(&se->list);
kfree(se);
}
sis->nr_extents = 0;
}

/*
Expand Down Expand Up @@ -893,8 +892,7 @@ add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
new_se->start_block = start_block;

list_add_tail(&new_se->list, &sis->extent_list);
sis->nr_extents++;
return 0;
return 1;
}

/*
Expand Down Expand Up @@ -928,19 +926,23 @@ add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
* This is extremely effective. The average number of iterations in
* map_swap_page() has been measured at about 0.3 per page. - akpm.
*/
static int setup_swap_extents(struct swap_info_struct *sis)
static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
{
struct inode *inode;
unsigned blocks_per_page;
unsigned long page_no;
unsigned blkbits;
sector_t probe_block;
sector_t last_block;
sector_t lowest_block = -1;
sector_t highest_block = 0;
int nr_extents = 0;
int ret;

inode = sis->swap_file->f_mapping->host;
if (S_ISBLK(inode->i_mode)) {
ret = add_swap_extent(sis, 0, sis->max, 0);
*span = sis->pages;
goto done;
}

Expand Down Expand Up @@ -985,19 +987,28 @@ static int setup_swap_extents(struct swap_info_struct *sis)
}
}

first_block >>= (PAGE_SHIFT - blkbits);
if (page_no) { /* exclude the header page */
if (first_block < lowest_block)
lowest_block = first_block;
if (first_block > highest_block)
highest_block = first_block;
}

/*
* We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
*/
ret = add_swap_extent(sis, page_no, 1,
first_block >> (PAGE_SHIFT - blkbits));
if (ret)
ret = add_swap_extent(sis, page_no, 1, first_block);
if (ret < 0)
goto out;
nr_extents += ret;
page_no++;
probe_block += blocks_per_page;
reprobe:
continue;
}
ret = 0;
ret = nr_extents;
*span = 1 + highest_block - lowest_block;
if (page_no == 0)
page_no = 1; /* force Empty message */
sis->max = page_no;
Expand Down Expand Up @@ -1265,6 +1276,8 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
union swap_header *swap_header = NULL;
int swap_header_version;
int nr_good_pages = 0;
int nr_extents;
sector_t span;
unsigned long maxpages = 1;
int swapfilesize;
unsigned short *swap_map;
Expand Down Expand Up @@ -1300,7 +1313,6 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
nr_swapfiles = type+1;
INIT_LIST_HEAD(&p->extent_list);
p->flags = SWP_USED;
p->nr_extents = 0;
p->swap_file = NULL;
p->old_block_size = 0;
p->swap_map = NULL;
Expand Down Expand Up @@ -1477,9 +1489,11 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
p->swap_map[0] = SWAP_MAP_BAD;
p->max = maxpages;
p->pages = nr_good_pages;
error = setup_swap_extents(p);
if (error)
nr_extents = setup_swap_extents(p, &span);
if (nr_extents < 0) {
error = nr_extents;
goto bad_swap;
}
nr_good_pages = p->pages;
}
if (!nr_good_pages) {
Expand All @@ -1494,9 +1508,11 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
p->flags = SWP_ACTIVE;
nr_swap_pages += nr_good_pages;
total_swap_pages += nr_good_pages;
printk(KERN_INFO "Adding %dk swap on %s. Priority:%d extents:%d\n",
nr_good_pages<<(PAGE_SHIFT-10), name,
p->prio, p->nr_extents);

printk(KERN_INFO "Adding %dk swap on %s. "
"Priority:%d extents:%d across:%lluk\n",
nr_good_pages<<(PAGE_SHIFT-10), name, p->prio,
nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10));

/* insert swap space into swap_list: */
prev = -1;
Expand Down

0 comments on commit 1ffa845

Please sign in to comment.