summaryrefslogtreecommitdiff
path: root/mm/swapfile.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-03-03 00:53:21 +0300
committerJens Axboe <axboe@kernel.dk>2021-03-03 03:25:46 +0300
commitcaf6912f3f4af7232340d500a4a2008f81b93f14 (patch)
tree64099ad5cba8855452bb5eb518da72a5bac3855a /mm/swapfile.c
parentf5f4fc4649ae542b1a25670b17aaf3cbb6187acc (diff)
downloadlinux-caf6912f3f4af7232340d500a4a2008f81b93f14.tar.xz
swap: fix swapfile read/write offset
We're not factoring in the start of the file for where to write and read the swapfile, which leads to very unfortunate side effects of writing where we should not be... Fixes: 48d15436fde6 ("mm: remove get_swap_bio") Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index f039745989d2..084a5b9a18e5 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -219,6 +219,19 @@ offset_to_swap_extent(struct swap_info_struct *sis, unsigned long offset)
BUG();
}
+sector_t swap_page_sector(struct page *page)
+{
+ struct swap_info_struct *sis = page_swap_info(page);
+ struct swap_extent *se;
+ sector_t sector;
+ pgoff_t offset;
+
+ offset = __page_file_index(page);
+ se = offset_to_swap_extent(sis, offset);
+ sector = se->start_block + (offset - se->start_page);
+ return sector << (PAGE_SHIFT - 9);
+}
+
/*
* swap allocation tell device that a cluster of swap can now be discarded,
* to allow the swap device to optimize its wear-levelling.