linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/swap_state.c: use the same way to count page in [add_to|delete_from]_swap_cache
@ 2020-03-14 21:59 Wei Yang
  2020-03-15  0:21 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yang @ 2020-03-14 21:59 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Wei Yang

Function add_to_swap_cache() and delete_from_swap_cache() are counter
parts, while currently they use different way to count page.

It doesn't break any thing because we only have two size for PageAnon,
but this is confusing and not a good practice.

This patch corrects it by both using compound_nr().

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 mm/swap_state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 8e7ce9a9bc5e..51d8884a693a 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -158,7 +158,7 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp)
 void __delete_from_swap_cache(struct page *page, swp_entry_t entry)
 {
 	struct address_space *address_space = swap_address_space(entry);
-	int i, nr = hpage_nr_pages(page);
+	int i, nr = compound_nr(page);
 	pgoff_t idx = swp_offset(entry);
 	XA_STATE(xas, &address_space->i_pages, idx);
 
@@ -251,7 +251,7 @@ void delete_from_swap_cache(struct page *page)
 	xa_unlock_irq(&address_space->i_pages);
 
 	put_swap_page(page, entry);
-	page_ref_sub(page, hpage_nr_pages(page));
+	page_ref_sub(page, compound_nr(page));
 }
 
 /* 
-- 
2.23.0


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

* Re: [PATCH] mm/swap_state.c: use the same way to count page in [add_to|delete_from]_swap_cache
  2020-03-14 21:59 [PATCH] mm/swap_state.c: use the same way to count page in [add_to|delete_from]_swap_cache Wei Yang
@ 2020-03-15  0:21 ` Matthew Wilcox
  2020-03-15  1:23   ` Wei Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2020-03-15  0:21 UTC (permalink / raw)
  To: Wei Yang; +Cc: akpm, linux-mm, linux-kernel

On Sat, Mar 14, 2020 at 09:59:12PM +0000, Wei Yang wrote:
> Function add_to_swap_cache() and delete_from_swap_cache() are counter
> parts, while currently they use different way to count page.
> 
> It doesn't break any thing because we only have two size for PageAnon,
> but this is confusing and not a good practice.
> 
> This patch corrects it by both using compound_nr().

You're converting in the wrong direction.  hpage_nr_pages() is optimised
away when CONFIG_TRANSPARENT_HUGEPAGE is undefined, whereas compound_nr()
is not.

I also have this patch pending:
http://git.infradead.org/users/willy/linux-dax.git/commitdiff/192b635b428ae74f680574cdcc3d5e9d213fcb64

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

* Re: [PATCH] mm/swap_state.c: use the same way to count page in [add_to|delete_from]_swap_cache
  2020-03-15  0:21 ` Matthew Wilcox
@ 2020-03-15  1:23   ` Wei Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Yang @ 2020-03-15  1:23 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Wei Yang, akpm, linux-mm, linux-kernel

On Sat, Mar 14, 2020 at 05:21:01PM -0700, Matthew Wilcox wrote:
>On Sat, Mar 14, 2020 at 09:59:12PM +0000, Wei Yang wrote:
>> Function add_to_swap_cache() and delete_from_swap_cache() are counter
>> parts, while currently they use different way to count page.
>> 
>> It doesn't break any thing because we only have two size for PageAnon,
>> but this is confusing and not a good practice.
>> 
>> This patch corrects it by both using compound_nr().
>
>You're converting in the wrong direction.  hpage_nr_pages() is optimised
>away when CONFIG_TRANSPARENT_HUGEPAGE is undefined, whereas compound_nr()
>is not.

Ok, I didn't think about the optimisation.

Will use hpage_nr_pages() in v2.

>
>I also have this patch pending:
>http://git.infradead.org/users/willy/linux-dax.git/commitdiff/192b635b428ae74f680574cdcc3d5e9d213fcb64

-- 
Wei Yang
Help you, Help me

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

end of thread, other threads:[~2020-03-15  7:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-14 21:59 [PATCH] mm/swap_state.c: use the same way to count page in [add_to|delete_from]_swap_cache Wei Yang
2020-03-15  0:21 ` Matthew Wilcox
2020-03-15  1:23   ` Wei Yang

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