Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 126225
b: refs/heads/master
c: 6a6ba83
h: refs/heads/master
i:
  126223: 814b9fa
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Jan 6, 2009
1 parent 18627c1 commit 474f109
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 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: ebebbbe904634b0ca1c674457b399f68db5e05b1
refs/heads/master: 6a6ba83175c029c7820765bae44692266b29e67a
1 change: 1 addition & 0 deletions trunk/include/linux/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct swap_extent {
enum {
SWP_USED = (1 << 0), /* is slot in swap_info[] used? */
SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */
SWP_DISCARDABLE = (1 << 2), /* blkdev supports discard */
/* add others here before... */
SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */
};
Expand Down
39 changes: 37 additions & 2 deletions trunk/mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,37 @@ void swap_unplug_io_fn(struct backing_dev_info *unused_bdi, struct page *page)
up_read(&swap_unplug_sem);
}

/*
* swapon tell device that all the old swap contents can be discarded,
* to allow the swap device to optimize its wear-levelling.
*/
static int discard_swap(struct swap_info_struct *si)
{
struct swap_extent *se;
int err = 0;

list_for_each_entry(se, &si->extent_list, list) {
sector_t start_block = se->start_block << (PAGE_SHIFT - 9);
pgoff_t nr_blocks = se->nr_pages << (PAGE_SHIFT - 9);

if (se->start_page == 0) {
/* Do not discard the swap header page! */
start_block += 1 << (PAGE_SHIFT - 9);
nr_blocks -= 1 << (PAGE_SHIFT - 9);
if (!nr_blocks)
continue;
}

err = blkdev_issue_discard(si->bdev, start_block,
nr_blocks, GFP_KERNEL);
if (err)
break;

cond_resched();
}
return err; /* That will often be -EOPNOTSUPP */
}

#define SWAPFILE_CLUSTER 256
#define LATENCY_LIMIT 256

Expand Down Expand Up @@ -1658,6 +1689,9 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
goto bad_swap;
}

if (discard_swap(p) == 0)
p->flags |= SWP_DISCARDABLE;

mutex_lock(&swapon_mutex);
spin_lock(&swap_lock);
if (swap_flags & SWAP_FLAG_PREFER)
Expand All @@ -1671,9 +1705,10 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)
total_swap_pages += nr_good_pages;

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

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

0 comments on commit 474f109

Please sign in to comment.