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 D19B729D26E for ; Mon, 11 May 2026 21:47:58 +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=1778536080; cv=none; b=QKuo9bemL+cx9GQv3vpF6OfJW0lURRw/necn57nQ4mBal7RvSZpRbq27byLH6yl0MyooJNKSHXggzVX7YL2iE5lL/zYfsuPcS3mDRo88BGevYVRrLoAnnuStuxfn9W8fIzFB/JNLXQi4UDKC6riscgONvTuuTi8smiFgLW7BOvg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778536080; c=relaxed/simple; bh=66iH2gLYu4zQZAcOaJ3NTaFrvEJ477mi4pa9WQaFGSU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ve+2JyU7p52tiJskXZx8kAkjVFU0JE3Wnz0icZtKk6MQpb9rCwffnctiBO2AIBGfCEPUL0e2gwZnnAKkYeIyJBOIaHCelTuxgJxiprayjAlyQ+kg1rHvayBLRDxtv6VY9JDr/0E2aLvVQC/0EB5k06z3wpIT65lTHiTmxM1Wqn0= 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=We3Jcm0z; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=J7KajjBn; 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="We3Jcm0z"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="J7KajjBn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778536077; 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=H1xQri7WeZK2KoP5ZA3AQxtudqmOYwmsKhoFrsVAKDU=; b=We3Jcm0z0zWTR2lMgmkqZKpcJZCLmyi5HzfpYAf+169bQVb4V5eQ++IiWTv9+mMsVNlfx0 169+IsQODI7NpOforTUtjg9jL4S8ofaXfbkhDCpyXVxW6XUYkIJ2ZwSQVmHonvkGYn0aWs LfwM/gQv8zET5vSledQsSIlIqiDVDAw= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-YhtKqJ-pP8eEa-WrtjrXhQ-1; Mon, 11 May 2026 17:47:56 -0400 X-MC-Unique: YhtKqJ-pP8eEa-WrtjrXhQ-1 X-Mimecast-MFC-AGG-ID: YhtKqJ-pP8eEa-WrtjrXhQ_1778536075 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43d789cebcfso4065150f8f.1 for ; Mon, 11 May 2026 14:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778536075; x=1779140875; 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=H1xQri7WeZK2KoP5ZA3AQxtudqmOYwmsKhoFrsVAKDU=; b=J7KajjBnJ54pjWAYMRSsb0QaN2s8AymWVa9kjkDtSBBGJmpr6eJW5odqnv+PSC2Pm8 zwfqBDP1UUMAYTZ66JJxocTCj+t2WoySDo2bkC5Hg6JIJIRaZCYx68mHDmt/5EsVVadK rE1IrO9h3X4Ie1iAKw33RES7R/2OhLfhxU2rwOYuObEi1u9CZsL4T00gS0J2Rj1k92vy GLxY4EQ69F5erskVanp2Q3NcimKReNJx6TRE1s3evzLfG2ZnbcZaWNMaLWMFvkOjnj7A G0q84tv1anc70aqp5pYtVk0AeiHu5FoADgEF2UAYkxxK61nxsr+M+J+gBMRiliaHpRjg zP0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778536075; x=1779140875; 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=H1xQri7WeZK2KoP5ZA3AQxtudqmOYwmsKhoFrsVAKDU=; b=PURgjOakPgS/r4wmEA86GYSNskr2ViUwYIFB7yl8kBAQULkUfwfz4ZKCu9RjbA/cx7 qldgGi1ALjUWTcRYF9uzh7UUp8J1MrcSe/9N7FlVR0st85tz1F1szsIRh7jKR968XQIT L6dOQxLLnzmZ6ZFyRO/gY+t0ToRFAMjbyjUS9sn+TYSJoHmztXn/tM6yU1WVPOVyOSI6 +T9gFrRTf/cBLCydoekgb6rXWyEWlW2EHSGNFUM0OHtMGJUuyiVqwJL9CQkzvvGa1VGU ZklLMTgCgpu8qCCPsfb7ZtvCCSO2/xQqRiSqUrYNvk7nLYhkjxsk+8Aj2cELL5BYOH4/ tMSg== X-Gm-Message-State: AOJu0YxyF0ZquuTq0BT/n6Hpz73MOixrFrj7zeNIlXNiMUHDbMa81+BP uMbgGmaFZnWJTDCmnMl6MhIYVx3v+9YN2URbZ54VmBsGgZLCUnlsbjdVyQKF619TQTZWh1fTZZz jvUwKyHUFK0HiKsUuVPUseYD8NmwpzR++y33WPof1X7IaENqSB+Lz4dSyb23hqFUd3A== X-Gm-Gg: Acq92OG8kF/mtf206PTydwUf90d1U86Kumx326QOoskkUaYEZLBs+41kPZuLwmRezv4 QwiSFxue4K38tzBgt4MjFKc3NbpaDE76FxHgkS9hAzztKQdbdR0fjFe2IN9S+QiWedSlZyILP4v N3BcUcjfsniB62HPGJcjNhNqOmOMM9RTsRXHYykWpnRNJNCt5j8WImC93mElgN7G1WNZskcwI3a jOaEXs9WZvFFgPBVR4ahbEJbcCWR6Y2FdausPt8BQ7Ze9ZGRyn+CQLEtznR+lXW10X7X9IQx6LV nNfOPuoyEE22sdrRJkVOX79bhOFl01f2J/jcm1KgCuTxY77jiC0/0/ssHj8KP/KJ50bAnrKFnE7 B4eaAKpRY9StkgZ8cQglJnpX1I3pe0EACHGWuI/8d X-Received: by 2002:a05:600c:3f0a:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e8e208ec7mr17163405e9.9.1778536075131; Mon, 11 May 2026 14:47:55 -0700 (PDT) X-Received: by 2002:a05:600c:3f0a:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e8e208ec7mr17163285e9.9.1778536074640; Mon, 11 May 2026 14:47:54 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8e5dd3e1sm8561305e9.1.2026.05.11.14.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 14:47:54 -0700 (PDT) Date: Mon, 11 May 2026 17:47:48 -0400 From: "Michael S. Tsirkin" To: Gregory Price 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: <20260511174337-mutt-send-email-mst@kernel.org> 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 12:36:59PM -0400, Gregory Price wrote: > 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 Heh. The reason is that it either allocates from buddy - using gfp flags or from the pool, in which case it zeroes. We could even avoid the bool - just test __GFP_ZERO inside alloc_hugetlb_folio. Would that be better? -- MST