linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next v2] swap_state: update shadow_nodes for anonymous page
@ 2023-01-13  7:50 yang.yang29
  2023-01-13  8:47 ` Bagas Sanjaya
  0 siblings, 1 reply; 3+ messages in thread
From: yang.yang29 @ 2023-01-13  7:50 UTC (permalink / raw)
  To: akpm, hannes, willy
  Cc: linux-fsdevel, linux-kernel, linux-mm, iamjoonsoo.kim,
	yang.yang29, ran.xiaokai

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, we missied updating shadow nodes for
it. This caused that shadow nodes of anonymous page will never be
reclaimd by scan_shadow_nodes() even they use much memory and
system memory is tense.

This patch updates shadow_nodes of anonymous page when swap
cache is add or delete.

Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU")
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
change for v2
- Include a description of the user-visible effect. Add fixes tag. Modify comments.
Also call workingset_update_node() in clear_shadow_from_swap_cache(). Thanks
to Matthew Wilcox.
---
include/linux/xarray.h | 3 ++-
 mm/swap_state.c        | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 44dd6d6e01bc..5cc1f718fec9 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 swap cache.
  */
 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..7a003d8abb37 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);
@@ -252,6 +256,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
 		struct address_space *address_space = swap_address_space(entry);
 		XA_STATE(xas, &address_space->i_pages, curr);

+		xas_set_update(&xas, workingset_update_node);
+
 		xa_lock_irq(&address_space->i_pages);
 		xas_for_each(&xas, old, end) {
 			if (!xa_is_value(old))
-- 
2.15.2


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

* Re: [PATCH linux-next v2] swap_state: update shadow_nodes for anonymous page
  2023-01-13  7:50 [PATCH linux-next v2] swap_state: update shadow_nodes for anonymous page yang.yang29
@ 2023-01-13  8:47 ` Bagas Sanjaya
  2023-01-13 13:59   ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Bagas Sanjaya @ 2023-01-13  8:47 UTC (permalink / raw)
  To: yang.yang29, akpm, hannes, willy
  Cc: linux-fsdevel, linux-kernel, linux-mm, iamjoonsoo.kim, ran.xiaokai

[-- Attachment #1: Type: text/plain, Size: 1712 bytes --]

On Fri, Jan 13, 2023 at 03:50:45PM +0800, yang.yang29@zte.com.cn wrote:
> This patch updates shadow_nodes of anonymous page when swap
> cache is add or delete.

By what?

> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index cb9aaa00951d..7a003d8abb37 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);
> @@ -252,6 +256,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
>  		struct address_space *address_space = swap_address_space(entry);
>  		XA_STATE(xas, &address_space->i_pages, curr);
> 
> +		xas_set_update(&xas, workingset_update_node);
> +
>  		xa_lock_irq(&address_space->i_pages);
>  		xas_for_each(&xas, old, end) {
>  			if (!xa_is_value(old))

Adding xas_set_update() call?

In any case, please explain what you are doing above in imperative mood
(no "This patch does foo" but "Do foo" instead).

Thanks.

-- 
An old man doll... just what I always wanted! - Clara

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH linux-next v2] swap_state: update shadow_nodes for anonymous page
  2023-01-13  8:47 ` Bagas Sanjaya
@ 2023-01-13 13:59   ` Matthew Wilcox
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2023-01-13 13:59 UTC (permalink / raw)
  To: Bagas Sanjaya
  Cc: yang.yang29, akpm, hannes, linux-fsdevel, linux-kernel, linux-mm,
	iamjoonsoo.kim, ran.xiaokai

On Fri, Jan 13, 2023 at 03:47:31PM +0700, Bagas Sanjaya wrote:
> On Fri, Jan 13, 2023 at 03:50:45PM +0800, yang.yang29@zte.com.cn wrote:
> > This patch updates shadow_nodes of anonymous page when swap
> > cache is add or delete.
> 
> By what?

This is not a helpful question.

> > @@ -252,6 +256,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
> >  		struct address_space *address_space = swap_address_space(entry);
> >  		XA_STATE(xas, &address_space->i_pages, curr);
> > 
> > +		xas_set_update(&xas, workingset_update_node);
> > +
> >  		xa_lock_irq(&address_space->i_pages);
> >  		xas_for_each(&xas, old, end) {
> >  			if (!xa_is_value(old))
> 
> Adding xas_set_update() call?

It makes perfect sense to me.

> In any case, please explain what you are doing above in imperative mood
> (no "This patch does foo" but "Do foo" instead).

Not helpful either.



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

end of thread, other threads:[~2023-01-13 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13  7:50 [PATCH linux-next v2] swap_state: update shadow_nodes for anonymous page yang.yang29
2023-01-13  8:47 ` Bagas Sanjaya
2023-01-13 13:59   ` Matthew Wilcox

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