linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] swap_state: update shadow_nodes for anonymous page
@ 2022-12-29 13:30 yang.yang29
  2022-12-29 17:03 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: yang.yang29 @ 2022-12-29 13:30 UTC (permalink / raw)
  To: akpm, hannes
  Cc: linux-fsdevel, linux-kernel, linux-mm, willy, iamjoonsoo.kim,
	yang.yang29

From: Yang Yang <yang.yang29@zte.com.cn>

Shadow_nodes is for shadow nodes reclaiming of workingset handling,
it is updated when page cache add or delete since long time ago
workingset only supported page cache. But when workingset supports
anonymous page detection[1], we missied updating shadow nodes for
it.

[1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")

Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 include/linux/xarray.h | 3 ++-
 mm/swap_state.c        | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 44dd6d6e01bc..cd2ccb09c596 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -1643,7 +1643,8 @@ static inline void xas_set_order(struct xa_state *xas, unsigned long index,
  * @update: Function to call when updating a node.
  *
  * The XArray can notify a caller after it has updated an xa_node.
- * This is advanced functionality and is only needed by the page cache.
+ * This is advanced functionality and is only needed by the page cache
+ * and anonymous page.
  */
 static inline void xas_set_update(struct xa_state *xas, xa_update_node_t update)
 {
diff --git a/mm/swap_state.c b/mm/swap_state.c
index cb9aaa00951d..ed7c652d06db 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -94,6 +94,8 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
 	unsigned long i, nr = folio_nr_pages(folio);
 	void *old;

+	xas_set_update(&xas, workingset_update_node);
+
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 	VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio);
 	VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio);
@@ -145,6 +147,8 @@ void __delete_from_swap_cache(struct folio *folio,
 	pgoff_t idx = swp_offset(entry);
 	XA_STATE(xas, &address_space->i_pages, idx);

+	xas_set_update(&xas, workingset_update_node);
+
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 	VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio);
 	VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio);
-- 
2.15.2

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

* Re: [PATCH linux-next] swap_state: update shadow_nodes for anonymous page
  2022-12-29 13:30 [PATCH linux-next] swap_state: update shadow_nodes for anonymous page yang.yang29
@ 2022-12-29 17:03 ` Matthew Wilcox
  2022-12-30  1:36   ` yang.yang29
  2023-01-03  1:44   ` yang.yang29
  0 siblings, 2 replies; 4+ messages in thread
From: Matthew Wilcox @ 2022-12-29 17:03 UTC (permalink / raw)
  To: yang.yang29
  Cc: akpm, hannes, linux-fsdevel, linux-kernel, linux-mm,
	iamjoonsoo.kim

On Thu, Dec 29, 2022 at 09:30:03PM +0800, yang.yang29@zte.com.cn wrote:
> From: Yang Yang <yang.yang29@zte.com.cn>
> 
> Shadow_nodes is for shadow nodes reclaiming of workingset handling,
> it is updated when page cache add or delete since long time ago
> workingset only supported page cache. But when workingset supports
> anonymous page detection[1], we missied updating shadow nodes for
> it.

Please include a description of the user-visible effect of this (I
think I can guess, but I'd like it spelled out)

> [1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")
> 
> Signed-off-by: Yang Yang <yang.yang29@zte.com>

No Fixes: line?  It doesn't need to be backported?

> ---
>  include/linux/xarray.h | 3 ++-
>  mm/swap_state.c        | 4 ++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/xarray.h b/include/linux/xarray.h
> index 44dd6d6e01bc..cd2ccb09c596 100644
> --- a/include/linux/xarray.h
> +++ b/include/linux/xarray.h
> @@ -1643,7 +1643,8 @@ static inline void xas_set_order(struct xa_state *xas, unsigned long index,
>   * @update: Function to call when updating a node.
>   *
>   * The XArray can notify a caller after it has updated an xa_node.
> - * This is advanced functionality and is only needed by the page cache.
> + * This is advanced functionality and is only needed by the page cache
> + * and anonymous page.

... "and swap cache.", not anonymous page.


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

* Re: [PATCH linux-next] swap_state: update shadow_nodes for anonymous page
  2022-12-29 17:03 ` Matthew Wilcox
@ 2022-12-30  1:36   ` yang.yang29
  2023-01-03  1:44   ` yang.yang29
  1 sibling, 0 replies; 4+ messages in thread
From: yang.yang29 @ 2022-12-30  1:36 UTC (permalink / raw)
  To: willy; +Cc: akpm, hannes, linux-fsdevel, linux-kernel, linux-mm,
	iamjoonsoo.kim

