Skip to contentSkip to conversation

mm/swap_state: Skip meaningless swap cache readahead when ra_info.win == 0

PATCH Applied Miaohe Lin 2 participants 2 messages Oct 9, 2020 – Oct 25, 2020

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm/swap_state: Skip meaningless swap cache readahead when ra_info.win == 0

swap_ra_info() may leave ra_info untouched in non_swap_entry() case as page table lock is not held. In this case, we have ra_info.nr_pte == 0 and it is meaningless to continue with swap cache readahead. Skip such ops by init ra_info.win = 1.

---
 mm/swap_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/swap_state.c +1 -1
index ee465827420e..b9013c3f94c9 100644
@@ -839,7 +839,7 @@ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask,
 	swp_entry_t entry;
 	unsigned int i;
 	bool page_allocated;
-	struct vma_swap_readahead ra_info = {0,};
+	struct vma_swap_readahead ra_info = {1,};
 
 	swap_ra_info(vmf, &ra_info);
 	if (ra_info.win == 1)
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 9 lines · On Fri, 9 Oct 2020 09:30:59 -0400 Miaohe Lin <[email protected]> wrote:

swap_ra_info() may leave ra_info untouched in non_swap_entry() case as page table lock is not held. In this case, we have ra_info.nr_pte == 0 and it is meaningless to continue with swap cache readahead. Skip such ops by init ra_info.win = 1.

mm/swap_state.c static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask, · line 845

Quoted 8 lines
mm/swap_state.c +1 -1
@@ -839,7 +839,7 @@ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask,
 	swp_entry_t entry;
 	unsigned int i;
 	bool page_allocated;
-	struct vma_swap_readahead ra_info = {0,};
+	struct vma_swap_readahead ra_info = {1,};
 
 	swap_ra_info(vmf, &ra_info);
 	if (ra_info.win == 1)

Looks right. But I think it would be better to fix this in swap_ra_info() - make it more consistent in its return state.

Otherwise, let's modernify that struct initializer:

mm/swap_state.c renamed from mm/swap_state.c~mm-swap_state-skip-meaningless-swap-cache-readahead-when-ra_infowin-==-0-fix +3 -1
@@ -839,7 +839,9 @@ static struct page *swap_vma_readahead(s
 	swp_entry_t entry;
 	unsigned int i;
 	bool page_allocated;
-	struct vma_swap_readahead ra_info = {1,};
+	struct vma_swap_readahead ra_info = {
+		.win = 1,
+	};
 
 	swap_ra_info(vmf, &ra_info);
 	if (ra_info.win == 1)

_