linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sidhartha Kumar <sidhartha.kumar@oracle.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Muchun Song <muchun.song@linux.dev>
Subject: Re: [PATCH] hugetlb: Convert alloc_buddy_hugetlb_folio to use a folio
Date: Tue, 2 Apr 2024 14:19:51 -0700	[thread overview]
Message-ID: <ab794542-b0ea-47e2-8486-723f94caee8e@oracle.com> (raw)
In-Reply-To: <20240402200656.913841-1-willy@infradead.org>

On 4/2/24 1:06 PM, Matthew Wilcox (Oracle) wrote:
> While this function returned a folio, it was still using __alloc_pages()
> and __free_pages().  Use __folio_alloc() and put_folio() instead.  This
> actually removes a call to compound_head(), but more importantly, it
> prepares us for the move to memdescs.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>   mm/hugetlb.c | 33 ++++++++++++++++-----------------
>   1 file changed, 16 insertions(+), 17 deletions(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index a3bffa8debde..5f1e0b1a0d57 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2177,13 +2177,13 @@ static struct folio *alloc_buddy_hugetlb_folio(struct hstate *h,
>   		nodemask_t *node_alloc_noretry)
>   {
>   	int order = huge_page_order(h);
> -	struct page *page;
> +	struct folio *folio;
>   	bool alloc_try_hard = true;
>   	bool retry = true;
>   
>   	/*
> -	 * By default we always try hard to allocate the page with
> -	 * __GFP_RETRY_MAYFAIL flag.  However, if we are allocating pages in
> +	 * By default we always try hard to allocate the folio with
> +	 * __GFP_RETRY_MAYFAIL flag.  However, if we are allocating folios in
>   	 * a loop (to adjust global huge page counts) and previous allocation
>   	 * failed, do not continue to try hard on the same node.  Use the
>   	 * node_alloc_noretry bitmap to manage this state information.
> @@ -2196,43 +2196,42 @@ static struct folio *alloc_buddy_hugetlb_folio(struct hstate *h,
>   	if (nid == NUMA_NO_NODE)
>   		nid = numa_mem_id();
>   retry:
> -	page = __alloc_pages(gfp_mask, order, nid, nmask);
> +	folio = __folio_alloc(gfp_mask, order, nid, nmask);
>   
> -	/* Freeze head page */
> -	if (page && !page_ref_freeze(page, 1)) {
> -		__free_pages(page, order);
> +	if (folio && !folio_ref_freeze(folio, 1)) {
> +		folio_put(folio);
>   		if (retry) {	/* retry once */
>   			retry = false;
>   			goto retry;
>   		}
>   		/* WOW!  twice in a row. */
> -		pr_warn("HugeTLB head page unexpected inflated ref count\n");
> -		page = NULL;
> +		pr_warn("HugeTLB unexpected inflated folio ref count\n");
> +		folio = NULL;
>   	}
>   
>   	/*
> -	 * If we did not specify __GFP_RETRY_MAYFAIL, but still got a page this
> -	 * indicates an overall state change.  Clear bit so that we resume
> -	 * normal 'try hard' allocations.
> +	 * If we did not specify __GFP_RETRY_MAYFAIL, but still got a
> +	 * folio this indicates an overall state change.  Clear bit so
> +	 * that we resume normal 'try hard' allocations.
>   	 */
> -	if (node_alloc_noretry && page && !alloc_try_hard)
> +	if (node_alloc_noretry && folio && !alloc_try_hard)
>   		node_clear(nid, *node_alloc_noretry);
>   
>   	/*
> -	 * If we tried hard to get a page but failed, set bit so that
> +	 * If we tried hard to get a folio but failed, set bit so that
>   	 * subsequent attempts will not try as hard until there is an
>   	 * overall state change.
>   	 */
> -	if (node_alloc_noretry && !page && alloc_try_hard)
> +	if (node_alloc_noretry && !folio && alloc_try_hard)
>   		node_set(nid, *node_alloc_noretry);
>   
> -	if (!page) {
> +	if (!folio) {
>   		__count_vm_event(HTLB_BUDDY_PGALLOC_FAIL);
>   		return NULL;
>   	}
>   
>   	__count_vm_event(HTLB_BUDDY_PGALLOC);
> -	return page_folio(page);
> +	return folio;
>   }
>   
>   static struct folio *__alloc_fresh_hugetlb_folio(struct hstate *h,
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>


  reply	other threads:[~2024-04-02 21:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 20:06 Matthew Wilcox (Oracle)
2024-04-02 21:19 ` Sidhartha Kumar [this message]
2024-04-03  4:55 ` Oscar Salvador
2024-04-03  6:19   ` Muchun Song
2024-04-03  7:25     ` Oscar Salvador
2024-04-03 21:17       ` Matthew Wilcox
2024-04-04 11:13         ` Oscar Salvador
2024-04-07  7:14           ` Muchun Song
2024-04-03  6:00 ` Muchun Song

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=ab794542-b0ea-47e2-8486-723f94caee8e@oracle.com \
    --to=sidhartha.kumar@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=willy@infradead.org \
    /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