linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Gladyshev Ilya <gladyshev.ilya1@h-partners.com>
Cc: Gorbunov Ivan <gorbunov.ivan@h-partners.com>,
	David Hildenbrand <david@kernel.org>,
	Kiryl Shutsemau <kas@kernel.org>, Zi Yan <ziy@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Muchun Song <muchun.song@linux.dev>,
	Will Deacon <will@kernel.org>, Yu Zhao <yuzhao@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] mm: make ref_unless functions unless_zero only
Date: Mon, 2 Mar 2026 13:34:04 +0000	[thread overview]
Message-ID: <54591d9e-0298-4907-8c51-84e45d62e551@lucifer.local> (raw)
In-Reply-To: <a0c89b49d38c671a0bdd35069d15ee13e08314d2.1772370066.git.gladyshev.ilya1@h-partners.com>

On Sun, Mar 01, 2026 at 01:19:39PM +0000, Gladyshev Ilya wrote:
> There are no users of (folio/page)_ref_add_unless(page, nr, u) with
> u != 0 [1] and all current users are "internal" for page refcounting API.
> This allows us to safely drop this parameter and reduce function
> semantics to the "unless zero" cases only.
>
> If needed, these functions for the u!=0 cases can be trivially
> reintroduced later using the same atomic_add_unless operations as before.
>
> [1]: The last user was dropped in v5.18 kernel, commit 27674ef6c73f
> ("mm: remove the extra ZONE_DEVICE struct page refcount"). There is no
> trace of discussion as to why this cleanup wasn't done earlier.
>
> Co-developed-by: Gorbunov Ivan <gorbunov.ivan@h-partners.com>
> Signed-off-by: Gorbunov Ivan <gorbunov.ivan@h-partners.com>
> Signed-off-by: Gladyshev Ilya <gladyshev.ilya1@h-partners.com>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Acked-by: Kiryl Shutsemau <kas@kernel.org>
> Acked-by: Zi Yan <ziy@nvidia.com>

Nice cleanup, thanks! LGTM so:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

>
> ---
> Changes since v1:
> - Rebased on mm-new
> - Remove mention of the "next patch" from commit msg
>
> No functional changes
>
> Link to v1: https://lore.kernel.org/all/20260206133328.426921-1-gladyshev.ilya1@h-partners.com
>
> ---
>  include/linux/mm.h       |  2 +-
>  include/linux/page_ref.h | 12 ++++++------
>  2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index a68f065399ee..1294d29c8d93 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1506,7 +1506,7 @@ static inline int folio_put_testzero(struct folio *folio)
>   */
>  static inline bool get_page_unless_zero(struct page *page)
>  {
> -	return page_ref_add_unless(page, 1, 0);
> +	return page_ref_add_unless_zero(page, 1);
>  }
>
>  static inline struct folio *folio_get_nontail_page(struct page *page)
> diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
> index 490d0ad6e56d..94d3f0e71c06 100644
> --- a/include/linux/page_ref.h
> +++ b/include/linux/page_ref.h
> @@ -228,18 +228,18 @@ static inline int folio_ref_dec_return(struct folio *folio)
>  	return page_ref_dec_return(&folio->page);
>  }
>
> -static inline bool page_ref_add_unless(struct page *page, int nr, int u)
> +static inline bool page_ref_add_unless_zero(struct page *page, int nr)
>  {
> -	bool ret = atomic_add_unless(&page->_refcount, nr, u);
> +	bool ret = atomic_add_unless(&page->_refcount, nr, 0);
>
>  	if (page_ref_tracepoint_active(page_ref_mod_unless))
>  		__page_ref_mod_unless(page, nr, ret);
>  	return ret;
>  }
>
> -static inline bool folio_ref_add_unless(struct folio *folio, int nr, int u)
> +static inline bool folio_ref_add_unless_zero(struct folio *folio, int nr)
>  {
> -	return page_ref_add_unless(&folio->page, nr, u);
> +	return page_ref_add_unless_zero(&folio->page, nr);
>  }
>
>  /**
> @@ -255,12 +255,12 @@ static inline bool folio_ref_add_unless(struct folio *folio, int nr, int u)
>   */
>  static inline bool folio_try_get(struct folio *folio)
>  {
> -	return folio_ref_add_unless(folio, 1, 0);
> +	return folio_ref_add_unless_zero(folio, 1);
>  }
>
>  static inline bool folio_ref_try_add(struct folio *folio, int count)
>  {
> -	return folio_ref_add_unless(folio, count, 0);
> +	return folio_ref_add_unless_zero(folio, count);
>  }
>
>  static inline int page_ref_freeze(struct page *page, int count)
> --
> 2.43.0
>


      reply	other threads:[~2026-03-02 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-01 13:19 Gladyshev Ilya
2026-03-02 13:34 ` Lorenzo Stoakes [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=54591d9e-0298-4907-8c51-84e45d62e551@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=gladyshev.ilya1@h-partners.com \
    --cc=gorbunov.ivan@h-partners.com \
    --cc=kas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=will@kernel.org \
    --cc=yuzhao@google.com \
    --cc=ziy@nvidia.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