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.129.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 3F0193BFE4C for ; Wed, 20 May 2026 22:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315818; cv=none; b=crb5RS+3k4N193neFTTHdbkmNFzhQ8Oga2lMFb73YLYO+b2iK5m9YyxNv5fs7MErir/NbiD35huuIwRdQp71Em7eEQ47ZRQI0g/lny4FAvxcCZ8iUIpy8De6yeTnDnG8fdNlx50ryQu+c2Rze8KlZWSFdhcBMhigr+xylbTk4/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315818; c=relaxed/simple; bh=4jLzODooKNrRdgluzPWerRBde7vslo8ZvEbzyAfj6vs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uL+d8oEvig3i9wkN5HkFEJuzNUUF1U9cFJX+bUYaeNWODjz/vVMx/3Gq27is1J4yR2OvmM8GsPy/zJXWXmNVaOAMy8YmSqgbBq1+cNTY8MhC8jdcCroryAX2yWoMaXyUS1XMxUGp+NxTUxHUItjaYuxoMBsC/wuUni1V43LGbHI= 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=UDVJCnMe; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=i2zJUhn+; arc=none smtp.client-ip=170.10.129.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="UDVJCnMe"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="i2zJUhn+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315816; 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=RfirkbM5TmZ61fE0cxqW40X8dDTC2oX5xU5kp1FvlUs=; b=UDVJCnMeqL9Y804VfU1aS1nPg5k86wTtG5afXRosp90JyOiM6lAMhXNUJSrTRZkUr3AXmn fpZTF+fSvHggmZ9x2N4/77gHpm4tCl4Ye9tjvoGmcD6OCLMHFWSSg2uy0Zrv7NMzTqheW1 Qh8jgka2cC0UZsbzqs7e3lgtr2L8CcE= 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-385-bSqVn1dSOMqDzhN-b9Nhcg-1; Wed, 20 May 2026 18:23:34 -0400 X-MC-Unique: bSqVn1dSOMqDzhN-b9Nhcg-1 X-Mimecast-MFC-AGG-ID: bSqVn1dSOMqDzhN-b9Nhcg_1779315814 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48fe44ce385so43116705e9.0 for ; Wed, 20 May 2026 15:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315813; x=1779920613; 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=RfirkbM5TmZ61fE0cxqW40X8dDTC2oX5xU5kp1FvlUs=; b=i2zJUhn+h40vRXyy98eHacGk85O/p46nBPQpstfgGvKGv2V3iRrSJGexMGMpzmnyI0 7c1LNVOncCbbOdF3E6TNNJn/9okx1CG4+HHT4XttNN6of8KESMYyqTqQovwLGr56e2T7 7KLO8UJusFi2yXz8QIQ53UPj0EmYw2gfN5oPXBWX89hkKMSRLfFR9OJIj+OTZAgdQX1X P/N4VqJJy8IwlrCY2rXU20TLVs6KaM2itLOiRy1PFOB97RqYSBwsgX4/VZKIVknEUg1i ifg6E2hN/ymkIFxH2k+PEFSL+UrLYl3kSDJdVljQDd6/1+OW5p/2c28h3Cg9+OYyxyAN pHyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315813; x=1779920613; 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=RfirkbM5TmZ61fE0cxqW40X8dDTC2oX5xU5kp1FvlUs=; b=EXFFGVWFz8rbLmMbF+FLshwYHik768VM1tI8simRZLwSLrLo5tgk/3nNn1IckIJOq7 IwPUKO95ytDnrtf91LR/CMA0JDSH/gbS/eiwzStEYv6PlTGjf0Mi/KOkV2k019LnZZlU 6IcFRW5czLqx3pSAqYaIRwFfnD4mR4zWftXEjt1XoP2oR5RkrIIXvTe2qB5Qczw8lsqz FDQPvGd/GjmH0qzQapJLVd22uSMee2lO3uafgBPzTGLXsdxX/KG9uyZfWvaIFREOxNgT 9ghKuKrfT/EWjf5GMLUKQ7mZ22ihJVWRs8QTwAfykrTxobcNIgSwXb4TVERlLkTSHJr8 zE3w== X-Gm-Message-State: AOJu0YxJna2Q0OpBJMJ7CJOxi71Lbu2KJFmCk/VCgsirPFZVCtasmgG7 LYC9sQ1TBVPpnYqvhtJBkEls7oovhdDZEcpQ/yI/H0Qf7tCyegp6Hj3W4blu/+YJBK+y1LiFNRF NUId3F+St3hNn7Eaq75iWpQo7SMiJIZLO/pDZ2iGYavahtkO+Bk+Nz1Rm201ghhs9tvPmJ3dXPP EKZW8aQe8309V8GanJJXEVfcxXy6d+f5pVVU4V4BBizVU= X-Gm-Gg: Acq92OG4rp0wAPjCsGUxE8iNwqw+WLyxD61hq7B4oRAWmLat/dH15dnkH3aViXw/A5f b+xVWcivIeQHe6K0XFIkZrIL+t/4l4gQW2keSM0By9GiU+FYgiYRePCsGiFUhG54erGOIF8KfmV xZuPT4DD8uYy3on0ziBm0K+yq1dyPgKIflG8TLVoKXsa5ewOiJi82wGB4YobT2aNrGI6Znaj1rK bMypztP9X5hNxWxmwA9u7s5iQF77101qKbHRKI3cnIZDpTDViHXsZbnVvPApwex0fe8sDL4mF2p BntgX+SbV+ylkfA+qsmNe8aU7tbY8+G5kiYXRVtv8NCYZNuk+qqSpAY2ILe8c86TcNiWQwMfRru cOu4eTQv7+Fv3iW4K9JgTqF2ZhEfT3XNRMzLhsitM2NU= X-Received: by 2002:a05:600c:848d:b0:48e:635a:18d7 with SMTP id 5b1f17b1804b1-49035fbaad0mr3145165e9.0.1779315813538; Wed, 20 May 2026 15:23:33 -0700 (PDT) X-Received: by 2002:a05:600c:848d:b0:48e:635a:18d7 with SMTP id 5b1f17b1804b1-49035fbaad0mr3144455e9.0.1779315812865; Wed, 20 May 2026 15:23:32 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49033d8e24bsm20927915e9.10.2026.05.20.15.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:23:32 -0700 (PDT) Date: Wed, 20 May 2026 18:23:27 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , 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 , Gregory Price , 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 , Qi Zheng , Shakeel Butt , Youngjun Park Subject: [PATCH v8 35/37] mm: add put_page_zeroed and folio_put_zeroed 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: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Add put_page_zeroed() / folio_put_zeroed() for callers that hold a reference to a page known to be zeroed. If this drops the last reference, the zeroed hint is propagated to the buddy allocator. If someone else still holds a reference, the hint is simply lost - this is best-effort. This is useful for balloon drivers during deflation: the host has already zeroed the pages, and the balloon is typically the sole owner. But if the page happens to be shared, silently dropping the hint is safe and avoids the need for callers to check the refcount. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/mm.h | 13 +++++++++++++ mm/swap.c | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d1e768dcda13..86638ffaad01 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1913,6 +1913,7 @@ static inline struct folio *virt_to_folio(const void *x) } void __folio_put(struct folio *folio); +void __folio_put_zeroed(struct folio *folio); void split_page(struct page *page, unsigned int order); void folio_copy(struct folio *dst, struct folio *src); @@ -2090,6 +2091,18 @@ static inline void folio_put(struct folio *folio) __folio_put(folio); } +/* Caller must be sole owner to guarantee page is still zero */ +static inline void folio_put_zeroed(struct folio *folio) +{ + if (folio_put_testzero(folio)) + __folio_put_zeroed(folio); +} + +static inline void put_page_zeroed(struct page *page) +{ + folio_put_zeroed(page_folio(page)); +} + /** * folio_put_refs - Reduce the reference count on a folio. * @folio: The folio. diff --git a/mm/swap.c b/mm/swap.c index 5cc44f0de987..ecec780172ad 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -94,13 +94,15 @@ static void page_cache_release(struct folio *folio) lruvec_unlock_irqrestore(lruvec, flags); } -void __folio_put(struct folio *folio) +static void ___folio_put(struct folio *folio, bool zeroed) { + /* zeroed hint ignored for now, no current user */ if (unlikely(folio_is_zone_device(folio))) { free_zone_device_folio(folio); return; } + /* zeroed hint ignored for now, no current user */ if (folio_test_hugetlb(folio)) { free_huge_folio(folio); return; @@ -109,10 +111,24 @@ void __folio_put(struct folio *folio) page_cache_release(folio); folio_unqueue_deferred_split(folio); mem_cgroup_uncharge(folio); - free_frozen_pages(&folio->page, folio_order(folio)); + if (zeroed) + free_frozen_pages_zeroed(&folio->page, folio_order(folio)); + else + free_frozen_pages(&folio->page, folio_order(folio)); +} + +void __folio_put(struct folio *folio) +{ + ___folio_put(folio, false); } EXPORT_SYMBOL(__folio_put); +void __folio_put_zeroed(struct folio *folio) +{ + ___folio_put(folio, true); +} +EXPORT_SYMBOL(__folio_put_zeroed); + typedef void (*move_fn_t)(struct lruvec *lruvec, struct folio *folio); static void lru_add(struct lruvec *lruvec, struct folio *folio) -- MST