From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (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 D2F0C378D94 for ; Tue, 12 May 2026 22:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778623425; cv=none; b=mKJytA2tJ5ygTt7nK2VmbMHa4Fz/cWNWVXakyuKm1GrFqvfrjLcUWIC3lvk19/T0zlJ+D7AsLX0a0CsAWPya+5tXjyy2TE8hOtLCCLgMl7hEqeJHLEeUeoKF1kk5WFi4vdXtfjnEPoB1BLjvqBK5k9puu8qU9j0GMsjpwBuIZqc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778623425; c=relaxed/simple; bh=P11G55OuJ+x8NFPakVaRen/yKl8LGk3f8r6ZSNSvUlg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fEhHa5Q5KdM+a+J5XT0D0RR2o6yh6sdaGGumsGprhTntd3it9R5tZgPSETlpjStp4GdMxEzbIFZMwkPKV+CMJUfeCXJ+oSfKdyDOSTqDvvCTDGUNr4JQrsVEtwNsA7au0rjb7ioJQtpQ6u2pSRma/pxl0CWfukZq3kE25D024YM= 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=jsT43T3c; arc=none smtp.client-ip=209.85.160.170 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="jsT43T3c" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-50d75bfb259so40932951cf.1 for ; Tue, 12 May 2026 15:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1778623423; x=1779228223; 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=Fpy4x7dEQdIOgJjvqOzPRDk/nU9rzNx4M+UIRXa20ZQ=; b=jsT43T3cT9yGQu/crmwxkQxlp9rbtY8Z5LtApvHsfgw4u5WkDzwkD4wAjrO+Um7FoH W0wUMuWW93bjckdlQmZ9mEh50+8c3WdVUvx5xTWZ7x1mnKSNBz7btFQkQ3s3h6kLWL2s IF751qamqB6BGt7rypxVe11WtdHK4RCKZcM4VE9p+9kCfTRylOr2XSYYHT4e3Yk3JWer pweQ8lfRKOXhaXIFDK5DMKpS0C6whaM25dkynMIdA96S53aui+Q85Dr6kCtSI6oej5u6 Wi6LxYIVl29Oq4uvZKQG3PESN97AryYq6ZCPVcki9amq/mk55igNFlcbXvxw6l5FsaBa QUpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778623423; x=1779228223; 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=Fpy4x7dEQdIOgJjvqOzPRDk/nU9rzNx4M+UIRXa20ZQ=; b=cNTElpnJXJ7RpzucHTCTvpmPFYqzN1Ods2CZlg9b/129M4xTs5c5PQPann+5Sc2Nz8 yZcPgPnCPqlW/WQuLjMzjJdQtsBpbxhm3mq+AYvlNm+MUmca8ctvegyVIrj9pwXmT0vX RKLF+gP9qnNq7Qz7jAQ40heyapHQg84lmwLFjRvJKdRUtmtPJBjX2EChD3oBelmIw1OB xg4cv2OBSQ+yggeauX2M0EdFboYJwBd28+Wl+qpNff2rccsfjQNdEOVoAAHmCt62lLEe qmEX6pLrciHjq3h6GuEEdEPb0ATNj3KY6MYeRGzjCSCgb33R+HkbzStt17HunCZcHK5C QTJQ== X-Gm-Message-State: AOJu0YyU6FEBA9//JRAJULFmxoXSxWPz8/dQfpuAaZTq67WgiUZ5TRhS 427ai5A6Ov28bZE17wbld96DAek4OSc3IlsXbHlu94fdKnkgmY3OJsN07MwPDNtnnd8= X-Gm-Gg: Acq92OHR1De9yuZiMJlnmpiqefbE143Bv7BIKlsp5mmR4SIvB5OZtAqmWsu2EaC/VvI npDcLbFTVkrEa7y61wEejw8MqW/0igdeIrvmR90bBfiBZLC7kybhVmpG3sdZyG/BSrok1Nhv5YX X6YkVbR+ZbudvI7wXKkZLUfrJr6KWFKg5fpN1W4xK0YMjfqqGZfG64mEUDtw2tiBvFxUqFnP6RQ J21UFEb/LLB1IPI9XH5Fpdl4Bp7Yj4gtFjxkTLbtk//81ZB4f+TtplWIzTZt1ScBhOfrtTDPiVs p7RjfJlLVpYqZg26ni4aimdnAiaymzswb+t+96jQeinq/PXLH4Iz5W4vCYEuldr4t/n54Crmyt3 LX80ZOSl09MhTo47E7Shj7vt0lFbAYhsivYF+rj3Z+KENBJ6C+cc0X292OEum1Lk+8670qJcKw1 /JQRL/nOKeTfdESeHw/M8lRLRDw8EJZnA4g+TqB0x4zobqDs0R7yh3FZWzr9YwL+KeBwn3rc+U7 5wtCwBmaJRO5a2VI8756eo= X-Received: by 2002:a05:622a:11ce:b0:50f:f0be:dc7b with SMTP id d75a77b69052e-5162ff46f46mr3954791cf.39.1778623422619; Tue, 12 May 2026 15:03:42 -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 d75a77b69052e-5148e7c0fa5sm141204081cf.16.2026.05.12.15.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 15:03:42 -0700 (PDT) Date: Tue, 12 May 2026 18:03:39 -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 v7 17/31] mm: hugetlb: add gfp parameter and skip zeroing for zeroed pages Message-ID: References: <4039b0b96594b69b15ad4bcd64cbb33de3cec350.1778616612.git.mst@redhat.com> 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: <4039b0b96594b69b15ad4bcd64cbb33de3cec350.1778616612.git.mst@redhat.com> On Tue, May 12, 2026 at 05:06:37PM -0400, Michael S. Tsirkin wrote: > Add a gfp_t parameter to alloc_hugetlb_folio(). When __GFP_ZERO > is set, the function guarantees the returned folio is zeroed: > - Fresh allocations (buddy or gigantic): zeroed by > post_alloc_hook via __GFP_ZERO. > - Pool pages with HPG_zeroed set: already zeroed, skip. > - Pool pages without HPG_zeroed: zeroed via folio_zero_user(). > > The address parameter is renamed to user_addr; the function > aligns it internally for reservation and NUMA policy lookups. > For pool pages that need zeroing, user_addr is passed to > folio_zero_user() for cache-friendly zeroing near the faulting > subpage. All callers pass a page-aligned address; the > hugetlb_no_page caller passes vmf->real_address & PAGE_MASK > for consistency. > > HPG_zeroed (stored in hugetlb folio->private bits) tracks > known-zero pool pages. It is set when alloc_surplus_hugetlb_folio > allocates with __GFP_ZERO, and cleared in free_huge_folio when > the page returns to the pool after userspace use. > > Suggested-by: Gregory Price > 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 | 3 +-- > include/linux/hugetlb.h | 5 ++++- > mm/hugetlb.c | 47 ++++++++++++++++++++++++++++++----------- > 3 files changed, 40 insertions(+), 15 deletions(-) > This seems much much cleaner this way. One nit, doesn't need a respin unless you feel like it. Reviewed-by: Gregory Price > @@ -2980,6 +2993,11 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > > spin_unlock_irq(&hugetlb_lock); > > + if ((gfp & __GFP_ZERO) && from_pool && > + !folio_test_hugetlb_zeroed(folio)) stupid question: if (!from_pool) - wouldn't folio_test_hugetlb_zeroed(folio) be true because __GFP_ZERO is passed? If not, SHOULD it be true (i.e. should we be setting that in the non-pool allocation path when __GFP_ZERO is passed and allocation succeeds?) If so, can this just be simplified to: if ((gfp & __GFP_ZERO) && !folio_test_hugetlb_zeroed(folio)) Maybe that lets you eliminate the bool entirely? ~Gregory