All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok()
@ 2022-12-01 13:50 wonder_rock
  2022-12-01 22:41 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: wonder_rock @ 2022-12-01 13:50 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Deyan Wang

From: Deyan Wang <wonder_rock@126.com>

Add a comment to explain why we call get_pfnblock_migratetype() twice
in __free_pages_ok().

Signed-off-by: Deyan Wang <wonder_rock@126.com>
---
 mm/page_alloc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2d4c81224508..52dd4fff280b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1702,6 +1702,11 @@ static void __free_pages_ok(struct page *page, unsigned int order,
 	if (!free_pages_prepare(page, order, true, fpi_flags))
 		return;
 
+	/*
+	 * Calling get_pfnblock_migratetype() without spin_lock_irqsave() here
+	 * is used to avoid calling get_pfnblock_migratetype() under the lock.
+	 * This will reduce the lock holding time.
+	 */
 	migratetype = get_pfnblock_migratetype(page, pfn);
 
 	spin_lock_irqsave(&zone->lock, flags);
-- 
2.25.1


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

* Re: [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok()
  2022-12-01 13:50 [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok() wonder_rock
@ 2022-12-01 22:41 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-12-01 22:41 UTC (permalink / raw)
  To: wonder_rock; +Cc: linux-mm, linux-kernel

On Thu,  1 Dec 2022 21:50:45 +0800 wonder_rock@126.com wrote:

> Add a comment to explain why we call get_pfnblock_migratetype() twice
> in __free_pages_ok().
> 
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1702,6 +1702,11 @@ static void __free_pages_ok(struct page *page, unsigned int order,
>  	if (!free_pages_prepare(page, order, true, fpi_flags))
>  		return;
>  
> +	/*
> +	 * Calling get_pfnblock_migratetype() without spin_lock_irqsave() here
> +	 * is used to avoid calling get_pfnblock_migratetype() under the lock.
> +	 * This will reduce the lock holding time.
> +	 */
>  	migratetype = get_pfnblock_migratetype(page, pfn);
>  
>  	spin_lock_irqsave(&zone->lock, flags);

I guess that if the comment helped one reader, it will help others. 
But this is a pretty common trick in MM and most readers will recognize
it.

That being said, get_pfnblock_migratetype() is pretty lightweight. 
Particularly when compared with __free_one_page().  I wonder if the
optimization does much good.

If the second call to get_pfnblock_migratetype() is almost never performed
then we just added a bunch of testing and branching inside the lock
which actually made things worse!

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

end of thread, other threads:[~2022-12-01 22:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 13:50 [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok() wonder_rock
2022-12-01 22:41 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.