From nobody Thu Apr 9 15:10:15 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 782082E888A for ; Sat, 7 Mar 2026 16:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899728; cv=none; b=qXVC4UI28OQp39ZXipXBTLnzMa3juEq+uKvIdSa5e1csf06NhXT9BhmVw5Hm+jn/qZq7MfFYpkoP4cnrqS6dbC8O9AvAN473Gl0SgDbyDzqkHWyIYmSukMjBF4yu+I+Qaw31Urm9n12EbKu7pyBwZfm2+N95fIE+M9a2oSovfzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899728; c=relaxed/simple; bh=nlToZmaB1n6dDw+eMzdYWKgFtlcgYp+PAKEi0NGirZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=stIOI91sJF5jpdPBcbMYya/mYg0h0WUVSWY/vI6p4h7kQyCs5zd9R6zigMbDdCZzZo73R4bj2kXqjUcMAfvYL7gS3hf725qnSWIZulNNoCmykD9p2KuFuq1Qylx/uVL9HKzgTIYXbv6KEdin/e+QuGCcM75GMSiO8c/dss9on0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=eT8VmgpA; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="eT8VmgpA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=XWwVHwhFxPwZWzEvxtvZzmQI5X0pdoxE0LNq0dsk950=; b=eT8VmgpA4tPqQycYOYqOZCmKTg xvFkQUi/k68fZ9amprgPmd2KagoVRiso3gqcaX0K5MUzHJVbHsF0d1cj4Mu7lEWsPgwnjmw4AFNu4 C/JJZSkv8KzCfQwQGfrI5+odHMLXM7RtSlj9rW4B+7lPwbGo3x9MxrSq3rnEDGTfiu33/qhp8/R82 1U5G/QETEPtbdbtBnJmUYdcwdru2qIuEKZWWc6Zkd2tVTAptQWGcMqZYXOoalxmTppRrh5h5W/weW d6B5kfNFVUoyWBYqoRUNzMS+CA+tJcxd3vKSaiq22GOowlcDW12NGFMlCDclCnmU7hgCmjHcaof47 tqUl9I0w==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1vyuCj-000nEa-ID; Sat, 07 Mar 2026 16:08:37 +0000 From: Breno Leitao Date: Sat, 07 Mar 2026 08:08:05 -0800 Subject: [PATCH v3 1/4] mm: khugepaged: export set_recommended_min_free_kbytes() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260307-thp_logs-v3-1-a45d2c8f3685@debian.org> References: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> In-Reply-To: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, usamaarif642@gmail.com, kas@kernel.org, kernel-team@meta.com, "Lorenzo Stoakes (Oracle)" , Breno Leitao X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=1306; i=leitao@debian.org; h=from:subject:message-id; bh=nlToZmaB1n6dDw+eMzdYWKgFtlcgYp+PAKEi0NGirZY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprE14+evRyvdKxaDGyxMGTTyJb0VRMtiwTvLeJ dIz7YpRrCKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaaxNeAAKCRA1o5Of/Hh3 bXiED/kBAQZNjkicewFQbE4GK0Mp6mmXS/Bii4ayWO98XHh1pYI+T88J2dgXy99YxBYuXemKaiX EcBjcAB8U05WNsV/P0RzS6JDdgXNE+xYvwRcdRumXJ/+Vbp00T9Q5kdtjphg+vuVp1vBHuVS0rk E8+CHhTDCIXrN15GMTWp1oCEKKc4uvA4s7dvxM/8BBwBN247Yr9I80jBxTIHRf+k2r9Zu3mo621 IH2AXs39IPTFIfSDdX/nM1jkdMnG/4hJWudzUSm2HshLuh8DG7DjezLe79WKENgTqTGfT3FEBPK pVCWmCZ9bHAIaoea/3gb8YfLOBEc4wcu9ln3bF/jkteEBKl0YGTmwJGK/iZ67MD6BIDvNAj3ZrK i5gaJPrWuYgfw9+3yBA6+GpGGUIngORxZ837/Es6y8N4Ugp8wukzn1U4LMXlKtCGBuIbl4fC4M0 4e3sOlr1Xyftcoj3WEy4zvHFgSSsGkm1x6fsjLrEuzIrSroCaQ1f+hLz/xFA5iawD05WZ76AWpG WK0csuGO3E0dN3fVnlOIFftTcWnaZnJK/QysXPU7sH34cZkTcskclBKmkC9LqY+fd1hWQSDL2mm nB7SUnoj1G7iIQzA8i9IXIabI1prKjg7ksu1cH+uzH5Sb5O8GARo7xdkffc+ikJE+g2sL6DDWsA ieq/WfkLvyv5YXg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Make set_recommended_min_free_kbytes() callable from outside khugepaged.c by removing the static qualifier and adding a declaration in mm/internal.h. This allows callers that change THP settings to recalculate watermarks without going through start_stop_khugepaged(). Suggested-by: Lorenzo Stoakes (Oracle) Signed-off-by: Breno Leitao Reviewed-by: Lorenzo Stoakes (Oracle) --- mm/internal.h | 5 +++++ mm/khugepaged.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/internal.h b/mm/internal.h index cb0af847d7d99..7bd768e367793 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -623,6 +623,11 @@ int user_proactive_reclaim(char *buf, */ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address); =20 +/* + * in mm/khugepaged.c + */ +void set_recommended_min_free_kbytes(void); + /* * in mm/page_alloc.c */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 1dd3cfca610db..56a41c21b44c9 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2630,7 +2630,7 @@ static int khugepaged(void *none) return 0; } =20 -static void set_recommended_min_free_kbytes(void) +void set_recommended_min_free_kbytes(void) { struct zone *zone; int nr_zones =3D 0; --=20 2.47.3 From nobody Thu Apr 9 15:10:15 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 5936D30EF9A for ; Sat, 7 Mar 2026 16:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899732; cv=none; b=KRfkN5mBN6/ER2Top9kVwqFloZG7iGypiW7niBsKqHyGAmCcdDXuJMDjfg+AQPdyBDtw73TJapJcORqBkHSqT5jqlj0d9IzC6PQMY9mfF3LLNS3QDmqQnS5NDE7rwCpq9GGYd3HthoMNKoPYA4QtcrnnqetZWYJbw5u7/ltfDeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899732; c=relaxed/simple; bh=/1eLIdHPUDcvIpxBXzEH0x3IBBqIpnLjC8GGQWUs0vI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JqHzDeLjajBPWUoFtmzdd+TiuFvltfhM3KQKTTcsIfa8geV7lqTuYPc/3d7jI+5jEwgOESkn+fpnMsqKvGJR6onPiGIzdt7gJQ3R8LRHlLMzZG8LvbytUpOeUTSD1XyXCGShvDz07B7mvKYpvSccouOSRFu7nnp6e9RgTHsVivU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=RpL+LiTn; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="RpL+LiTn" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=MmDCySQR75AVk0G7ci1h/kEC5miQyqWVJmvwkT82m+0=; b=RpL+LiTnoiDsgV78/8WS8ttgTb ZsmBF9ssOwmpVcJlDEZKbeS+gtSQZVlX/sp9Pzaexm/PQ8bCXwBe+PKAEb7Y7DOHBcFOt3NgySK4Y KGRiZrzGYmZXWS/bxOGeAZ8ccEsZgULBWbwBe/xBU//J9kaSj6HuZDZI6cfUpGHFfIr1NykXCh9f2 6WzeeUg56bBtiDLxStoKQKwoqNsWmoARKN6Drn7Y02tgeg6BwFS4kLI7HMOinhnBTNDcfj46943ge 8GnG+13pfC2Yx+w5U8CdMATDHxlux0G8agRf9xawP/UA62J9YZMKFSIXEhUC5LOuAydsbV8XJBYXP 6SUJ0KSw==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1vyuCp-000nEg-CY; Sat, 07 Mar 2026 16:08:43 +0000 From: Breno Leitao Date: Sat, 07 Mar 2026 08:08:06 -0800 Subject: [PATCH v3 2/4] mm: huge_memory: refactor anon_enabled_store() with change_anon_orders() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260307-thp_logs-v3-2-a45d2c8f3685@debian.org> References: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> In-Reply-To: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, usamaarif642@gmail.com, kas@kernel.org, kernel-team@meta.com, Breno Leitao , "Lorenzo Stoakes (Oracle)" X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=4393; i=leitao@debian.org; h=from:subject:message-id; bh=/1eLIdHPUDcvIpxBXzEH0x3IBBqIpnLjC8GGQWUs0vI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprE14ggv8eqItj5fMOtP7NI8WiFHHpkVrd8wfU TZwIe4ToJ+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaaxNeAAKCRA1o5Of/Hh3 bYzMD/92I3HOSF/fOgXxnBNEfHeYuzs1HW42exZ5kHHQkpteZS92Ko3J5hADsYJlPZNUV+taKBj Vx3SmbJLfn34uCfU7hposW1qqhrmGAVZKZv9VL88hNtFpjv0ryqTU4HPpADkCvTg375TCzQyIy5 YaqOkGj2mTacqGZk+9QrfwcfziakMA4GJ52pihbWktcxd9Z2IywFp08P8NF1MJ8GF2nlGEfTRqi TkXaKCEvD5EU/DfpyLbKTLvPMX0LNgrH7iFcVYL0hdREE8p8lCefYnr1AKjynzCt1KmAqZCPr0h TNCQsQXmDzbACkSxJpoX192zsKtCWhyK9Dv666ky3tbvFp7rRzhvexjEcry0lPiWRaOPtFQwomX tOqmLA0cKVqmrxniyd6gN14LHULh9mRuCBUDFpj7hCRuqFRe1ce8ayLIekLrqCLFbAaW0iALa5u EKgHNOUL00Gn8LXYEIe62shrQHs1Us6XMoUTJzFxm4Sdb5AFv2f1yvWn+XTs1qy3Pf170XZEiZw SmPDHR8cUGNTMkuxv2T0fWbZFb+q7USUs2iZKdg8y9vJFArx+UBHJhNWqWUIwHqS4oEQqIPyBmn 5yzXQuxR/WyudBuWUGebEGk6HyvQXQZwTy2Rpjn5Sj87G1BI2GggFqGyJ9NlzLJqsJkXdGeXUY9 GGeXafGfOTgHzKw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao 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..17ce6a16702bf 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); } =20 +enum anon_enabled_mode { + ANON_ENABLED_ALWAYS, + ANON_ENABLED_MADVISE, + ANON_ENABLED_INHERIT, + ANON_ENABLED_NEVER, +}; + +static const char * const anon_enabled_mode_strings[] =3D { + [ANON_ENABLED_ALWAYS] =3D "always", + [ANON_ENABLED_MADVISE] =3D "madvise", + [ANON_ENABLED_INHERIT] =3D "inherit", + [ANON_ENABLED_NEVER] =3D "never", +}; + static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) @@ -515,48 +529,54 @@ static ssize_t anon_enabled_show(struct kobject *kobj, return sysfs_emit(buf, "%s\n", output); } =20 +static bool change_anon_orders(int order, enum anon_enabled_mode mode) +{ + static unsigned long *orders[] =3D { + &huge_anon_orders_always, + &huge_anon_orders_madvise, + &huge_anon_orders_inherit, + }; + bool changed =3D false; + int i; + + spin_lock(&huge_anon_orders_lock); + for (i =3D 0; i < ARRAY_SIZE(orders); i++) { + if (i =3D=3D mode) + changed |=3D !test_and_set_bit(order, orders[i]); + else + changed |=3D test_and_clear_bit(order, orders[i]); + } + spin_unlock(&huge_anon_orders_lock); + + return changed; +} + static ssize_t anon_enabled_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int order =3D to_thpsize(kobj)->order; - ssize_t ret =3D count; + int mode; =20 - if (sysfs_streq(buf, "always")) { - spin_lock(&huge_anon_orders_lock); - clear_bit(order, &huge_anon_orders_inherit); - clear_bit(order, &huge_anon_orders_madvise); - set_bit(order, &huge_anon_orders_always); - spin_unlock(&huge_anon_orders_lock); - } else if (sysfs_streq(buf, "inherit")) { - spin_lock(&huge_anon_orders_lock); - clear_bit(order, &huge_anon_orders_always); - clear_bit(order, &huge_anon_orders_madvise); - set_bit(order, &huge_anon_orders_inherit); - spin_unlock(&huge_anon_orders_lock); - } else if (sysfs_streq(buf, "madvise")) { - spin_lock(&huge_anon_orders_lock); - clear_bit(order, &huge_anon_orders_always); - clear_bit(order, &huge_anon_orders_inherit); - set_bit(order, &huge_anon_orders_madvise); - spin_unlock(&huge_anon_orders_lock); - } else if (sysfs_streq(buf, "never")) { - spin_lock(&huge_anon_orders_lock); - clear_bit(order, &huge_anon_orders_always); - clear_bit(order, &huge_anon_orders_inherit); - clear_bit(order, &huge_anon_orders_madvise); - spin_unlock(&huge_anon_orders_lock); - } else - ret =3D -EINVAL; + mode =3D sysfs_match_string(anon_enabled_mode_strings, buf); + if (mode < 0) + return -EINVAL; =20 - if (ret > 0) { - int err; + if (change_anon_orders(order, mode)) { + int err =3D start_stop_khugepaged(); =20 - err =3D start_stop_khugepaged(); if (err) - ret =3D err; + return err; + } else { + /* + * Recalculate watermarks even when the mode didn't + * change, as the previous code always called + * start_stop_khugepaged() which does this internally. + */ + set_recommended_min_free_kbytes(); } - return ret; + + return count; } =20 static struct kobj_attribute anon_enabled_attr =3D --=20 2.47.3 From nobody Thu Apr 9 15:10:15 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 27A35303A12 for ; Sat, 7 Mar 2026 16:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899733; cv=none; b=mop7/ku2qyyOQtSeFuDMkvbQvmzYgVUTUlJFpKxOgocrZq5qGl2ysJE4LBKWryj3JhJso84v77xcjDXHt6O2V0uwFCYZgauc6eqJa13h1xdrEI2uYvzn53ojTCcHx+oVa8kK6AKe30PnL2MgOJc2K1xq0/snUcB3p/Q27flVmYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899733; c=relaxed/simple; bh=zlsaZ8kaCXcEEWIfMU8ynz2khbS/0r7SuYWkIjlj6TQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gGLvu8cTMP6tU8N9ByORR9aVr1bgnGqNrhOtt+Reoxeh7n4Mx1asyE4aOgIO3e44L7VPgSa2fSDJh+LC7SidSLaXb81Wu+qwLquiwroBvEjz0/QK8HStneyUd305HBgd7gjYR5Tzol2onPL1wrpbojZrP0jP2KKulyO/xb2haEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=EI/k/aux; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="EI/k/aux" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=3BNLcjJkZMBW12wECnG4ZYadEB66BxAZDl3NHar6Yso=; b=EI/k/auxY1T02XN/UP4PqDzHrL slPATE+jk30i/S8biwszCh2iE4Zb9ARBGw3CwesLF2KbuWagwu2y6Ij5TVb5x+sF4ifvze9eXfOSV iDc13K6BCgrHCxqorCEn1VptlJ636ttS64jUZi8c5JHGOryv/v/dVLra6H1eQkapFGWlgnWp3WS41 hzP8625taHtht+cUPTPSD4Z5vGBX3WdedzDYXjyDJhCxaIcQWx1iZWpW1WeED0/z8rsNsJNA0xvPz K0JG9XlVQ5kpMWDv7vnUwCOego5wQasxcOv8tPAZB/AxTnOnvfPSgl5K14QG67sM5H+Niuu4xRHCs Sq9yzDgw==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1vyuCv-000nEt-Hx; Sat, 07 Mar 2026 16:08:49 +0000 From: Breno Leitao Date: Sat, 07 Mar 2026 08:08:07 -0800 Subject: [PATCH v3 3/4] mm: huge_memory: refactor enabled_store() with change_enabled() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260307-thp_logs-v3-3-a45d2c8f3685@debian.org> References: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> In-Reply-To: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, usamaarif642@gmail.com, kas@kernel.org, kernel-team@meta.com, Breno Leitao , "Lorenzo Stoakes (Oracle)" X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=3425; i=leitao@debian.org; h=from:subject:message-id; bh=zlsaZ8kaCXcEEWIfMU8ynz2khbS/0r7SuYWkIjlj6TQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprE14/7kDvB5SOmDe7Zro8AP41H6s3+3zeHxI+ EMzX91akimJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaaxNeAAKCRA1o5Of/Hh3 bUytD/468PRW2gj7l60eHMlh0rUTgGs0T/PmzAmGB06mt60u9k2lCaZFJIkJb48s0st40J0Ayrk sEOPprlA5VYar59IcpJdlYNtT9w3y5XRYKM4b+KDdtiUq5I2Q5sP66AXoaN+NJ7tbKU0Wzn4Kl3 pqtnSEzHF+Zt/AdlWunrLSj2MLYrGXl/9FWm2YJV4rWOD4MKQ+UYJ4UA9wFvdRO1h0JTjxQwwlS zZeoKNAYP3JznzCuKAgWwKcO+YtGwwXq7PjzW7U3zmFOZueCAHhpkPQrKSkjcVusWszmquhbQa6 iAq90h29OzPM1mKC7pAgoMy65q82M3FLS9VtRdD2n/HS/eepPrVGioeD1fs1+RbBkESsRtL8jCB liFSaAXvCcnTG5kwcRwXZ19LYlzB0IlllVLwX4pHOIrVtASck9UwexFkSowU01AT3jPd2Wugkk7 JT1TY1NUpFxPRRistC1Oz5oZEC2axEnRscDVkQGRrjAKVQ8o6CR6+VmbnfedB2SvZsZ/1ReP/bH 7cQCszoDQXgkLAOftYf9PkK2YCrvUpIh3VOlosNdND1PbYpWFzGubSeDoBdfp4sbAPY/87GLdxi NufArKiPTDzlbNpkbq/THj1QonDLcwrrCKYOgY3FO+2bMMALJqUbHJeuFOOX//K5qybGHQ/gpmc 0chCT0kx5PyeUXw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Refactor enabled_store() to use a new change_enabled() helper. Introduce a separate enum global_enabled_mode and global_enabled_mode_strings[], mirroring the anon_enabled_mode pattern from the previous commit. A separate enum is necessary because the global THP setting does not support "inherit", only "always", "madvise", and "never". Reusing anon_enabled_mode would leave a NULL gap in the string array, causing sysfs_match_string() to stop early and fail to match entries after the gap. The helper uses the same loop pattern as change_anon_orders(), iterating over an array of flag bit positions and using test_and_set_bit()/test_and_clear_bit() to track whether the state actually changed. Signed-off-by: Breno Leitao Reviewed-by: Lorenzo Stoakes (Oracle) --- mm/huge_memory.c | 63 ++++++++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 17ce6a16702bf..c38c86e6d0c02 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -330,30 +330,63 @@ static const char * const anon_enabled_mode_strings[]= =3D { [ANON_ENABLED_NEVER] =3D "never", }; =20 +enum global_enabled_mode { + GLOBAL_ENABLED_ALWAYS, + GLOBAL_ENABLED_MADVISE, + GLOBAL_ENABLED_NEVER, +}; + +static const char * const global_enabled_mode_strings[] =3D { + [GLOBAL_ENABLED_ALWAYS] =3D "always", + [GLOBAL_ENABLED_MADVISE] =3D "madvise", + [GLOBAL_ENABLED_NEVER] =3D "never", +}; + +static bool change_enabled(enum global_enabled_mode mode) +{ + static const unsigned long thp_flags[] =3D { + TRANSPARENT_HUGEPAGE_FLAG, + TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + }; + bool changed =3D false; + int i; + + for (i =3D 0; i < ARRAY_SIZE(thp_flags); i++) { + if (i =3D=3D mode) + changed |=3D !test_and_set_bit(thp_flags[i], + &transparent_hugepage_flags); + else + changed |=3D test_and_clear_bit(thp_flags[i], + &transparent_hugepage_flags); + } + + return changed; +} + static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - ssize_t ret =3D count; + int mode; =20 - if (sysfs_streq(buf, "always")) { - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flag= s); - set_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - } else if (sysfs_streq(buf, "madvise")) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags); - } else if (sysfs_streq(buf, "never")) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flag= s); - } else - ret =3D -EINVAL; + mode =3D sysfs_match_string(global_enabled_mode_strings, buf); + if (mode < 0) + return -EINVAL; =20 - if (ret > 0) { + if (change_enabled(mode)) { int err =3D start_stop_khugepaged(); + if (err) - ret =3D err; + return err; + } else { + /* + * Recalculate watermarks even when the mode didn't + * change, as the previous code always called + * start_stop_khugepaged() which does this internally. + */ + set_recommended_min_free_kbytes(); } - return ret; + return count; } =20 static struct kobj_attribute enabled_attr =3D __ATTR_RW(enabled); --=20 2.47.3 From nobody Thu Apr 9 15:10:15 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 2C9F41531C1 for ; Sat, 7 Mar 2026 16:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899738; cv=none; b=YOXrhPXh0KZXrye916ecw5FHR0zmgUQ45BI6CuanW7+BU23zNDbR26cdCZM5xfpAbK50WDtEyx/BPy/GFtCs5hX1wPDnkIIiLjsJCf1xRAfVvLpZiPzdKfe8WPY0S72owXjVjpPC/Xa4S8XRfp9Ti6P9FUJbvVLvqiqbNJ5bSJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772899738; c=relaxed/simple; bh=gxJOAYW1B4QBpNiriL+Xya3ATpxserwPiuGqRjqavaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TBpFsHvhU22Kmi2svrqD/0V/jPpHrTnP6GQrT1IUbjIOO3pN6DM2xnJFtWGCf9bWTWyUwK1Mz2XGu8em1RzucqIMkW4y/YOfcRGuRcqpdgCxwTf/K20WiOw87ThxswJ5sJVWKrtRKaTnJUDNSuLuEqynRiw+9xDZ4c65v6W0WD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=vLA57anC; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="vLA57anC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=wMsK7bM5B63ETngSFYeak+wzJyKrL8AAUXzgpqkd3S8=; b=vLA57anCPTfZr3sKp6F/baWHvv UC8qxxbtwcpSbW2dIyqgABteJ42mbwZq20K7uOdmbaEsqEG0UPEdndunEGCAKfzzc/uuZn2xlPR/w 5FaCcRdUr+XmJF1YFsXfcfr7zOCzDiGEGkWn1vS+DgP5QqyWzujBNv8cZyY0BBdPvxDFS81Kd25fw C3o12YPxGWW+we/xYV/8tD3hKR9uWaMSaE0/Aze6r+xZkXrcnvOKIEPg9Wb3cIfXQl50trHNpxiQh Dj8No0gKpNLBCt2z9GyJxf7TDwa2oJ4jWP/uHC991mJGvi7EGsdSChDKQyWPtNMU/VVudBEPgXtSb uruz+YDw==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1vyuD1-000nKY-3F; Sat, 07 Mar 2026 16:08:55 +0000 From: Breno Leitao Date: Sat, 07 Mar 2026 08:08:08 -0800 Subject: [PATCH v3 4/4] mm: ratelimit min_free_kbytes adjustment messages Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260307-thp_logs-v3-4-a45d2c8f3685@debian.org> References: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> In-Reply-To: <20260307-thp_logs-v3-0-a45d2c8f3685@debian.org> To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, usamaarif642@gmail.com, kas@kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=1843; i=leitao@debian.org; h=from:subject:message-id; bh=gxJOAYW1B4QBpNiriL+Xya3ATpxserwPiuGqRjqavaM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprE146M/jYBIhqmoonwG80+PQZnFGxW0TpZfU5 7lPztdMst2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaaxNeAAKCRA1o5Of/Hh3 bWFdD/4muGHfgN3wEPB53oBk6T1XmgcYkTs113p09NYp6EbEkvPg848y/LKpsID16FKtBpcN/yl yXRE+EAEkew22gpyYrrNTns/e97pk2IDSlwvxNfqspVAyjRumZTirq8VRY6Z1EDr9ESiiJ59OaS cNJjYp6vaoZ6Czi6t44GkZVXZVXYIbOa68SSVThtLQ/FHZB4rWdooHHiBw43GtI4jyQNMqUGmNU PWnlmBXy0yUPwTGxdQG6uN5i72AuKnUr3+MrWjYhfx8/ru9NRmma2Jz+5FuLIDvTTD06RUd/RvE BAqPsV2M7LtZKOlbUUM9a90zBhJhQgYBtbPiUxyU2hDjwGCZwDJTBaRDjq6QqMkcQiougXXHkmd 23hfObnpY68ckXphaNlzCEMTbd3GXNeQ1Jt5VmmeLCCHswD8KCj3Sun2iYHnGzTDl3KAD03tAH3 etNUHV7aGSqmJxrcGn9nGM3132zJOECmXKH9GIxHeRTb2OjNW/VpiUC/ZivbsQ16zqQfw4RRdG+ 6CdbnHFG4/+Zouyf1i4G4CJqvVSURmYk31tfpiN2xiva8GYBcprtUyUaifyHGN7hA+KyfURpWDk EH+DfWrjQ6OypnUnUnpK9C8Jj4cHUhNHt5EIPEY8NtzNawYNTCBknbxrQVc0fn6WGA5NclJK+QM JodNgpZytCZSvaQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao The "raising min_free_kbytes" pr_info message in set_recommended_min_free_kbytes() and the "min_free_kbytes is not updated to" pr_warn in calculate_min_free_kbytes() can spam the kernel log when called repeatedly. Switch the pr_info in set_recommended_min_free_kbytes() and the pr_warn in calculate_min_free_kbytes() to their _ratelimited variants to prevent the log spam for this message. Signed-off-by: Breno Leitao --- mm/khugepaged.c | 4 ++-- mm/page_alloc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 56a41c21b44c9..d44d463ccfd3e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2671,8 +2671,8 @@ void set_recommended_min_free_kbytes(void) =20 if (recommended_min > min_free_kbytes) { if (user_min_free_kbytes >=3D 0) - pr_info("raising min_free_kbytes from %d to %lu to help transparent hug= epage allocations\n", - min_free_kbytes, recommended_min); + pr_info_ratelimited("raising min_free_kbytes from %d to %lu to help tra= nsparent hugepage allocations\n", + min_free_kbytes, recommended_min); =20 min_free_kbytes =3D recommended_min; } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2d4b6f1a554ed..c840c886807bf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6553,8 +6553,8 @@ void calculate_min_free_kbytes(void) if (new_min_free_kbytes > user_min_free_kbytes) min_free_kbytes =3D clamp(new_min_free_kbytes, 128, 262144); else - pr_warn("min_free_kbytes is not updated to %d because user defined value= %d is preferred\n", - new_min_free_kbytes, user_min_free_kbytes); + pr_warn_ratelimited("min_free_kbytes is not updated to %d because user d= efined value %d is preferred\n", + new_min_free_kbytes, user_min_free_kbytes); =20 } =20 --=20 2.47.3