From nobody Fri Apr 17 10:46:45 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