From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76EF1261B9E for ; Wed, 11 Mar 2026 04:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773204743; cv=none; b=OVWpIDvRLNwFak+EPe3zm/xpZBJlzZaUxcIg83Peqr4Z7vBb1kcnDxhML4Opwy06EsKiv/L5Q9h0BwzKk/1GusFvZ+rDAVQty8PY+3WgySV5jqQFAuAaEbN3DlXHupPwldPXJx77WfBUok4m/2uZR3HhtjHpryrO1REK01WzTVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773204743; c=relaxed/simple; bh=AV/mZ3gNQzsLUGpJSC+27QS+tJ+b7vLlaQAA5ivnX+U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PTajBSkEVWT+PKfsfjDr2JwD31zHJFHSR+sSa4NJCiKPhmv7ORk8QN1kRcb8zmuUQCWhqUuQSbNmkhC3VHLWb5VUhdSojwXa1gEEx9qx4Vr2QgAMgDeT6f7ZAt699zbhYXNxDmCopmUjuUfrXql4s6IBKD0ki606i1326t7IWLc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=YgPf4gzY; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="YgPf4gzY" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773204739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vcx2tEiM5H2TyNtKlNF/IXle4ed2aOsVuUva7tVU4ck=; b=YgPf4gzYEQFnc2G2R71vHKH2wNhu/NkhsvJENqvp6gxGBcUCh2KRtpTtTaVSAoN1E+H5Ud +TPEdKlc5NZpMYuA/F7u2br/L4behR5oIf4nDTpHfXXZS5Knx9645OuyL8op5axLAWqubH ikU6AJ2BLGupt/sqhbtQ/Dy8Xm8yeyU= Date: Wed, 11 Mar 2026 12:52:02 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v5 2/4] mm: huge_memory: refactor anon_enabled_store() with change_anon_orders() Content-Language: en-US To: Wei Yang , Breno Leitao Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org, usamaarif642@gmail.com, kas@kernel.org, kernel-team@meta.com, "Lorenzo Stoakes (Oracle)" References: <20260310-thp_logs-v5-0-686099175bf6@debian.org> <20260310-thp_logs-v5-2-686099175bf6@debian.org> <20260311031229.mloqvlmmqipr7k2h@master> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260311031229.mloqvlmmqipr7k2h@master> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/3/11 11:12, Wei Yang wrote: > On Tue, Mar 10, 2026 at 10:57:08AM -0700, Breno Leitao wrote: >> Consolidate the repeated spin_lock/set_bit/clear_bit pattern in >> anon_enabled_store() into a new change_anon_orders() helper that >> loops over an orders[] array, setting the bit for the selected mode >> and clearing the others. >> >> Introduce enum anon_enabled_mode and anon_enabled_mode_strings[] >> for the per-order anon THP setting. >> >> Use sysfs_match_string() with the anon_enabled_mode_strings[] table >> to replace the if/else chain of sysfs_streq() calls. >> >> The helper uses test_and_set_bit()/test_and_clear_bit() to track >> whether the state actually changed, so start_stop_khugepaged() is >> only called when needed. When the mode is unchanged, >> set_recommended_min_free_kbytes() is called directly to preserve >> the watermark recalculation behavior of the original code. >> >> Signed-off-by: Breno Leitao >> Reviewed-by: Lorenzo Stoakes (Oracle) >> --- >> mm/huge_memory.c | 84 +++++++++++++++++++++++++++++++++++--------------------- >> 1 file changed, 52 insertions(+), 32 deletions(-) >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 8e2746ea74adf..e19dda5aaf195 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -316,6 +316,20 @@ static ssize_t enabled_show(struct kobject *kobj, >> return sysfs_emit(buf, "%s\n", output); >> } >> >> +enum anon_enabled_mode { >> + ANON_ENABLED_ALWAYS = 0, >> + ANON_ENABLED_MADVISE = 1, >> + ANON_ENABLED_INHERIT = 2, >> + ANON_ENABLED_NEVER = 3, >> +}; >> + >> +static const char * const anon_enabled_mode_strings[] = { >> + [ANON_ENABLED_ALWAYS] = "always", >> + [ANON_ENABLED_MADVISE] = "madvise", >> + [ANON_ENABLED_INHERIT] = "inherit", >> + [ANON_ENABLED_NEVER] = "never", >> +}; >> + > > Just one trivial thing, maybe keep the sequence as the sysfs output? > > Currently the output of /sys/kernel/transparent_hugepage/hugepages-xxxkB is > > always inherit madvise [never] > > But no strong opinion on this. Yeah, keeping the enum order consistent with the sysfs output looks sensible :) Apart from that, LGTM. Reviewed-by: Lance Yang