linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org,
	roman.gushchin@linux.dev, shakeelb@google.com,
	muchun.song@linux.dev, linux-mm@kvack.org,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/memcg: use get_page() for device private pages in mc_handle_swap_pte()
Date: Sat, 15 Jul 2023 04:56:41 +0100	[thread overview]
Message-ID: <ZLIY+ZwrLvpapGE6@casper.infradead.org> (raw)
In-Reply-To: <20230715032802.2508163-1-linmiaohe@huawei.com>

On Sat, Jul 15, 2023 at 11:28:02AM +0800, Miaohe Lin wrote:
> When page table locked is held, the page can't be freed from under us.

But the page isn't mapped into the page table ... there's a swap entry
in the page table, so I don't think your logic holds.

> So use get_page() to get the extra page reference to simplify the code.
> No functional change intended.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/memcontrol.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 93e3cc581b51..4ca382efb1ca 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5670,8 +5670,9 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,
>  	 */
>  	if (is_device_private_entry(ent)) {
>  		page = pfn_swap_entry_to_page(ent);
> -		if (!get_page_unless_zero(page))
> -			return NULL;
> +		/* Get a page reference while we know the page can't be freed. */
> +		get_page(page);
> +
>  		return page;
>  	}
>  
> -- 
> 2.33.0
> 
> 


  reply	other threads:[~2023-07-15  3:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-15  3:28 Miaohe Lin
2023-07-15  3:56 ` Matthew Wilcox [this message]
2023-07-17  2:28   ` Miaohe Lin
2023-07-23  1:16     ` Miaohe Lin

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=ZLIY+ZwrLvpapGE6@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeelb@google.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