linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: fix swap offset when replacing shmem page
@ 2018-11-19  0:47 Yu Zhao
  2018-11-19  1:09 ` [PATCH v2] " Yu Zhao
  0 siblings, 1 reply; 11+ messages in thread
From: Yu Zhao @ 2018-11-19  0:47 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Andrew Morton, linux-mm, linux-kernel, Yu Zhao

We used to have a single swap address space with swp_entry_t.val
as its radix tree index. This is not the case anymore. Now Each
swp_type() has its own address space and should use swp_offset()
as radix tree index.

Signed-off-by: Yu Zhao <yuzhao@google.com>
---
 mm/shmem.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index d44991ea5ed4..a92c6ae26915 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1509,11 +1509,13 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
 {
 	struct page *oldpage, *newpage;
 	struct address_space *swap_mapping;
-	pgoff_t swap_index;
+	swp_entry_t entry;
 	int error;
 
+	VM_BUG_ON(PageSwapCache(*pagep));
+
 	oldpage = *pagep;
-	swap_index = page_private(oldpage);
+	entry.val = page_private(oldpage);
 	swap_mapping = page_mapping(oldpage);
 
 	/*
@@ -1532,7 +1534,7 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
 	__SetPageLocked(newpage);
 	__SetPageSwapBacked(newpage);
 	SetPageUptodate(newpage);
-	set_page_private(newpage, swap_index);
+	set_page_private(newpage, entry.val);
 	SetPageSwapCache(newpage);
 
 	/*
@@ -1540,7 +1542,8 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
 	 * a nice clean interface for us to replace oldpage by newpage there.
 	 */
 	xa_lock_irq(&swap_mapping->i_pages);
-	error = shmem_replace_entry(swap_mapping, swap_index, oldpage, newpage);
+	error = shmem_replace_entry(swap_mapping, swp_offset(entry),
+				    oldpage, newpage);
 	if (!error) {
 		__inc_node_page_state(newpage, NR_FILE_PAGES);
 		__dec_node_page_state(oldpage, NR_FILE_PAGES);
-- 
2.19.1.1215.g8438c0b245-goog

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-11-23 20:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-19  0:47 [PATCH] mm: fix swap offset when replacing shmem page Yu Zhao
2018-11-19  1:09 ` [PATCH v2] " Yu Zhao
2018-11-19 22:11   ` Hugh Dickins
2018-11-20  1:29     ` Yu Zhao
2018-11-20  5:07       ` Hugh Dickins
2018-11-20 13:12         ` Matthew Wilcox
2018-11-21 21:54   ` [PATCH v3] mm: use swp_offset as key in shmem_replace_page() Yu Zhao
2018-11-21 22:11     ` Matthew Wilcox
2018-11-22  0:36     ` Hugh Dickins
2018-11-22  5:01     ` Andrew Morton
2018-11-23 20:11       ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).