From nobody Mon Feb 9 17:23:14 2026 Received: from sg-1-104.ptr.blmpb.com (sg-1-104.ptr.blmpb.com [118.26.132.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5354431619A for ; Wed, 7 Jan 2026 11:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.104 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767785664; cv=none; b=M8tTHcyWd8WVV0irvSPKNIhTonoXpAH8OOB5rOl9blvyUSXxhGc89WTiJKTBy1RQs3jlePZ9+hBKTWFRzDrM5ZVEqq/nuilvZtV9I6Ft4p/KhEnaF8HumUZeqUQwSVoYxcNB8/r6T5GhNQrdPxCChqbUBa9TKuhOoa7cDCXwgeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767785664; c=relaxed/simple; bh=40yvhytXGaLDqg3XSFneNPh9JRhq1EhG2iHDd344www=; h=Cc:Date:Mime-Version:To:Message-Id:Content-Type:From:Subject: In-Reply-To:References; b=B7ZLhsm6rpxWGOPEiFD9y7dh59B7zNWxr+qbt0Ho+hKRCRlnHeC1EAkakttMqoR5pckn4akShOeBxF6u/u8Qdz8fOCNAW5TZf7wjAziHzbggDszm/0Y/HExVQCfhRBVNxuv12fwh0CXK644lNTFlSK1HGuJ9SZIAWAUnwJzjCm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=dSNIvTeq; arc=none smtp.client-ip=118.26.132.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="dSNIvTeq" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1767785656; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=pQGsuo+iA51rKHReFsoIiKz498AYBUnjfg0gVNCR4mw=; b=dSNIvTeqojGMFDN8IC8DMsdhS9EEmH2X0jq3KlLwWu6X6qMZZ5Sd4aRqcwxPZrjulQDdSs DaHfm2fMpvJahZhqz2+xtXHwNkO+7LbrtKEtgNulKDIiFJtnjw6/pa+PsC0OJKR0xSuIiy upumWCdoFpLJky9kx1TskoDENnpHIQ9sLyNynyBvqXF8lQcmK7a4afuVnjiGDHsEX8IXsi RAETEey2pViXlddvwMKUL/30oQD0sP4xss0SygzEs7HMRhSsXUIJSlStbBcY9q6vHR2lUv ZYhC1PU90pPgd092DDUNaqKPfdse44n2QfEx7whshrVzq0dmsrbIVFouX4vOng== Cc: , , Date: Wed, 7 Jan 2026 19:31:30 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2 X-Original-From: Li Zhe To: , , , , Message-Id: <20260107113130.37231-9-lizhe.67@bytedance.com> X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable From: "Li Zhe" Subject: [PATCH v2 8/8] mm/hugetlb: limit event generation frequency of function do_zero_free_notify() In-Reply-To: <20260107113130.37231-1-lizhe.67@bytedance.com> References: <20260107113130.37231-1-lizhe.67@bytedance.com> Content-Type: text/plain; charset="utf-8" Throttling notifications reduces the number of scheduling notify_work making the mechanism far more efficient when huge numbers of huge folios are freed in rapid succession. Signed-off-by: Li Zhe --- mm/hugetlb_sysfs.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb_sysfs.c b/mm/hugetlb_sysfs.c index 77e7214a380e..1e3a6983457a 100644 --- a/mm/hugetlb_sysfs.c +++ b/mm/hugetlb_sysfs.c @@ -341,6 +341,8 @@ static bool hugetlb_sysfs_initialized __ro_after_init; struct node_hstate_item { struct kobject *hstate_kobj; struct work_struct notify_work; + unsigned long notified_at; + spinlock_t notify_lock; }; =20 /* @@ -364,11 +366,30 @@ static void pre_zero_notify_fun(struct work_struct *w= ork) sysfs_notify(item->hstate_kobj, NULL, "zeroable_hugepages"); } =20 +static void __do_zero_free_notify(struct node_hstate_item *item) +{ + unsigned long last; + unsigned long next; + +#define PRE_ZERO_NOTIFY_MIN_INTV DIV_ROUND_UP(HZ, 100) + spin_lock(&item->notify_lock); + last =3D item->notified_at; + next =3D last + PRE_ZERO_NOTIFY_MIN_INTV; + if (time_in_range(jiffies, last, next)) { + spin_unlock(&item->notify_lock); + return; + } + item->notified_at =3D jiffies; + spin_unlock(&item->notify_lock); + + schedule_work(&item->notify_work); +} + void do_zero_free_notify(struct hstate *h, int nid) { struct node_hstate *nhs =3D &node_hstates[nid]; =20 - schedule_work(&nhs->items[hstate_index(h)].notify_work); + __do_zero_free_notify(&nhs->items[hstate_index(h)]); } =20 static ssize_t zeroable_hugepages_show(struct kobject *kobj, @@ -597,6 +618,8 @@ void hugetlb_register_node(struct node *node) break; } INIT_WORK(&item->notify_work, pre_zero_notify_fun); + item->notified_at =3D jiffies; + spin_lock_init(&item->notify_lock); } } =20 --=20 2.20.1