From nobody Thu Apr 9 11:17:56 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 8C51C395DAE for ; Mon, 9 Mar 2026 11:08:12 +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=1773054493; cv=none; b=A9fzDI4REr39E5Sy3RH6eq6R269w9/g+qlAsSvQTbMqLGWYvOPalR7EkRNYiyHcn6HLqXuYbdIemD0zqFf6cHhycpyiLq+9SNJ82cMMQnCI/QY3I5TDDrjoTT6heIvjvGl+pAU16M92Nm6alEfCXJYXUPDLSQz8gxldYhJZUsAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773054493; c=relaxed/simple; bh=nlToZmaB1n6dDw+eMzdYWKgFtlcgYp+PAKEi0NGirZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sblObOHldY6PnIgl1zcGCvSyo1ke/9n5hklM+6AANXOzLyHGQ7UaSDTQ4W9qDlvLudceDOK2QJElHFYWFYKv3u/dec8zJLMDbXqp3oDGX/eg2Ds7iqDVhNRl9Ysdj3fNMUVaX2pgJJ7NUp5OnSr9hCOPLfEtBrPQSs+zqnSrrRA= 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=lZMx0HT0; 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="lZMx0HT0" 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=lZMx0HT0Q9ge1TmDMeF6Btdmqq GrfpAcpyPbQMCedySls6W1fihtN0AIv2+Fc4Bj9aG3KS9xNPrLPiibuF3KfQi+x2clCOo7Zrs6RVX scbyNP/vNzydyHoJATfCxkgMOnE70nXl1ebjNEdpTwuLfzHVRgqDX9Pe+Q2WeHVdMGRBj43ylX++M 3yw/0gY2MTZWV2u6fsOC0z9OJ+rS2Cc8fZotsoLqmqWX4wNWO7EqUyDnsQsSllo6w+K1MDz+Wc2II moXRu5PQp28dG9P5RA32MlEBkFKN77mYhtnrPu4JZx9IXruQC++CKfVOrxKrU9P1kyHgbTUsB6aDq Lra49Fjw==; 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 1vzYSq-002AwP-T8; Mon, 09 Mar 2026 11:07:57 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 04:07:30 -0700 Subject: [PATCH v4 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: <20260309-thp_logs-v4-1-926b9840083e@debian.org> References: <20260309-thp_logs-v4-0-926b9840083e@debian.org> In-Reply-To: <20260309-thp_logs-v4-0-926b9840083e@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/8eHdtAcsmYgBprqn+JFWMLGaISD8obUOaYQc/aBnqki6WkYp3Z 73Gt940yJuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa6p/gAKCRA1o5Of/Hh3 bQHoD/sElmky1V9utSUmBeA264BBtdY9tgT9j0rrkCA8R7RVXS3kjEmR3KPUj4lURA9FO3rxkMI KSGSWdJ6YtkEy3xkhIznu9vGkGr0ZbNLNYA1cb1YWTU0ygEFijHOp6+OD0e9OzXO22phZG4wTkX /3SeXP3mF0dkwCfoOF/CxUaJBSydOxL9jxqvA/V8Q2C6DlOjiYiwcLtJG6MlHzFbEDRxGI7TIOg 1Emq5TQPeWj1Z8aThJkZ5LPBwzHQR5qaqb80v9EfaY1PryzFFf65xqFuKcQ+eyUV4kg6Q4kK60l ip+n7Mgw85UJDic+S9aPJRmZf9z0AOVwTTXs4kRPGQOOFBiocr4S6qQvMna2NKPNU0Uj5Ar15yA Q5apSWZ0/Xy5tLyu2+yI4Y4Lf28UzkS444rBTscC9RTHHOqYA6n9S4i5yuWS/C9TVf0msE4mUTn zVm8B+fveNNunLNQr9y9fU8D00mr3PWM88nvhZjLKHzfscx4cYl+50uR6lD8fnyOJiGw7YQMdky v9lyu2jEM8JxKR4sX1GOLSZNuq+Jk+swNb0O1Px5SVWcweHxRiER1Mj8GpWTrArqmrhii9mNVYF A/J49a4oiKeDydskHR9Y068Q6JsWauT7kEtNwEG1jSSVL6m5usEHwpu21da5nHKsjFanhRZjBfA P3Flr93QMxuhh6A== 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) Acked-by: David Hildenbrand (Arm) --- 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 11:17:56 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 5D1DA396B8A for ; Mon, 9 Mar 2026 11:08:16 +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=1773054497; cv=none; b=OABZHRONI8Mu5h96VsFkHMlAP2/5DaDz8juiMsbes+vVtX53/1u8+y17l8SjfiiLaT0ERuDY1e17ZbPbFULhQO3HKhnyf8AE/xiWIQTFtsJZ7svEXOC4kb7uBrxShSbFKW3XTLChR5JoHsN9j7HassaxW0maRGfDD+mSiPZAEXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773054497; c=relaxed/simple; bh=0o3mclXhx2QxfkKcINCvef62gv9C6nChRQktfQw550o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cfcf1n265l0x5Ym/2dXEQDcBR6vxbwV4rWM35BI6KoieIOmk60RdLbiBqWRwrUggCegu3/Lj+b2FUk8YiRex8t2cua8Ma2R9n+0d1YraDmSZbXOMOB0qBu6ZOVeX/D5V7rLtyHt0S/VcmuwKtntrgep4RACNlYEeDzXH/rlT+bE= 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=aJzk43P5; 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="aJzk43P5" 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=vDF64xxZzJ7cjs3+cnvijW6JKtdwRCzUCIJnt/1dnjg=; b=aJzk43P5l/5qDBrMnOPgN+KrlX AQBPF2JgaxiMCcO3LXDwmIXQWXLfGBdxeOIiQ1ZZvd/DmkXKZKg096kmoDB8HlBzwdnViag37651c cF7wY4nfX66lPUKnHytO3Qn/mu0fWkMxy4ZAi3xKLVqrvvi7OW99YObl8ACPV6qhWHYxcL5PB1qYb QW6LBwvhbag0pqw5WplP9emxj1krIjNhIb1fVkb38paf/iuFkLMYl4sp/2YgQukIOkw+9fEQfq5pj LHmf2UuIoEijkYDFdOisUKq1cF9fXQmUbr9PKzu8KfAvVX22CGMIFom3NXIaXfIb+0CBwU4jbilrR /pOKJnPQ==; 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 1vzYSw-002AwY-Kj; Mon, 09 Mar 2026 11:08:03 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 04:07:31 -0700 Subject: [PATCH v4 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: <20260309-thp_logs-v4-2-926b9840083e@debian.org> References: <20260309-thp_logs-v4-0-926b9840083e@debian.org> In-Reply-To: <20260309-thp_logs-v4-0-926b9840083e@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=4428; i=leitao@debian.org; h=from:subject:message-id; bh=0o3mclXhx2QxfkKcINCvef62gv9C6nChRQktfQw550o=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprqn+AeoIXBGWkxLKEcTZncPU7aYGAQAdEASX2 BOq9g76TpuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa6p/gAKCRA1o5Of/Hh3 bR9iEACr0Gx5HEv/nW2mooEN34Yye3riL+2G1zLa7DFoqSg3g0ghDMjnXKNf/jm6074lXwEqFp1 mSFCL4U17ZCIyasG73+lRhzDl8RvYlOM9f50Wvt0o/9zkrjvxGAsblskzElCdsSRokqsgGCpqJ1 R2lR+CyErBfvMz0A05PNRxkjjA+DiwulGVh5SJs0eXFJcGfqTpDGHuboRHq8qMpBEFiCoSCVIoQ WtdO8GdzMfZaKPD6it2vV6BLt6pCaWGO8bbonSGekSevOqTpXu8TGJ68jGcy6F5RdhgsuJdlavj Q7L6BZDNDQyRRCmVuD0CS1fEu4HluJufR/w0Wv4dA40v9e+YYgUnhY7+6zcOI1D1T+d7tPWpLQ+ 4QztZzAAoNjek1IDON//L4DMVHDfyRKA453v1NnRIFlBt5rvlBff365DWbhSuL41kFh46v9lnZH A03UOPjHUenBllemwNnde0kR0aTsuKXkRWJyoXvT88JinUkuIEfG8qhlpFSw05wOxgWwIo5PmlL Ugcy/Rj8HkwBteRwLIipr9tGoEWfD5Oo3UBTJbxePWEOwy8Ef/sSCuSr4XQzMk33Am2ixKwUCae AF5VYC5n6YIsWUyem4CSaD3ZuYSC7/LWemzEcx7wDSNzfLjvAgGnS/RhxvWmDbRmoEjG6nVefz4 skxojNfuFFwZhUQ== 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..2d5b05a416dab 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 =3D 0, + ANON_ENABLED_MADVISE =3D 1, + ANON_ENABLED_INHERIT =3D 2, + ANON_ENABLED_NEVER =3D 3, +}; + +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, + }; + enum anon_enabled_mode m; + bool changed =3D false; + + spin_lock(&huge_anon_orders_lock); + for (m =3D 0; m < ARRAY_SIZE(orders); m++) { + if (m =3D=3D mode) + changed |=3D !test_and_set_bit(order, orders[m]); + else + changed |=3D test_and_clear_bit(order, orders[m]); + } + 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 11:17:56 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 EA923395DAE for ; Mon, 9 Mar 2026 11:08:21 +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=1773054503; cv=none; b=eW5bJOlXVWtibmVfm7GzEuiKraqqhqK10JHT97SyXEKHmoRUdezMVEBxL0lV+nv09WZ+GCMY+M5NLUzXUeqns/SEVO8wJQbWdj5tmtfOU4A92Pw5tUFeL7b6vDB3QJVIWyLwkj9YQQzq8KiK+wRolIH1lmuCmovFJiDaBkFB614= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773054503; c=relaxed/simple; bh=Rps73ws/DtMzsKWxDZkfpvyl2AU0CyVMps0aEftLyqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t6iJ1+avRrvfO6a/GP5zzuRGvrOm2dNINv3QMgS8JIPCoWyFyCWM1BeT1S0+gzPDnWNdio5NtFBxxQSVT1DwI9/KHJf3cewkW72nS8Z3yEDxL2HVeRd808eMTihuu6UAuHhZlYgbHlXgk4V83LWCkVXaLomfp/7qQr5nTivdJQA= 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=dzrNIntp; 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="dzrNIntp" 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=N4HGQ0yYz7DIk6VexLHFU9Nzgo9+u3GkTdEP1uFtaE0=; b=dzrNIntpVxT6cyfGOLdS/AuFBn KoPTQiOlGIlz4i0FfjWTL1rfst+Cfpbs8MX8Gs0OPGcvUivBzWYnV6rwV5V9wmRKbNdjlIz0UlTE+ eXRAZo5/MqR1jBHSNZY8WEt4Hbd+hBFgMqB9FinSel9Q8+5w+JEKoX8l548D2mD8dEeFao86z6wvd fSno6VKnc+Liem6MWw45zcRapK4xezH4G//BySGJSiFcJ8RR+SfMwkWTAQt7k4ZREOw/MRsL7GkOH Oj/XtT4lulUVLKrfRiGBHoXrrL8oX2vTJLKFgliuBOifPPX4ruhHA+OsYyvKYhD2kI5s5DX2rwQAe 2hqhjrPg==; 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 1vzYT2-002Awp-P8; Mon, 09 Mar 2026 11:08:09 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 04:07:32 -0700 Subject: [PATCH v4 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: <20260309-thp_logs-v4-3-926b9840083e@debian.org> References: <20260309-thp_logs-v4-0-926b9840083e@debian.org> In-Reply-To: <20260309-thp_logs-v4-0-926b9840083e@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=3458; i=leitao@debian.org; h=from:subject:message-id; bh=Rps73ws/DtMzsKWxDZkfpvyl2AU0CyVMps0aEftLyqQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprqn/YQ4/idw1iXzDtS07ZJOflm8xgjZE7IOdp gm18zxehfaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa6p/wAKCRA1o5Of/Hh3 bUKmEACusVurwYRevmZNNAslBZC0bm0mW0N9BmG03cGa4uzjS6kmskhapX3Y+NlLXVlbPel5yr3 pa+OBl2fHWgenUWzN3oKRpyKPJeGAlfiiWe8r8LckwJgSRYzt+o5iebL0M5GD/Hk1JQEi0PsAny 7gP8LBLlvJjKCFN6+VvL1HCHuNHSgXaDA4fOmhGqQPZhXOL2DIPawMqlQfnFqTBO5/5AbXFdFpB Wyuj0goQDWhZ7FBqo3sFTN9YuBqqueNsFCsnNkulvA98XdbL1Ze4waumD5Rx2glA3rj1SpMCTch E6yQWbdDOp0bj9XGmmvsaOddvh2JvH5n7SNOUfg/IyFJA8dg37NFkWLfHGjvEHBlurGfWLBQx37 aiKt/BlxFsJEHHFaCzn6e/xZtNDSL/8+mpjmCvseB6KxRq7soR4cokFy8PUzsSDPPUwUKdJPQSs UxruOJJdP0NdeYJZPJW1CcALD+PUjC7Zmd5MvBxqizC/03n4UJqB5SDnV30sA+4uMG2lf5UXz5z jxHBCvqhA22Yb8KkyJJu18UXwCe77XUzt4YoW0lKh8CBxud9F0z3nSdTk8H1kqP+sRI1F5y08RJ vzQ/mbyyTa+DFEUrxuqIUW5fgBitzezIWKr++pQgWWr6n5lsHZrPk5egP+W5slxNu7g07Yrxy52 +KEm4oWBwGgjbbQ== 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 2d5b05a416dab..be42a28da31d8 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 =3D 0, + GLOBAL_ENABLED_MADVISE =3D 1, + GLOBAL_ENABLED_NEVER =3D 2, +}; + +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, + }; + enum global_enabled_mode m; + bool changed =3D false; + + for (m =3D 0; m < ARRAY_SIZE(thp_flags); m++) { + if (m =3D=3D mode) + changed |=3D !test_and_set_bit(thp_flags[m], + &transparent_hugepage_flags); + else + changed |=3D test_and_clear_bit(thp_flags[m], + &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 11:17:56 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 47F2339901B for ; Mon, 9 Mar 2026 11:08:33 +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=1773054514; cv=none; b=VvSYqLWd8n8w0L/mV6MqZWY6a5AprjTKjAr5CBU3ja12M+p/Jl0s7xX56mQGi5ehyvCvNKQtGpa0kUxqebt6UsI9aAGLLxIOBgbLkkKcCbl1TFo6plkRSBtI4LrCaWU0Lz6nA7oumWByK3iSfZMYX3SraKQjNCz5CnQ1z0kC+/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773054514; c=relaxed/simple; bh=gxJOAYW1B4QBpNiriL+Xya3ATpxserwPiuGqRjqavaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TnQoPhqFCdI3ZmeDHWlGKyLN/E5lEmvX3cQEpOQFwyHY1Z2w3QKUglvvFPZrSF6GjyEprZp2YAwmBexGZsbnSecPxF0vAbz4SsKwcphTNHESEfp9j3wcwg/iI/mVJ/vDixM2NAbJxaYyTElHPOnssibEmlDKS1czaNL23xjfQ/Y= 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=W0AP1pLS; 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="W0AP1pLS" 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=W0AP1pLSww6cUu+rrjh4ETPJwA 7fmvpRIRwDnYQ3jD/oVEQjEIFsC0EZlkImak0GRbIiJlmpmBVR3EZ1AGgoLq/TOsMtNfLtz6fKtGy QNNcuwP8HP6taKLkawDmsztAF1QzJ0jY2Fl0jqy5NNKulgPxt9yhFYu2V9Jd6ow+DTfyl3vqdYW7I tgGs37g2JwHx1zSJ/BZuTO5SOXZr7LKsbqY2CLnyp93/0GGdW4zM8FnBog0wyWrhcpfX0fjF/d44/ HJqZjxGqOijUNpZKDvBRfPQLQectFx4V2TTDJPMuy4nqg4ncmYsOkEBGRD0+adFIzbHciOJ9HZ9lg 1meto49w==; 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 1vzYT8-002AxC-8p; Mon, 09 Mar 2026 11:08:14 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 04:07:33 -0700 Subject: [PATCH v4 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: <20260309-thp_logs-v4-4-926b9840083e@debian.org> References: <20260309-thp_logs-v4-0-926b9840083e@debian.org> In-Reply-To: <20260309-thp_logs-v4-0-926b9840083e@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/8eHdtAcsmYgBprqn/cxp7hkynlnePb5KD/sJsCZvmL33WAN9yK uvcpPlFbEaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa6p/wAKCRA1o5Of/Hh3 bdxkD/9G1F8AwU1+LXl8P7LYZ+zg2h0RX17IxPHAYVheiq2a7IAMka1Xc1ncXPdpiXwXNLPovRv zHXUst0HCXECjf9tizl0PrN6N4If7gf7ylD2nQp0IIHrsgAOn8UDooarDGynEKYIB3ighYgtblA nJNXRDbF3YVyDubRuGCc+BTp22R+Jt2zAC7MY4KdeO/H8F6qZeCAIxjNvwTPYe3ViBMlmmist5I KCVEF5BTXGYW/1ouPDGmKHYgxd0BF7UG6IJ+EFOCCZ6fGqMdApOLNmOvzzlBx1yi3jSiKHpEG4t xJD8Vp4UMignNto/EFkgBWXHzHLhIEOnEg17W10GPm0OROlm9G2QR8WjlKuPpLfMhnZg3YviiVs l63queiiAvrMmS8PQDLLM3LkuiPb56CfRJAOP5ubnCuZ171y1oILAZLiF9KavKmlHi6dGYRI1UV ahA4OUdVtlbmIUjD4dpZ9TPC+ZggirIRF45Th546T0THBGRRRj2R8S+l4sFEjkXmwiIO1aYEXli 5jldlW+cHWAVOlNG8o5mT2NWLjam7O1b9YBJKPSEpCSFlz4Z1ii1z+XxOn03cOqANyAmyTfZgi7 wYVdgTylK/6zN1pLykNNEeNQ4I0gUpQZoKw0dEYHezMcTAwOJKmKfV75OdX2Z39OdV/aiRP5VP9 1J6bsGKQR2q+ZhQ== 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 Acked-by: David Hildenbrand (Arm) Reviewed-by: Baolin Wang Reviewed-by: Lorenzo Stoakes (Oracle) --- 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