> Please include a description of the user-visible effect of this (I
> think I can guess, but I'd like it spelled out)

> No Fixes: line?  It doesn't need to be backported?

> .... "and swap cache.", not anonymous page.

Thanks to your reviewing! I will send patchv2 to fix those all after
further review.

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

* Re: [PATCH linux-next] swap_state: update shadow_nodes for anonymous page
  2022-12-29 17:03 ` Matthew Wilcox
  2022-12-30  1:36   ` yang.yang29
@ 2023-01-03  1:44   ` yang.yang29
  1 sibling, 0 replies; 4+ messages in thread
From: yang.yang29 @ 2023-01-03  1:44 UTC (permalink / raw)
  To: hannes, iamjoonsoo.kim; +Cc: akpm, linux-fsdevel, linux-kernel, linux-mm, willy

I tested the patch, and occur kernel panic, I am trying to solve it.

Hardware: qemu with 4G memory of x86.
OS: 5.14-rc6, with zram enabled.
Test program: some programs malloc and access some memory.
Trigger: count_shadow_nodes() return > 0 many times, and shadow_lru_isolate()
started it's work.
Log:
[ 4955.607376] BUG: unable to handle page fault for address: 000000ab000000aa
[ 4955.607376] #PF: supervisor read access in kernel mode
[ 4955.607376] #PF: error_code(0x0000) - not-present page
[ 4955.607376] PGD 115588067 P4D 0
[ 4955.607376] Oops: 0000 [#1] SMP NOPTI
[ 4955.607376] CPU: 2 PID: 72 Comm: kswapd0 Not tainted 5.14.0-rc6+ #101
[ 4955.607376] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014
[ 4955.607376] RIP: 0010:_raw_spin_trylock+0x0/0x20
[ 4955.607376] Code: 0f c1 07 f7 c6 00 02 00 00 74 01 fb c3 0f 1f 00 66 2e 0f 1f 84 00 00 00 00 00 f7 c6 00 02 00 00 c6 07 00 74 01 fb c3 0f 1f 00 <8b> 07 85 c0 75 0b ba 01 00 00 00 f0 0f b1 17 74 03 31 c0 c3 b8 01
[ 4955.607376] RSP: 0018:ff504e75c0267bc0 EFLAGS: 00000082
[ 4955.607376] RAX: 000000000000002f RBX: ff286ccb402c6108 RCX: c0000001001b49d9
[ 4955.607376] RDX: 0000000000000000 RSI: 00000001001b49d9 RDI: 000000ab000000aa
[ 4955.607376] RBP: ff286ccb6f6426e0 R08: 0000000000000003 R09: 000000000752a700
[ 4955.607376] R10: 000000000000003e R11: ff504e75c02679f0 R12: ff286ccb6f6426c8
[ 4955.607376] R13: 000000ab000000aa R14: ff286ccb402c6100 R15: ff286ccb402c6100
[ 4955.607376] FS:  0000000000000000(0000) GS:ff286ccb7bd00000(0000) knlGS:0000000000000000
[ 4955.607376] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 4955.607376] CR2: 000000ab000000aa CR3: 00000001001ae000 CR4: 00000000007516e0
[ 4955.607376] PKRU: 55555554
[ 4955.607376] Call Trace:
[ 4955.607376]  shadow_lru_isolate+0x5d/0x1a0
[ 4955.607376]  ? workingset_update_node+0x110/0x110
[ 4955.607376]  __list_lru_walk_one.isra.14+0x57/0x110
[ 4955.607376]  ? workingset_update_node+0x110/0x110
[ 4955.607376]  list_lru_walk_one_irq+0x32/0x40
[ 4955.607376]  shrink_slab.constprop.88+0x17a/0x380
[ 4955.607376]  shrink_node+0x1a8/0x400
[ 4955.607376]  balance_pgdat+0x288/0x520
[ 4955.607376]  kswapd+0x15e/0x390
[ 4955.607376]  ? wait_woken+0x60/0x60
[ 4955.607376]  ? balance_pgdat+0x520/0x520
[ 4955.607376]  kthread+0xf9/0x140
[ 4955.607376]  ? set_kthread_struct+0x40/0x40
[ 4955.607376]  ret_from_fork+0x22/0x30
[ 4955.607376] Modules linked in:
[ 4955.607376] CR2: 000000ab000000aa
[ 4955.607376] ---[ end trace 74c5ee73e52d917d ]---
[ 4955.607376] RIP: 0010:_raw_spin_trylock+0x0/0x20
[ 4955.607376] Code: 0f c1 07 f7 c6 00 02 00 00 74 01 fb c3 0f 1f 00 66 2e 0f 1f 84 00 00 00 00 00 f7 c6 00 02 00 00 c6 07 00 74 01 fb c3 0f 1f 00 <8b> 07 85 c0 75 0b ba 01 00 00 00 f0 0f b1 17 74 03 31 c0 c3 b8 01
[ 4955.607376] RSP: 0018:ff504e75c0267bc0 EFLAGS: 00000082
[ 4955.607376] RAX: 000000000000002f RBX: ff286ccb402c6108 RCX: c0000001001b49d9
[ 4955.607376] RDX: 0000000000000000 RSI: 00000001001b49d9 RDI: 000000ab000000aa
[ 4955.607376] RBP: ff286ccb6f6426e0 R08: 0000000000000003 R09: 000000000752a700
[ 4955.607376] R10: 000000000000003e R11: ff504e75c02679f0 R12: ff286ccb6f6426c8
[ 4955.607376] R13: 000000ab000000aa R14: ff286ccb402c6100 R15: ff286ccb402c6100
[ 4955.607376] FS:  0000000000000000(0000) GS:ff286ccb7bd00000(0000) knlGS:0000000000000000
[ 4955.607376] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 4955.607376] CR2: 000000ab000000aa CR3: 00000001001ae000 CR4: 00000000007516e0
[ 4955.607376] PKRU: 5555555

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

end of thread, other threads:[~2023-01-03  1:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-29 13:30 [PATCH linux-next] swap_state: update shadow_nodes for anonymous page yang.yang29
2022-12-29 17:03 ` Matthew Wilcox
2022-12-30  1:36   ` yang.yang29
2023-01-03  1:44   ` yang.yang29

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).