From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 1E4C02DF13A for ; Sun, 12 Apr 2026 22:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776034277; cv=none; b=aVpLeE4PhOt9L1/UPuhQqN0u/NPhx8xd+iyCIbdj4I3TZYE2mkiA7AZS3xPt/z3woPMstX/r2PpDHYWp271EHCwS12Czx4kTvDltxqOLkPZKEsMFYqSw+Camidn2GHyxIP5J1otVipNLFrUtVQAzoPGvV6cHLQsTh7sYoUD7Xmw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776034277; c=relaxed/simple; bh=wQTexAwnGytwCFSIS/P6kaYAjB5J4jvqVusvwQE/7Cs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BChXEpWPjzddRj47N+GQMwNieh/S7miZj02fazt4YkR05XD/9h/zvwYVf9oz1fi7luZK7pTl+mbLlgkaajQB8gBdD8jr8+WV+z1RT2RXpQQoB4VA4sbMq3iDtNZnty0LzzMc/xzEfZkmP+TqXoyDY1+g8az0arDWZMMeTFWj5W0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fu1CzD+B; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=s+HA1VM9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fu1CzD+B"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="s+HA1VM9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776034275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r7PQCfO1LkfIlhF+m0/p+q9abrYZpC0b3LWn2Ob4o6U=; b=fu1CzD+BMumnfx9vR6GOdf786bHrfgbCJrLKwOudYOO6x4ha1357fpUtT7kpXx49dlfNHH WFQXzkaCusX5IlyAYAkLOVphMf/k8eSw/UygjWqGSbApxwTM/k8YFYGa3M0I6EtuFNj1N0 JkqcjlyD/mXjH7XMj6nJPQ0fWpcBjUw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-0TtdwjPIPdaHIu1tgA9_Bw-1; Sun, 12 Apr 2026 18:51:07 -0400 X-MC-Unique: 0TtdwjPIPdaHIu1tgA9_Bw-1 X-Mimecast-MFC-AGG-ID: 0TtdwjPIPdaHIu1tgA9_Bw_1776034266 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4837bfcfe0dso31266775e9.1 for ; Sun, 12 Apr 2026 15:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776034266; x=1776639066; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=r7PQCfO1LkfIlhF+m0/p+q9abrYZpC0b3LWn2Ob4o6U=; b=s+HA1VM9CmJd6wXx2oQUTmB/nT78FijhLXvU0/QP+3poY2x2EdOihkkrKHdiauVMu6 GJ/YRZGye70cTGhnaczaOFVSH7UL0wLnKAJEVYBlAzdewNBHSe03dVKpt3kY2cFB9cv9 HNSmXIjvKh6hWTNPQfCosce9WtPrA6JbMM6KZWwn2eRA5n3TouFRk8GkLW0NnFY1DAoc 1pgK0bgmURemcGil2qR3OGxw8tHDlB1xafSsFEIlAlrr53jcY1dZ901t6LbNoQVFFZcf EAIPCdu4T4uFBgWH8utDDlUd2uPon9/J1/S6vYZYUn1R2nHnAdqyagHYuNLh+ZjvT0wh l5uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776034266; x=1776639066; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r7PQCfO1LkfIlhF+m0/p+q9abrYZpC0b3LWn2Ob4o6U=; b=ZWAwVbZB+l1EustVXGDZjtUVZ8NUylWAkTs46JIV+w+vXeXxjDusYl8TAP9qNpW3mJ ScHmnIVXfqgAgFQLDMZPdNOsvRUlJILP9Nks96pr0TTMTMp0kFJ6Gf9jiLRnyBReXC1H YNf9O/DaXoSEAPzKEAq2kerCVReGXRKhcS+UJk97zx8DxEVgWJe9d2+8a0O1PreNLN+7 f0dlNyrXFrGJyCIDWZ1cOfIq9RwYqt5P4laoXmYjclBGvLv+5q56Bf+qM0kTnevqbg1a ZVJ4fb5v6ZB8F2sQfcvty8jiC8LNSsEoJ9Lk56XxUV0SJWv/wC8f22x0+RwgMsPvhv+h TVKQ== X-Gm-Message-State: AOJu0Yy6scB+xEUhFX3w4PpbcRHnUOvmrgnefV9zrqeKHzQ+1AbYDEi1 Ymf7NzS+1ca2ecd6t26NqT+08zoWTHd8ypzCdixsZ7BVG02f2iZdyTMFHa53v6DJBHC8o7ekl80 sr0L1Y0FJQ6izd3zD/CZ7r+4j/l+XYOWQhlG3BJ6aIR3xIv8LOTk+Q0W/gbTS2dSiq05Yt45tkX m7f7jnzYbDpiXUQi+UBE7MfQDzocJvzgqhqeOHdSZFYJQ= X-Gm-Gg: AeBDieud4I+oPR4c46rfSX+II4/hBhY12VqvSZqdfQYU0JiN13fIFfUkL8Fdlj8YSa/ SF+SFasZVTcF0i2ZWR79cTHdSWbChyda6omL5HxAyI86A56PTIeQFxLlfXO1Soy1QYd7mcnhu4O wdWkjML5XvCwToVUzEKFJl9mbXTdg//i0Szt3ryb4GalF3aSscfMNB8M3F3TX7gPKfLPS+wj6VX 6TsAGpvzaOsWmbw9rKFTHg5Mtzdj7b39tFJi2TAKVSG3NXLyP0oOq0BniggD4+9Sj61LgbqgYBp 2zoVp9NlnfLSQmyjfgiX7HVFIyba/HHKWqm49RReVbmjRQnwpPpKqQrTLV2N09N4zTNNV1rc/WR SDjPQ+Sir9NgYelNPwy0aXzcjrxT1hzbudiua7lLV3D4= X-Received: by 2002:a05:600c:8585:b0:488:9bf8:7f17 with SMTP id 5b1f17b1804b1-488d684bcb0mr113206735e9.14.1776034265610; Sun, 12 Apr 2026 15:51:05 -0700 (PDT) X-Received: by 2002:a05:600c:8585:b0:488:9bf8:7f17 with SMTP id 5b1f17b1804b1-488d684bcb0mr113206465e9.14.1776034265017; Sun, 12 Apr 2026 15:51:05 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-21.inter.net.il. [80.230.25.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488d6881ea1sm80171315e9.33.2026.04.12.15.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 15:51:04 -0700 (PDT) Date: Sun, 12 Apr 2026 18:51:00 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Andrew Morton , David Hildenbrand , Vlastimil Babka , Brendan Jackman , Michal Hocko , Suren Baghdasaryan , Jason Wang , Andrea Arcangeli , linux-mm@kvack.org, virtualization@lists.linux.dev, Muchun Song , Oscar Salvador Subject: [PATCH RFC 7/9] mm: hugetlb: skip zeroing of pre-zeroed hugetlb pages Message-ID: <7d1c82bd0fe7f80212cb5ff7dafe24e1debca8f6.1776033771.git.mst@redhat.com> References: 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=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent When a surplus hugetlb page is allocated from the buddy allocator and the page was previously reported to the host (and zeroed on reclaim), skip the redundant folio_zero_user() in the hugetlb fault path. This only benefits surplus hugetlb pages that are freshly allocated from the buddy. Pages from the persistent hugetlb pool are not affected since they are not allocated from buddy at fault time. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- fs/hugetlbfs/inode.c | 3 ++- include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 3f70c47981de..301567ad160f 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -828,7 +828,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, error = PTR_ERR(folio); goto out; } - folio_zero_user(folio, addr); + if (!folio_test_clear_prezeroed(folio)) + folio_zero_user(folio, addr); __folio_mark_uptodate(folio); error = hugetlb_add_to_page_cache(folio, mapping, index); if (unlikely(error)) { diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 65910437be1c..07e3ef8c0418 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -937,7 +937,7 @@ static inline bool hugepage_movable_supported(struct hstate *h) /* Movability of hugepages depends on migration support. */ static inline gfp_t htlb_alloc_mask(struct hstate *h) { - gfp_t gfp = __GFP_COMP | __GFP_NOWARN; + gfp_t gfp = __GFP_COMP | __GFP_NOWARN | __GFP_PREZEROED; gfp |= hugepage_movable_supported(h) ? GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0beb6e22bc26..5b23b006c37c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5809,7 +5809,8 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, ret = 0; goto out; } - folio_zero_user(folio, vmf->real_address); + if (!folio_test_clear_prezeroed(folio)) + folio_zero_user(folio, vmf->real_address); __folio_mark_uptodate(folio); new_folio = true; -- MST