swap: make swap discard async
Subsystems (2)
PATCH v5 2/4 swap: make swap discard async
swap can do cluster discard for SSD, which is good, but there are some problems here:
1. swap do the discard just before page reclaim gets a swap entry and writes the disk sectors. This is useless for high end SSD, because an overwrite to a sector implies a discard to original sector too. A discard + overwrite == overwrite.
2. the purpose of doing discard is to improve SSD firmware garbage collection. Idealy we should send discard as early as possible, so firmware can do something smart. Sending discard just after swap entry is freed is considered early compared to sending discard before write. Of course, if workload is already bound to gc speed, sending discard earlier or later doesn't make difference.
3. block discard is a sync API, which will delay scan_swap_map() significantly.
4. Write and discard command can be executed parallel in PCIe SSD. Making swap discard async can make execution more efficiently.
This patch makes swap discard async and move discard to where swap entry is freed. Discard and write have no dependence now, so above issues can be avoided. Idealy we should do discard for any freed sectors, but some SSD discard is very slow. This patch still does discard for a whole cluster.
My test does a several round of 'mmap, write, unmap', which will trigger a lot of swap discard. In a fusionio card, with this patch, the test runtime is reduced to 18% of the time without it, so around 5.5x faster.
--- include/linux/swap.h | 5 - mm/swapfile.c | 183 +++++++++++++++++++++++++++++---------------------- 2 files changed, 108 insertions(+), 80 deletions(-)
include/linux/swap.h +3 -2
@@ -205,8 +205,6 @@ struct swap_info_struct {unsigned int inuse_pages;/* number of those currently in use */ unsigned int cluster_next;/* likely index for next allocation */ unsigned int cluster_nr;/* countdown to next cluster search */ -unsigned int lowest_alloc;/* while preparing discard cluster */ -unsigned int highest_alloc;/* while preparing discard cluster */ struct swap_extent *curr_swap_extent;struct swap_extent first_swap_extent;struct block_device *bdev;/* swap device or bdev of swap file */
@@ -228,6 +226,9 @@ struct swap_info_struct {* swap_lock. If both locks need hold, * hold swap_lock first. */ +struct work_struct discard_work;/* discard worker */ +struct swap_cluster_info discard_cluster_head;/* list head of discard clusters */ +struct swap_cluster_info discard_cluster_tail;/* list tail of discard clusters */ };struct swap_list_t {
mm/swapfile.c +105 -78
268 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Shaohua,
If you take the patch from my reply to
[patch 1/4 v5]swap: change block allocation algorithm for SSD
The following changes are just to make your merge easier
Thanks in advance!
Rafael
--- include/linux/swap.h | 5 +- mm/swapfile.c | 172 ++++++++++++++++++++++++++++----------------------- 2 files changed, 97 insertions(+), 80 deletions(-)
include/linux/swap.h +3 -2
@@ -200,8 +200,6 @@ struct swap_info_struct {unsigned int inuse_pages;/* number of those currently in use */ unsigned int cluster_next;/* likely index for next allocation */ unsigned int cluster_nr;/* countdown to next cluster search */ -unsigned int lowest_alloc;/* while preparing discard cluster */ -unsigned int highest_alloc;/* while preparing discard cluster */ struct swap_extent *curr_swap_extent;struct swap_extent first_swap_extent;struct block_device *bdev;/* swap device or bdev of swap file */
@@ -223,6 +221,9 @@ struct swap_info_struct {* swap_lock. If both locks need hold, * hold swap_lock first. */ +struct work_struct discard_work; +unsigned int discard_cluster_head; +unsigned int discard_cluster_tail; };struct swap_list_t {
mm/swapfile.c +94 -78
257 lines not on this page · raw message
Signature · 7 lines
1.8.1.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>