On Mon, Jun 08, 2026 at 02:46:34PM +0200, David Hildenbrand (Arm) wrote: > On 6/8/26 14:25, Lorenzo Stoakes wrote: > > On Mon, Jun 08, 2026 at 04:38:54AM -0400, Michael S. Tsirkin wrote: > >> 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. > >> > >> Note: put_page_zeroed uses folio_put_testzero() which only > >> detects sole ownership at the instant of the atomic decrement. > >> A concurrent reference holder (e.g. migration) means the hint > >> is silently lost. This is by design: the zeroed hint is a > >> performance optimization, not a correctness requirement. > >> Losing it just means the next allocation re-zeroes the page. > > > > Do not put comments about specific expected races like this in the commit > > message but not in the code. Subtleties need to be called out. > > > > The commit message also doesn't at all explain why PG_zeroed doesn't > > suffice here. > > > >> > >> Signed-off-by: Michael S. Tsirkin <[email protected]> > >> Assisted-by: Claude:claude-opus-4-6 > > > > I really don't understand why you have a 'zeroed' folio flag but need to > > also have new API calls to detect that? > > > > They're also HORRIBLY named. Zeroed as in what? Zero page? Huge zero page? > > Memory zeroed by kernel? Pages that userland happen to have zeroed? Or host > > VM zeroed? > > > > Each are cases we address individually and relate to folios. > > > > You absolutely fail to clarify _which one_ you mean, and provide absolutely > > no documentation and add an exported mm API with no description. > > > > This is just I think not something we want to add? Especially on something > > so fundamental? > > I raised previously that providing a folio helper is odd, and that I suggested > that we defer this change.
Sadly it's a dependency actually - without it memcg failures would cause repeated re-zeroing where previously it failed without zeroing. It's the result of the whole GFP_ZERO idea. > Maybe we'd want to add such an interface for frozen pages later (to be used by > the balloon), but I don't think we want that for folios. > > [1] > https://lore.kernel.org/all/[email protected]/ > > -- > Cheers, > > David

