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 6441F438FF5 for ; Fri, 29 May 2026 15:25:30 +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=1780068332; cv=none; b=EieM6WDzyUNOpvMtwf6zVJkGpoq1IgekvZTxOnDvrf9MfjwgkwgRGyxVXL8qIiHYpw5w8YRMHXL8nRQoF7i21WcwOFX6ZCLgXa+5IHwPiYysx/G1jpzFbGVFj8qkXbZwCRKb2zWVogFUD0Z3KA1lMMp6dsiNCmbsvKYWfIJbhR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068332; c=relaxed/simple; bh=4jLzODooKNrRdgluzPWerRBde7vslo8ZvEbzyAfj6vs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ISVDsrpkjY4DX6gCfhBtBwbxew9bCzGkcaB5l4/Tfuor92Eczf2mLjSUaSr4UprlA4yNomyG81he+kVWddTWGSVQfCBluB4UFYT3SwdEk+w7Th5Gv7G0kd5lmjWWd+ocMrqEpPs/rMDhExOuhbNsRIW6smE7gn7XYKqlN/P/ZUc= 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=gUu1Hc0H; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=aUzcSMVY; 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="gUu1Hc0H"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="aUzcSMVY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068329; 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=gUu1Hc0HAnHS78irJmTo5NJLq/aeeiWVp/uuOS+xq0dD35JGzFv3cl7+f35K1ciKM+gJ0A L7vL6zQx/Oc77uLD0ubZDTdEc7SK2lpeZ/jLa9iUJk186D7qIoiWCjfcLIvFifOiEwCN8G QBC+WZ937aEffVFI/1LtShD8ioTBgp0= 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-611-Eh4qUj1RORSLwAIn09h4iw-1; Fri, 29 May 2026 11:25:26 -0400 X-MC-Unique: Eh4qUj1RORSLwAIn09h4iw-1 X-Mimecast-MFC-AGG-ID: Eh4qUj1RORSLwAIn09h4iw_1780068326 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-45ef6417092so186647f8f.2 for ; Fri, 29 May 2026 08:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068325; x=1780673125; 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=aUzcSMVYTcG1a1AoBEOZITGRPzrodlZ6S8FCh5TOwuQxVP3MDZLE0SqYMlBlpTxsAD bUlvypdN4BclYIcVp8nQ5YjjjeZxDnC6+brRWOEBBXQyamza/AxxvG2XQYxOb0vPTfgz ysLM2lwYparz4wKPw5LiZQjb+uwU14Yb8DC3+WtbLlXKHOWA94nDv/zICbiaWQNBA5Tq DOq1O+760oIIqB+4NzjFUNmDcuOKkzmjEt2o2KvjwCip4VJDs+aQNOKhBKuNqEeuHQNo VZzwLJ2ExMgEx2tMlu0ttmx7mdzGsXbHYwyduBnMNJaI66tj9TYaL7PSKAy8VnbKAXWF pm1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068325; x=1780673125; 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=OX1gZ7Zn4XA8n7AowoZxOsHCh6laNCmgJy3mDtmd5R7pw7/uhbe+/bNOzHoL95LiVj oE9BwqRDuXy82MnvO1XdDfdRlNpM8UeBirmqRKV8PtrDdeeS5D3IJR9Pqmvu8FVy4J5V Y8w2D9zWDQ/B95m3pjY6bmr5csukITpw5ls2mxh25U5wlKg921vC5JiXmSa45ZHgNRX9 gi3Z+6RvvBlBjlc90aU93T23e2RJbAhsHopyc5rRXG6xVS2fU6xGRHxljF4IBXRebzgw R77PTymKeYNEr6DqXG4xqATTZExB0pQ96IfTI0DeO1P96e2hQ2Wyf5iUE/8edGkromwz RkTQ== X-Gm-Message-State: AOJu0YxmVEXrbeNVL3f5yjqlV+OPELc5zddPt8GxyaNEBjqDm8C0lZ6+ jrQgrHQ+ogEjAaoyJCLGEdr+hwvrueOoOwc5GApgx+W2w1W3FDSdsRjxyCj0vUDQiVSndGWWiWB KqMZgsDQafFkNy/MhWbvXodZY1Z5adQ1Wo7h5qELCMAkHTyL/KMDb5ulIUHge3G8t6h6962BTVU kI59142UaE6ddYVnByKfMtov6J7SjHY95sMMNUvO4luvA= X-Gm-Gg: Acq92OEMra3GbmqxRVaE9jTcIXSIMAPW9lBWhwQoDkHqnzp75yyT1BkgiRHlSRPI7h3 oLDdw6moUmVIoXquwYx0+JNW3Mamjdgm3a098BMObgHAAn36tggfTIki7sUlKMonQTdqQkhphv4 gXfTSrB1VLvB6ChutPwJkmboZV3pYkccUjT9BzVgeFdUTu2xzk66ERDmUqx+ff1lxN3PP2nBCT/ GLstgkvYjTVtgH4C6eyEsOT+ihUefxToMfS0Clqh+oFum4xauyTj/N2Enu6r5HpoTD8ZlwrVWhq TqJ3nz4dh8MPuu7N82RKMuig58B/pWuF4DwskfSuRcsvGApkdWLYD2K2jBDvBDRxtBPwlruwKAq ikcg5XXZJASk7vxbSNqJaVxU3D6iVPv2DabvP+GFCIF84E0m42SwFzQ== X-Received: by 2002:a05:600c:450d:b0:490:778:4fe4 with SMTP id 5b1f17b1804b1-490a2952091mr1218605e9.26.1780068325379; Fri, 29 May 2026 08:25:25 -0700 (PDT) X-Received: by 2002:a05:600c:450d:b0:490:778:4fe4 with SMTP id 5b1f17b1804b1-490a2952091mr1217355e9.26.1780068324663; Fri, 29 May 2026 08:25:24 -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 ffacd0b85a97d-45ef34b7d6bsm4731601f8f.10.2026.05.29.08.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:25:24 -0700 (PDT) Date: Fri, 29 May 2026 11:25:19 -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 v9 35/37] mm: add put_page_zeroed and folio_put_zeroed Message-ID: <343a0d61f4b597791e3ebd16dffc5b91a0d733e0.1780067978.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 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