From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 50A9244102C for ; Mon, 11 May 2026 16:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778517425; cv=none; b=SvTiGQVGLcpcXrYSZjqBa22xd4471GF4LLaaFt3lUxxcs6aiFAAPto+eAudMb1G6X2Xl71yVvIR9NnzzSQkl5PsikoNYX0fzauLD+DpfVEKMraULoPu5CA3wXcnCoH40DLLkTEH7Pl3+mpD+RJ4n8W4mYVCTMeHeMDnz0OwJ6MY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778517425; c=relaxed/simple; bh=32rtVjsBu7bs/E7DjCga1Xn78UtvzNsnqDjSRttbyRc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ob5QZf+30S/j4omSzTGDmhNz7blzIlzr+ECfNcb0yht11QF3w0P7xooaMOosuEuR3wCnRQ4jVhA+h4RkC05oOmCfuWCo9KOaEyKNxW9qMR1E5fZDTu8HoKUuU+Qfhatno2DEDRwd8esNWgiLTGkdLHoyFD1VTbtVYBXoSkYvZLA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=mnuJks6C; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="mnuJks6C" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-8ef5776530bso436794485a.0 for ; Mon, 11 May 2026 09:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1778517423; x=1779122223; 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=DPk5XHw7qn/fXCccKXVO5r2Z4HwdHblAfBNUt8aXN5s=; b=mnuJks6Cx11n572iPwbP1vzGqJCpM+jOgS4x4aY4Wr3p0a9Ws+RAyGJycwyDyJMCS6 sFVdijxHZi30atS3IJRFc1xuipXsDfauYTTqM25GuHRRmYBIuSS/kwovg6mnFU3xuo0R gsQFz8o7cAs/oZI+kJNJAPj/JVJEMRtbZInVyy0kra4KhrLIYvPNLpIAxywq2O1RhZL9 FqU+F+4+gN8eLcn6pDM54Nar5RpAmDV/qclM/69ykFW0wiAGdXeRZfkiQdIdgWCfeVyE S28X+Eo483PYOpDn15exA3reoQoGqQyzsY8Owkb4v6XCXSutlKSDc+3f4n25+3cIUeZm Bfgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778517423; x=1779122223; 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=DPk5XHw7qn/fXCccKXVO5r2Z4HwdHblAfBNUt8aXN5s=; b=N5TVa7nnhPXh2YaV2WSn+oKLqzMydy7i2hkXQcOI+tr49S9SC9+nKILsN0CmwS4CKO D+fxkLMmByrS5+ftm2CBqlVDzYGfi1Z62BkFhhMd/bYMXFCVJMybxrfVqL5+ftX7T5u0 KV6aXulGLkosncZek/bbd8bQDc9OXxvGWcW43tQexQLbXs4lCV37YUnKSKUhZlg9v1Kj nUciVI0xOixq1OoevBWtuUKEP5WyBh1hLV/MpBzjwnlB4r34aj+DL9oS8N+Uyn+Ej/Ft Gn34mQDW7Rj6aVjJQk2DP38sdGHkKBwLl4Jk40QSVpjJ7IK8/KeYCGGrNsfm8tcc18YT UEuA== X-Gm-Message-State: AOJu0Yxwl63UvRX/FPNJMqh6sEwxXQ7O5N9Guf7ONrzE5fweSqM9wg56 X1nbu36ObdAz2Z2+hgAmCuoJvyLhmOnCzMb29sTLebyrhrac/cLrlwjsW7lTelhTT5c= X-Gm-Gg: Acq92OElFeWIcCvrxyGx/g5uxDDI2cqQb0zc6p/OOWYsGncR3OvxiMVQn42qDm0tWgW expJcUT9GaJYyC2QjvvPFAv4QAd9yrNsAndzVzq9MXYkoG+kk7N0rtdx1rm2OQkM1+I3HwI9hpn 6kZvEUFbJP3aSOaC6zp6Olm+ksHScxneFfROepfEiEQDaScqicucReCu4HkrlRiMJaxlAtmab+I uiRGuWCD6Z3CH0MZf3N2WXgaJRBM6e+HfZg/IDeKU8U4QSqUbjXkO08ZOs8ec06o0CTKbACBv6E 4tbXCHmRtGqAeroZ9XA5bP31/NMSMpDBfaBZMRIaxUI1mnpnGP5FNussbBshD1nEVkXHci7KGkI 2iLvksi3Sf9iY8dLwmH/u91tdBU0/pvlXDErqET5BpGaZ7YoPf+VvYozjJ7KtzM1dTxkVxxeDnZ Jdmi9aQrtlN1kPCmKHNkiCSD8KHCy9dvwRaN6A6A9Xh4FgVl8kMkELOtAju09WzsE+0ko9wYjnl zYHxmi+xKdS X-Received: by 2002:a05:620a:17aa:b0:8cf:f2ec:c52c with SMTP id af79cd13be357-9090dfffe49mr1442495885a.7.1778517422959; Mon, 11 May 2026 09:37:02 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F (pool-100-36-248-188.washdc.fios.verizon.net. [100.36.248.188]) by smtp.gmail.com with ESMTPSA id af79cd13be357-907b87bd588sm1178556285a.29.2026.05.11.09.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 09:37:01 -0700 (PDT) Date: Mon, 11 May 2026 12:36:59 -0400 From: Gregory Price To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: Re: [PATCH resend v6 14/30] mm: hugetlb: use __GFP_ZERO and skip zeroing for zeroed pages Message-ID: 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: On Mon, May 11, 2026 at 05:03:02AM -0400, Michael S. Tsirkin wrote: > Convert the hugetlb fault and fallocate paths to use __GFP_ZERO. > For pages allocated from the buddy allocator, post_alloc_hook() > handles zeroing. > > Hugetlb surplus pages need special handling because they can be > pre-allocated into the pool during mmap (by hugetlb_acct_memory) > before any page fault. Pool pages are kept around and may need > zeroing long after buddy allocation, so a buddy-level zeroed > hint (consumed at allocation time) cannot track their state. > > Add a bool *zeroed output parameter to alloc_hugetlb_folio() > so callers know whether the page needs zeroing. Buddy-allocated > pages are always zeroed (zeroed by post_alloc_hook). Pool > pages use a new HPG_zeroed flag to track whether the page is > known-zero (freshly buddy-allocated, never mapped to userspace). > The flag is set in alloc_surplus_hugetlb_folio() after buddy > allocation and cleared in free_huge_folio() when a user-mapped > page returns to the pool. > > Callers that do not need zeroing (CoW, migration) pass NULL for > zeroed and 0 for gfp. > > Signed-off-by: Michael S. Tsirkin > Assisted-by: Claude:claude-opus-4-6 > Assisted-by: cursor-agent:GPT-5.4-xhigh > --- > fs/hugetlbfs/inode.c | 10 ++++++-- > include/linux/hugetlb.h | 8 +++++-- > mm/hugetlb.c | 52 ++++++++++++++++++++++++++++++----------- > 3 files changed, 53 insertions(+), 17 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 8b05bec08e04..24e42cb10ade 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -810,14 +810,20 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, > * folios in these areas, we need to consume the reserves > * to keep reservation accounting consistent. > */ > - folio = alloc_hugetlb_folio(&pseudo_vma, addr, false); > + { > + bool zeroed; > + > + folio = alloc_hugetlb_folio(&pseudo_vma, addr, false, > + __GFP_ZERO, &zeroed); This feels like a very odd pattern: 1) ask for __GFP_ZERO 2) Have to check whether it was actually zeroed Seems like the zeroing piece should just be sunk in if you're going to ask for __GFP_ZERO anyway. And in that case, maybe just `bool zero` as an argument, rather than GFP (to avoid future overloading of flags). ~Gregory