From nobody Mon Apr 13 21:11:09 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 795BD3A0EAB for ; Wed, 4 Mar 2026 10:23:25 +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=1772619807; cv=none; b=mMotQDvw0fNLnjOhtJpkeO/Zajm9Xjt/KGU72SXhPfGYRyfPRjSovgZarD5+tXWPvLVz75Dfsfk0+DT9762mqBl6Yr0S+WRwy4IMVdkCHd5y7RacRO+eV9eEBt/Dw65zPbLEc505IMFTkqSeQng+CcrzudQ+tKROWq+nm6fbK4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772619807; c=relaxed/simple; bh=KJ10dV4a/iqSKDAjRDFawsGHr65Ti4HQ6vbLNo+A1ow=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kAVnXM+Ggp/naRaMJq473Rr+J7DXfF9or0QgvEvP2Qmhc6i7nz6Gg9njo8pB8prjAp5PrL9ApL8a62fT3VL87FNru7RFCKxmihj6+KGzh62EGId89TDUcxkPoIMEHa0TK2y2HasB+UhtjGCp+hIB+eWWg3q2MVgzeyubvs5ydrw= 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=F7wDwb0N; 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="F7wDwb0N" 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=mz14ef9NiersuDV3XBNcZS69uEpO5WM2VO5bpvtQX0I=; b=F7wDwb0N79HiBv+8XaGsvNsnIa /HRDZswde0xtl4S4JgMYtvFYPqaIAM5sg25KPuqdJuckO2ZGOTjXgFi7cXd7H15wvMuqmobL2YM5K m6UjiKuLyOBrO2kW8ZVL4lbnpERHjvIp8WB1xpYtCMZDPsv/CB2GxGm9SMh1PKCC+ozd/49By84OG c5fbCk3DfcUiVAbaibxj/MQ0PC68s/NJvbXURtBOQJO8sYW/kvasnHzZzYrKDQHbd+W7qVqAcvPUu eUVlXbxFbbYBBsAYGrWX0ps4A223I6ReGObGKqkkq2W4EtYKFcALrErS4lJto6qS5JQtGmdGqGxGF oLufxumg==; 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 1vxjNq-00Ft4F-HS; Wed, 04 Mar 2026 10:23:14 +0000 From: Breno Leitao Date: Wed, 04 Mar 2026 02:22:33 -0800 Subject: [PATCH 1/2] mm: thp: avoid calling start_stop_khugepaged() in anon_enabled_store() 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: <20260304-thp_logs-v1-1-59038218a253@debian.org> References: <20260304-thp_logs-v1-0-59038218a253@debian.org> In-Reply-To: <20260304-thp_logs-v1-0-59038218a253@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 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-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=3364; i=leitao@debian.org; h=from:subject:message-id; bh=KJ10dV4a/iqSKDAjRDFawsGHr65Ti4HQ6vbLNo+A1ow=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpqAgHqsA8llrYYRvJmrXyyG81r3MDvEyYXC0kv jtvBgHnXKSJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaagIBwAKCRA1o5Of/Hh3 bfJWEACsT2Lwnd6evuyylGB9MhI0dlfMq/K58pIkwRcQSxpvHJDAFs4poR3Rw7fqCyjveDBJtoP XR3q+w4rRL+E/E8bPo06ArayKgzNMK+JogVvHEBI6nPEqd4YS25iUe6GtJnrCJzhMDm5+xxf4s0 GynqLW9RQl0KqubaE62xIsUxvykH9Y7PQBn1FsLLtPD/KnDvEZrixixIrDAZh/CmjJnUNh+xLZB Ws+01IqaH3ri9s3d21DCYNVyYzW/39Kj+kd6NXDT6HQIbXgPIKQxkqIew+qHg6V29uQdZh4d9sn pC6UT1qzuGr412z+JBayvZs6ltoPJp8nrpA/l19vrJJz/gLEcR7Xxpf2TzQxck1L2GVT6CPsdVg /LHmrS5B8rrE2hBCqgtHCOSVHkabvJCckl3c+PxUoUuySxuPA520O4zgMqJZQEyIGV4+ZCu6Iwj jFV7RLCdyZOXPWkq/WBbi2Z3nPT4iVPeiwmTo6iYvDWkEi9lrkhE5Km1cVXpUMit5D+GYrkn4Re FAiLH2Sd2rmW9Ks8e7/hD527O6jLiyEJjTPeCH6tLVWemTTdmllxDwpyhV09jyyrmyaIQ/p7a+f TlTVTnFwbqQUnWx7khvX/HtIh3zdcpOjbZ+1MozHlRwWYXo2XB67fYTg1dhghJLv+uCwKIrFyjN xGgSTKIol6Z6sfg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Writing "never" (or any other value) multiple times to /sys/kernel/mm/transparent_hugepage/hugepages-*/enabled calls start_stop_khugepaged() each time, even when nothing actually changed. This causes set_recommended_min_free_kbytes() to run unconditionally, which is unnecessary and floods the printk buffer with "raising min_free_kbytes" messages. Example: # for i in $(seq 100); do # echo never > /sys/kernel/mm/transparent_hugepage/enabled # done # dmesg | grep "min_free_kbytes is not updated" | wc -l 100 Use test_and_set_bit()/test_and_clear_bit() instead of the plain variants to detect whether any bit actually flipped, and skip the start_stop_khugepaged() call entirely when the configuration is unchanged. With this patch, redoing the same operation becomes a no-op. Signed-off-by: Breno Leitao --- mm/huge_memory.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8e2746ea74adf..9abfb115e9329 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -520,36 +520,37 @@ static ssize_t anon_enabled_store(struct kobject *kob= j, const char *buf, size_t count) { int order =3D to_thpsize(kobj)->order; + bool changed =3D false; ssize_t ret =3D count; =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); + changed =3D test_and_clear_bit(order, &huge_anon_orders_inherit); + changed |=3D test_and_clear_bit(order, &huge_anon_orders_madvise); + changed |=3D !test_and_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); + changed =3D test_and_clear_bit(order, &huge_anon_orders_always); + changed |=3D test_and_clear_bit(order, &huge_anon_orders_madvise); + changed |=3D !test_and_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); + changed =3D test_and_clear_bit(order, &huge_anon_orders_always); + changed |=3D test_and_clear_bit(order, &huge_anon_orders_inherit); + changed |=3D !test_and_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); + changed =3D test_and_clear_bit(order, &huge_anon_orders_always); + changed |=3D test_and_clear_bit(order, &huge_anon_orders_inherit); + changed |=3D test_and_clear_bit(order, &huge_anon_orders_madvise); spin_unlock(&huge_anon_orders_lock); } else ret =3D -EINVAL; =20 - if (ret > 0) { + if (ret > 0 && changed) { int err; =20 err =3D start_stop_khugepaged(); --=20 2.47.3 From nobody Mon Apr 13 21:11:09 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 586A23A2559 for ; Wed, 4 Mar 2026 10:23:28 +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=1772619809; cv=none; b=O9ufNwuKp3Q67tRcozixCMMQa33Ubd6kqbcp6CT/E63SR0xcgyyUmOvIF8jy2HBgMh1qKwygNs1pIkdkXJIBxyhIQK+WjTRxDs3B9gmudCHBEI253lpKIScKVuuCQF/ihbXAApqU1cuL8oOdAt5TbzYvlEeuU+bJzCXinEjaLMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772619809; c=relaxed/simple; bh=DYGJrnPPlP2gd8MfbcdjO+tkpdphLuDPYa9VQ0u4QcM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TfXUHyBvkskBIMrZ62kNoDqcPOqLK5TitU97vm2Yej7Xob9E008BqX2PsW19i16G3oHL6SvxltPQAgpN5UCoMYpoVBfRpEahS8JHHNb+/fkM1fbV/D5JzDR31DibpM4MFpCTLKK+tptj0aoUB5U5Uullt6kvg/aNVJifq2mdvXU= 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=OT+rf5ED; 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="OT+rf5ED" 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=62A7LeZ9IpCSBCgrNHLXMjzMVlSh0j3tAfN1CDmHNwU=; b=OT+rf5EDn/BQXidGHrc0PmRbCD 2HwOMfFsiuAMNqxNx+bfYsJcpenvNKh0//ey0EunlLAuswzUCHWFpPpC+WA4JBKosBmW4orTNb7mD 8ATDyZC1Q96BKDEEsPDayfF39P1CemzWEhZOtR+2ZRCTAMnpW2SzN3+25g6XABogxIfUPF6kDKJNd WifGiCLgDllDGfpwHunvz9wE53AOhHS5WfrYqTicnmkjyktigxQvaU3wl7dS9lUQYew51oajFoN0C RK9wzPtwoZerNmnbOKxrr8CWCoM2IuH4a0pwZtTz63dHlMJBCWcfRXKXC8Ap89pdmqIZxyoiXnFU+ PkoML/uA==; 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 1vxjNv-00Ft4K-VI; Wed, 04 Mar 2026 10:23:20 +0000 From: Breno Leitao Date: Wed, 04 Mar 2026 02:22:34 -0800 Subject: [PATCH 2/2] mm: thp: avoid calling start_stop_khugepaged() in enabled_store() 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: <20260304-thp_logs-v1-2-59038218a253@debian.org> References: <20260304-thp_logs-v1-0-59038218a253@debian.org> In-Reply-To: <20260304-thp_logs-v1-0-59038218a253@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 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-f4305 X-Developer-Signature: v=1; a=openpgp-sha256; l=2206; i=leitao@debian.org; h=from:subject:message-id; bh=DYGJrnPPlP2gd8MfbcdjO+tkpdphLuDPYa9VQ0u4QcM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpqAgHXd3XgvmFZqVfvSfOACS/eEUJxgb7CLYR2 N4lClDYjAOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaagIBwAKCRA1o5Of/Hh3 bRbgD/4xe2mql9zlE3u+QPlwFTvwUhxUcVOHRkiTki6BrK1R2IPEBYgcPpzUMOny71xKwQht31C Jbyvch9ttzyssxsLF9+l/6lprsxFDu8WM8isJk11KhXoxBVNEDhB59zSTwdSecZP8s5hkwzMWFy A9fFRa4wYw+UCJAGQ3uwKCY3964CwnxM1kmBi584uwnxCv0HO8ERbBXUXwtGG5LRQHRT3C89ekJ O6SQL8Be/AbujIiuWkgYC2+t0jr9rKb6FbG15+paKfbMWkizUYdJTzv5PrDikolb7H+kqLpzgIp cEG3FSQWqt18S9/2oeHSG7AnP4BxZn5V0lE8d4ElJVIlOd8fMq5XnPxVHzCjX5R9oGJXejVqA+1 bQT4tmJGU0/V1t7BXb+A/x06ZN5GbNQ82iSkzxBI8jPywvOhj3v1/21afnTLoRo/TnahNYv6ONk MlTbpA75G4GJdB7soF5c/sRLletU9fch4TOLrdBf9GuIwfxZnfhkOIt7eXG5vFYtSbnzt3vIRCJ UrPqgmTM2FyAU1RibHViK50b0BWVhpYO98xPwlpVUjTwQ/+mXR4Uq/pANxhVpehmyTcyCFocq9v crBagC7gzlJGOaTwonlZBMxNMw/iUtFuc/Y0ikvtOgVmtsYUJhpkPG+oID+KvFL9DS0phU4+hbs XkBQnefaXXpkIFQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Avoid calling start_stop_khugepaged() at the top-level enabled_store() for /sys/kernel/mm/transparent_hugepage/enabled. Use test_and_set_bit() and test_and_clear_bit() to detect whether the configuration actually changed before calling start_stop_khugepaged(). This avoid calling start_stop_khugepaged() unnecessary. Signed-off-by: Breno Leitao --- mm/huge_memory.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9abfb115e9329..b6ed44b6e8c02 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -320,21 +320,28 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { + bool changed =3D false; ssize_t ret =3D count; =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); + changed =3D test_and_clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + &transparent_hugepage_flags); + changed |=3D !test_and_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); + changed =3D test_and_clear_bit(TRANSPARENT_HUGEPAGE_FLAG, + &transparent_hugepage_flags); + changed |=3D !test_and_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); + changed =3D test_and_clear_bit(TRANSPARENT_HUGEPAGE_FLAG, + &transparent_hugepage_flags); + changed |=3D test_and_clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + &transparent_hugepage_flags); } else ret =3D -EINVAL; =20 - if (ret > 0) { + if (ret > 0 && changed) { int err =3D start_stop_khugepaged(); if (err) ret =3D err; --=20 2.47.3