public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Usama Arif <usamaarif642@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org, riel@surriel.com,
	shakeel.butt@linux.dev, roman.gushchin@linux.dev,
	yuzhao@google.com, david@redhat.com, baohua@kernel.org,
	ryan.roberts@arm.com, rppt@kernel.org, willy@infradead.org,
	cerasuolodomenico@gmail.com, corbet@lwn.net,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	kernel-team@meta.com, Shuang Zhai <zhais@google.com>
Subject: Re: [PATCH v2 1/4] mm: free zapped tail pages when splitting isolated thp
Date: Wed, 7 Aug 2024 15:45:12 -0400	[thread overview]
Message-ID: <20240807194512.GA1828817@cmpxchg.org> (raw)
In-Reply-To: <20240807134732.3292797-2-usamaarif642@gmail.com>

On Wed, Aug 07, 2024 at 02:46:46PM +0100, Usama Arif wrote:
> From: Yu Zhao <yuzhao@google.com>
> 
> If a tail page has only two references left, one inherited from the
> isolation of its head and the other from lru_add_page_tail() which we
> are about to drop, it means this tail page was concurrently zapped.
> Then we can safely free it and save page reclaim or migration the
> trouble of trying it.
> 
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> Tested-by: Shuang Zhai <zhais@google.com>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> ---
>  mm/huge_memory.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 0167dc27e365..35c1089d8d61 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2923,7 +2923,9 @@ static void __split_huge_page(struct page *page, struct list_head *list,
>  	unsigned int new_nr = 1 << new_order;
>  	int order = folio_order(folio);
>  	unsigned int nr = 1 << order;
> +	struct folio_batch free_folios;
>  
> +	folio_batch_init(&free_folios);
>  	/* complete memcg works before add pages to LRU */
>  	split_page_memcg(head, order, new_order);
>  
> @@ -3007,6 +3009,26 @@ static void __split_huge_page(struct page *page, struct list_head *list,
>  		if (subpage == page)
>  			continue;
>  		folio_unlock(new_folio);
> +		/*
> +		 * If a folio has only two references left, one inherited
> +		 * from the isolation of its head and the other from
> +		 * lru_add_page_tail() which we are about to drop, it means this
> +		 * folio was concurrently zapped. Then we can safely free it
> +		 * and save page reclaim or migration the trouble of trying it.
> +		 */
> +		if (list && page_ref_freeze(subpage, 2)) {

folio_ref_freeze(new_folio, 2)?

Otherwise looks good to me

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

  reply	other threads:[~2024-08-07 19:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 13:46 [PATCH v2 0/4] mm: split underutilized THPs Usama Arif
2024-08-07 13:46 ` [PATCH v2 1/4] mm: free zapped tail pages when splitting isolated thp Usama Arif
2024-08-07 19:45   ` Johannes Weiner [this message]
2024-08-08 15:56   ` David Hildenbrand
2024-08-07 13:46 ` [PATCH v2 2/4] mm: remap unused subpages to shared zeropage " Usama Arif
2024-08-07 20:02   ` Johannes Weiner
2024-08-08 15:53     ` Usama Arif
2024-08-07 13:46 ` [PATCH v2 3/4] mm: selftest to verify zero-filled pages are mapped to zeropage Usama Arif
2024-08-07 13:46 ` [PATCH v2 4/4] mm: split underutilized THPs Usama Arif
2024-08-08 15:55   ` David Hildenbrand
2024-08-09 10:31     ` Usama Arif
2024-08-09 13:21       ` David Hildenbrand
2024-08-09 14:25         ` Usama Arif

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=20240807194512.GA1828817@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=cerasuolodomenico@gmail.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=kernel-team@meta.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=usamaarif642@gmail.com \
    --cc=willy@infradead.org \
    --cc=yuzhao@google.com \
    --cc=zhais@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