linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <ljs@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	 Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	 Barry Song <baohua@kernel.org>,
	Lance Yang <lance.yang@linux.dev>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH v2 2/2] mm: huge_memory: refactor defrag_show() to use defrag_flags[]
Date: Sat, 18 Apr 2026 10:47:53 +0100	[thread overview]
Message-ID: <aeNSquoJ9gjTJ90p@lucifer> (raw)
In-Reply-To: <20260408-thp_defrag-v2-2-bc544c1bde4e@debian.org>

On Wed, Apr 08, 2026 at 08:47:01AM -0700, Breno Leitao wrote:
> Replace the hardcoded if/else chain of test_bit() calls and string
> literals in defrag_show() with a loop over defrag_flags[] and
> defrag_mode_strings[] arrays introduced in the previous commit.
>
> This makes defrag_show() consistent with defrag_store() and eliminates
> the duplicated mode name strings.
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Tested-by: Lance Yang <lance.yang@linux.dev>
> Reviewed-by: Lance Yang <lance.yang@linux.dev>
> Reviewed-by: Barry Song <baohua@kernel.org>
> Signed-off-by: Breno Leitao <leitao@debian.org>

I almost made a comment, but then realised it was fine :P so LGTM and:

Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>

> ---
>  mm/huge_memory.c | 38 ++++++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 16 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 76f2d32428c7f..6993c6d8709dc 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -455,24 +455,30 @@ static const enum transparent_hugepage_flag defrag_flags[] = {
>  static ssize_t defrag_show(struct kobject *kobj,
>  			   struct kobj_attribute *attr, char *buf)
>  {
> -	const char *output;
> +	int active = DEFRAG_NEVER;
> +	int len = 0;
> +	int i;
>
> -	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
> -		     &transparent_hugepage_flags))
> -		output = "[always] defer defer+madvise madvise never";
> -	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
> -			  &transparent_hugepage_flags))
> -		output = "always [defer] defer+madvise madvise never";
> -	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
> -			  &transparent_hugepage_flags))
> -		output = "always defer [defer+madvise] madvise never";
> -	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
> -			  &transparent_hugepage_flags))
> -		output = "always defer defer+madvise [madvise] never";
> -	else
> -		output = "always defer defer+madvise madvise [never]";
> +	for (i = 0; i < ARRAY_SIZE(defrag_flags); i++) {
> +		if (test_bit(defrag_flags[i], &transparent_hugepage_flags)) {
> +			active = i;
> +			break;
> +		}
> +	}
>
> -	return sysfs_emit(buf, "%s\n", output);
> +	for (i = 0; i < ARRAY_SIZE(defrag_mode_strings); i++) {
> +		if (i == active)
> +			len += sysfs_emit_at(buf, len, "[%s] ",
> +					     defrag_mode_strings[i]);
> +		else
> +			len += sysfs_emit_at(buf, len, "%s ",

I mean, we'll end up with a single trailing space, but I think we can
probably... oh wait hang on...

> +					     defrag_mode_strings[i]);
> +	}
> +
> +	/* Replace trailing space with newline */
> +	buf[len - 1] = '\n';

...OK :)

> +
> +	return len;
>  }
>
>  static ssize_t defrag_store(struct kobject *kobj,
>
> --
> 2.52.0
>

Cheers, Lorenzo


  reply	other threads:[~2026-04-18  9:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 15:46 [PATCH v2 0/2] mm: huge_memory: clean up defrag sysfs with shared data tables Breno Leitao
2026-04-08 15:47 ` [PATCH v2 1/2] mm: huge_memory: use sysfs_match_string() in defrag_store() Breno Leitao
2026-04-18  9:45   ` Lorenzo Stoakes
2026-04-08 15:47 ` [PATCH v2 2/2] mm: huge_memory: refactor defrag_show() to use defrag_flags[] Breno Leitao
2026-04-18  9:47   ` Lorenzo Stoakes [this message]
2026-04-08 16:04 ` [PATCH v2 0/2] mm: huge_memory: clean up defrag sysfs with shared data tables Zi Yan

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=aeNSquoJ9gjTJ90p@lucifer \
    --to=ljs@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=kernel-team@meta.com \
    --cc=lance.yang@linux.dev \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.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