linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: wonder_rock@126.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] mm/page_alloc: update comments in __free_pages_ok()
Date: Thu, 1 Dec 2022 14:41:03 -0800	[thread overview]
Message-ID: <20221201144103.8f79e5272e75957a34de4c4e@linux-foundation.org> (raw)
In-Reply-To: <20221201135045.31663-1-wonder_rock@126.com>

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!


      reply	other threads:[~2022-12-01 22:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 13:50 wonder_rock
2022-12-01 22:41 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221201144103.8f79e5272e75957a34de4c4e@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=wonder_rock@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox