diff options
author | Hugh Dickins <hugh@veritas.com> | 2009-01-06 17:39:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 18:59:05 -0500 |
commit | 20137a490f397d9c01fc9fadd83a8d198bda4477 (patch) | |
tree | 38e2d904e06f576a825cca3e1eaad7da6fd55947 | |
parent | 7992fde72ce06c73280a1939b7a1e903bc95ef85 (diff) |
swapfile: swapon randomize if nonrot
Swap allocation has always started from the beginning of the swap area;
but if we're dealing with a solidstate swap device which can only remap
blocks within limited zones, that would sooner wear out the first zone.
Therefore sys_swapon() test whether blk_queue is non-rotational, and if so
randomize the cluster_next starting position for allocation.
If blk_queue is nonrot, note SWP_SOLIDSTATE for later use, and report it
with an "SS" at the right end of the kernel's "Adding ... swap" message
(so that if it's both nonrot and discardable, "SSD" will be shown there).
Perhaps something should be shown in /proc/swaps (swapon -s), but we have
to be more cautious before making any addition to that format.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Joern Engel <joern@logfs.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Donjun Shin <djshin90@gmail.com>
Cc: Tejun Heo <teheo@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/swap.h | 1 | ||||
-rw-r--r-- | mm/swapfile.c | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/swap.h b/include/linux/swap.h index fe79f44c858e..cbf7fbed3dfd 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h | |||
@@ -122,6 +122,7 @@ enum { | |||
122 | SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ | 122 | SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ |
123 | SWP_DISCARDABLE = (1 << 2), /* blkdev supports discard */ | 123 | SWP_DISCARDABLE = (1 << 2), /* blkdev supports discard */ |
124 | SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */ | 124 | SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */ |
125 | SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */ | ||
125 | /* add others here before... */ | 126 | /* add others here before... */ |
126 | SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */ | 127 | SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */ |
127 | }; | 128 | }; |
diff --git a/mm/swapfile.c b/mm/swapfile.c index ca75b9e7c09f..b0f56603b9be 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/namei.h> | 16 | #include <linux/namei.h> |
17 | #include <linux/shm.h> | 17 | #include <linux/shm.h> |
18 | #include <linux/blkdev.h> | 18 | #include <linux/blkdev.h> |
19 | #include <linux/random.h> | ||
19 | #include <linux/writeback.h> | 20 | #include <linux/writeback.h> |
20 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
21 | #include <linux/seq_file.h> | 22 | #include <linux/seq_file.h> |
@@ -1806,6 +1807,11 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags) | |||
1806 | goto bad_swap; | 1807 | goto bad_swap; |
1807 | } | 1808 | } |
1808 | 1809 | ||
1810 | if (blk_queue_nonrot(bdev_get_queue(p->bdev))) { | ||
1811 | p->flags |= SWP_SOLIDSTATE; | ||
1812 | srandom32((u32)get_seconds()); | ||
1813 | p->cluster_next = 1 + (random32() % p->highest_bit); | ||
1814 | } | ||
1809 | if (discard_swap(p) == 0) | 1815 | if (discard_swap(p) == 0) |
1810 | p->flags |= SWP_DISCARDABLE; | 1816 | p->flags |= SWP_DISCARDABLE; |
1811 | 1817 | ||
@@ -1822,10 +1828,11 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags) | |||
1822 | total_swap_pages += nr_good_pages; | 1828 | total_swap_pages += nr_good_pages; |
1823 | 1829 | ||
1824 | printk(KERN_INFO "Adding %uk swap on %s. " | 1830 | printk(KERN_INFO "Adding %uk swap on %s. " |
1825 | "Priority:%d extents:%d across:%lluk%s\n", | 1831 | "Priority:%d extents:%d across:%lluk %s%s\n", |
1826 | nr_good_pages<<(PAGE_SHIFT-10), name, p->prio, | 1832 | nr_good_pages<<(PAGE_SHIFT-10), name, p->prio, |
1827 | nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10), | 1833 | nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10), |
1828 | (p->flags & SWP_DISCARDABLE) ? " D" : ""); | 1834 | (p->flags & SWP_SOLIDSTATE) ? "SS" : "", |
1835 | (p->flags & SWP_DISCARDABLE) ? "D" : ""); | ||
1829 | 1836 | ||
1830 | /* insert swap space into swap_list: */ | 1837 | /* insert swap space into swap_list: */ |
1831 | prev = -1; | 1838 | prev = -1; |