Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 83053
b: refs/heads/master
c: 8952898
h: refs/heads/master
i:
  83051: 892bbec
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Feb 5, 2008
1 parent 4a4ebec commit 9555bb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 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: 5402b976ae0be96b3a32f3508ab7308c380d6477
refs/heads/master: 8952898b0d25223f38daf46b86156fd1c4d17ad0
49 changes: 33 additions & 16 deletions trunk/mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,31 +1769,48 @@ get_swap_info_struct(unsigned type)
*/
int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
{
struct swap_info_struct *si;
int our_page_cluster = page_cluster;
int ret = 0, i = 1 << our_page_cluster;
unsigned long toff;
struct swap_info_struct *swapdev = swp_type(entry) + swap_info;
pgoff_t target, toff;
pgoff_t base, end;
int nr_pages = 0;

if (!our_page_cluster) /* no readahead */
return 0;
toff = (swp_offset(entry) >> our_page_cluster) << our_page_cluster;
if (!toff) /* first page is swap header */
toff++, i--;
*offset = toff;

si = &swap_info[swp_type(entry)];
target = swp_offset(entry);
base = (target >> our_page_cluster) << our_page_cluster;
end = base + (1 << our_page_cluster);
if (!base) /* first page is swap header */
base++;

spin_lock(&swap_lock);
do {
/* Don't read-ahead past the end of the swap area */
if (toff >= swapdev->max)
if (end > si->max) /* don't go beyond end of map */
end = si->max;

/* Count contiguous allocated slots above our target */
for (toff = target; ++toff < end; nr_pages++) {
/* Don't read in free or bad pages */
if (!si->swap_map[toff])
break;
if (si->swap_map[toff] == SWAP_MAP_BAD)
break;
}
/* Count contiguous allocated slots below our target */
for (toff = target; --toff >= base; nr_pages++) {
/* Don't read in free or bad pages */
if (!swapdev->swap_map[toff])
if (!si->swap_map[toff])
break;
if (swapdev->swap_map[toff] == SWAP_MAP_BAD)
if (si->swap_map[toff] == SWAP_MAP_BAD)
break;
toff++;
ret++;
} while (--i);
}
spin_unlock(&swap_lock);
return ret;

/*
* Indicate starting offset, and return number of pages to get:
* if only 1, say 0, since there's then no readahead to be done.
*/
*offset = ++toff;
return nr_pages? ++nr_pages: 0;
}

0 comments on commit 9555bb2

Please sign in to comment.