From mboxrd@z Thu Jan 1 00:00:00 1970 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 279CA3090F7 for ; Thu, 25 Dec 2025 08:23:35 +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=1766651018; cv=none; b=jowXn3+WSarEWAu9eIYcyb23RCbq/C/F/54TQEtYn9+akWYP9efjWwFDDrO5wPaNPW8f2l8u5Ps9Q6YlF9f4K8SEVgCPexsQPKZzf2MAD7sB0lyJOgqkxpiUOVX2BdPs6EEFzCC1xz+7BXsqjH0hJ6+g+nCfd6BPX8Sf6EcaLUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766651018; c=relaxed/simple; bh=EGXOpVsqJWGXssdX7k78B1WlQhFxlkd9QZgLNO7xOaU=; h=To:From:Subject:Message-Id:Cc:Date:Mime-Version:Content-Type; b=RWPID7T8c+DWKiF3ySogbCcfofFd34oKXEunHGE+ZhNsMsZNDZ5nFhNEAvAI3wSdIXly4EWIkoRm9Bk3SAqUgTCm4nMkhR1y6c3eulERSjujlaSKrzhqjiqedrn38SfGv/dlJO6Dk75P2t8bZxQfpoDvDd0nSXvqbMjk9xDpq9Y= 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=Kn1MMYcw; 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="Kn1MMYcw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1766650895; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=yiNawinEFDT7RNWcuSmOZol6+g8othUx6jWLOxsN1Rw=; b=Kn1MMYcwsf0iDzNFiZcE6plkN5gixFf1IaUPo6hP7whLh2O/DCwX40toUK2EGjArdIQcK+ 9owlX7Gn92c6+NlHiatqNskH0lHK8eBdFpRro53eZFO5pdtpRNfzg3A0vj9Q0CXWhE4+PO FbkvPXZN+YK7yMr9B6AMBUs+ok1ft0JKl2/4FnsipohR/NHEO76YbmD90mYOiTqVq78ojq 7YuK0U7wOgNDTI5vX6aCftnNqEUZYaC8mC5iaRBOg/3+YlQNl2gfHxO6QfG5GoZ1MDmB3U mLJgYzG3ABY/dlgUnBSZ+AZpS7668DOFlTQvuA8xW7BEzbJLse5QLzTbcsC/zA== To: , , , , X-Original-From: lizhe.67@bytedance.com From: =?utf-8?q?=E6=9D=8E=E5=96=86?= Subject: [PATCH 0/8] Introduce a huge-page pre-zeroing mechanism Message-Id: <20251225082059.1632-1-lizhe.67@bytedance.com> Cc: , , Date: Thu, 25 Dec 2025 16:20:51 +0800 X-Mailer: git-send-email 2.45.2 X-Lms-Return-Path: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 From: Li Zhe This patchset is based on this commit[1]("mm/hugetlb: optionally pre-zero hugetlb pages"). Fresh hugetlb pages are zeroed out when they are faulted in, just like with all other page types. This can take up a good amount of time for larger page sizes (e.g. around 40 milliseconds for a 1G page on a recent AMD-based system). This normally isn't a problem, since hugetlb pages are typically mapped by the application for a long time, and the initial delay when touching them isn't much of an issue. However, there are some use cases where a large number of hugetlb pages are touched when an application (such as a VM backed by these pages) starts. For 256 1G pages and 40ms per page, this would take 10 seconds, a noticeable delay. To accelerate the above scenario, this patchset exports a per-node, read-write zeroable_hugepages interface for every hugepage size. This interface reports how many hugepages on that node can currently be pre-zeroed and allows user space to request that any integer number in the range [0, max] be zeroed in a single operation. This mechanism offers the following advantages: (1) User space gains full control over when zeroing is triggered, enabling it to minimize the impact on both CPU and cache utilization. (2) Applications can spawn as many zeroing processes as they need, enabling concurrent background zeroing. (3) By binding the process to specific CPUs, users can confine zeroing threads to cores that do not run latency-critical tasks, eliminating interference. (4) A zeroing process can be interrupted at any time through standard signal mechanisms, allowing immediate cancellation. (5) The CPU consumption incurred by zeroing can be throttled and contained with cgroups, ensuring that the cost is not borne system-wide. On an AMD Milan platform, each 1 GB huge-page fault is shortened by at least 25628 us (figure inherited from the test results cited herein[1]). In user space, we can use system calls such as epoll and write to zero huge pages as they become available, and sleep when none are ready. The following pseudocode illustrates this approach. The pseudocode spawns eight threads that wait for huge pages on node 0 to become eligible for zeroing; whenever such pages are available, the threads clear them in parallel. static void thread_fun(void) { epoll_create(); epoll_ctl(); while (1) { val = read("/sys/devices/system/node/node0/hugepages/hugepages-1048576kB/zeroable_hugepages"); if (val > 0) system("echo max > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/zeroable_hugepages"); epoll_wait(); } } static void start_pre_zero_thread(int thread_num) { create_pre_zero_threads(thread_num, thread_fun) } int main(void) { start_pre_zero_thread(8); } [1]: https://lore.kernel.org/linux-mm/202412030519.W14yll4e-lkp@intel.com/T/#t Li Zhe (8): mm/hugetlb: add pre-zeroed framework mm/hugetlb: convert to prep_account_new_hugetlb_folio() mm/hugetlb: move the huge folio to the end of the list during enqueue mm/hugetlb: introduce per-node sysfs interface "zeroable_hugepages" mm/hugetlb: simplify function hugetlb_sysfs_add_hstate() mm/hugetlb: relocate the per-hstate struct kobject pointer mm/hugetlb: add epoll support for interface "zeroable_hugepages" mm/hugetlb: limit event generation frequency of function do_zero_free_notify() fs/hugetlbfs/inode.c | 3 +- include/linux/hugetlb.h | 26 ++++++ mm/hugetlb.c | 133 +++++++++++++++++++++++--- mm/hugetlb_internal.h | 6 ++ mm/hugetlb_sysfs.c | 202 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 335 insertions(+), 35 deletions(-) -- 2.20.1