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 73F143C3443 for ; Mon, 11 May 2026 09:02:25 +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=1778490146; cv=none; b=AAw3FJtUARHrtfc4TwHrPDVOIgbXctmunb6C7smHOZUlyAEwwquadXTb73tslB4rkBRTJsNqRz6MFcjLIfK1RRmnK4vJhKRTWgAQk88ea8mVoNdxNEOI4gvfOQhunNtt4MDNzHvtWkEAanI011hh0NMdbUuNwW/6I7honP2KjzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490146; c=relaxed/simple; bh=B3Elvsk2QbFB4j/MM54kU4HNtRj52gz2EfVB/ero4mc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GkYxz4P1Raxkf6LdvCezb5ckZoYRXWbhayDG7lQXUWEoHjxtQ6070oNJD5KIi4DTIO6XeaqXWWdG2WB0fENTyHBnxjAQKj8lPMgFLC0S1ecP/BImHDwbA+e0UunzCpaPnpA+f5DB7ljaDU/eNUOSa2EFxqDIL79CPfVbz4vRZtM= 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=gLMAdN1R; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=OoZW9QZu; 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="gLMAdN1R"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="OoZW9QZu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490144; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=gLMAdN1R/F4XKfMncfrbYvcUcowApFYWp60XFZWEtuol5vZ9+OR1bC1G9XXe3mktAW027d NXbSZJ88YE8hY3Ps5ySGsphb2iImEdKlBwzt9yYVC7LR46Srv65+IZjdQABPX+fnmTPBxj yrLhxPJk/2yAL/wd87oSlQvPlibaNV8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-YwPMQrk3MT2ifgtpB7D8fw-1; Mon, 11 May 2026 05:02:22 -0400 X-MC-Unique: YwPMQrk3MT2ifgtpB7D8fw-1 X-Mimecast-MFC-AGG-ID: YwPMQrk3MT2ifgtpB7D8fw_1778490141 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b8704795d25so326907966b.2 for ; Mon, 11 May 2026 02:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490141; x=1779094941; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=OoZW9QZu5TXmsWTfDYUbK4LvCRplUDXjit5ms3Dttqo/jLKb7EQudNd1NdZatrKPHR 9jL09BZwnEPg+mayHVSBRESXHBW+shsC0OhrDQmvR6OWfKdES6u16MBcY9EGYezuzC6q XuX3ZyihVgzvJg/c6svWsEw0l0nqKAkJdNecfYdW4QDi2Wq3/mTL4e4sStyCDKc97VD3 Yl01n0vjfaFAH5uNvoordE7oZTZTcNOELZF7uCzpRT5RM9b/4zvvxJv0ENWP78JXK2EP 4D0pupHo04oA4J1oSdYqc/yTyy31CiC1rDwXbnkzVfyPdzR9LniJpJ3+ek7X2LDpWwJS 6gIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490141; x=1779094941; 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=zuBj5G8Fe8DfsQghniXtZy4OYrf8Ud9rSYDvYLkW/0M=; b=TTm2RtRtvyLm+d/Ie3NwC9Za3cK0vYO/gdPX2KimXWrpQWXh5fqnNEmuMkCzTupgu/ LlLrpDMiTKk700LYlLeQUZ76qlb7WM9Ri3/RZnMuK6ZaDl1cFAJkmkt/C5sihCSG3jcu SYBj1LTCom5DhFvFcmy87hCgBLgL4gqGm4PCU7ZaSpQr/sbcArhbDB66uSK7TxcDBtEH s8iCpHEs49wBh84yz2TajsoUHbRI376FKVIgpvqoRwHZpPtAUrWnL8pjt0pW3LOl25QZ jbgBzA/yD/XMTfK7LDsIBQC7qMixsKRvDxUWXGDqw4pEGr9apTzyXAVv1v7GkUjDQMDr VaVw== X-Gm-Message-State: AOJu0YwVZ0wh8RsS8KE1+ochgamxH0PCjU2yinF+2VlAnrAqShe1tzY9 QinUpin+YL74mtshDuJ1uAIuGpUzyNKrvSsvq1otySmPn/kutRWonzZYKGFEsBabiMNH8uxTT/m DwlXO5cqaTTbrr15gUlcF0yJlFPgOIYXb/nwzayroEBWPicj/RINMDbmKfiss+hIfZl+s4lOkP6 gHmuTA2Bdx1HHAByHkYKJStv6oUii8SCaQavUjAaBjZn8= X-Gm-Gg: Acq92OH3A5B/wa1kiNINgxj8hFTsbB3Hw2SQT4ZDiAfKVfqKOrnfIqPYcWOakp0IJto 4PGuUlqdwGfhxCbFbxWIe/vxxilxEGJtQvYRhy5ZClMlSMzhIuxomHGtR9AQ8W1O9Bu8TrT4q5a +I7dA8BANHVFbzFUiGfWt1cwRPo7jimrLofQ8IwW+Inxe7au5cimHUFKEAGSnwE9S3yEOaIVPOX HjdXbu3rsdQqwgVRDrWcj93FSA3lZ+PK62TOVKSn9KT+AIcjMmM+R/SSpbo3fhmxe7w5ClwpuLv jymUz5qUc0cGLRMqhhbGfNw2ODamPuz23HesWky0c3Avfco0rMnf3sP3+B9OXjuD/52+aMTAytc y/vPLjDe2geiPXsfCRk41kPmEXk3HLyUTxHMeJSBKQlRFmgI76uo= X-Received: by 2002:a17:907:1ca8:b0:bc3:783f:1da9 with SMTP id a640c23a62f3a-bc56d13123amr1190835566b.33.1778490140347; Mon, 11 May 2026 02:02:20 -0700 (PDT) X-Received: by 2002:a17:907:1ca8:b0:bc3:783f:1da9 with SMTP id a640c23a62f3a-bc56d13123amr1190817666b.33.1778490138948; Mon, 11 May 2026 02:02:18 -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 ffacd0b85a97d-4548e4bb87bsm23408179f8f.2.2026.05.11.02.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:18 -0700 (PDT) Date: Mon, 11 May 2026 05:02:12 -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 Subject: [PATCH resend v6 06/30] mm: use folio_zero_user for user pages in post_alloc_hook Message-ID: <87e7ec6a9722ebe27a837a29781547d0d210147f.1778489843.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 When post_alloc_hook() needs to zero a page for an explicit __GFP_ZERO allocation for a user page (user_addr is set), use folio_zero_user() instead of kernel_init_pages(). This zeros near the faulting address last, keeping those cachelines hot for the impending user access. folio_zero_user() is only used for explicit __GFP_ZERO, not for init_on_alloc. On architectures with virtually-indexed caches (e.g., ARM), clear_user_highpage() performs per-line cache operations; using it for init_on_alloc would add overhead that kernel_init_pages() avoids (the page fault path flushes the cache at PTE installation time regardless). No functional change yet: current callers do not pass __GFP_ZERO for user pages (they zero at the callsite instead). Subsequent patches will convert them. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f76d5271b5c6..842f5080d728 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1851,9 +1851,20 @@ inline void post_alloc_hook(struct page *page, unsigned int order, for (i = 0; i != 1 << order; ++i) page_kasan_tag_reset(page + i); } - /* If memory is still not initialized, initialize it now. */ - if (init) - kernel_init_pages(page, 1 << order); + /* + * If memory is still not initialized, initialize it now. + * When __GFP_ZERO was explicitly requested and user_addr is set, + * use folio_zero_user() which zeros near the faulting address + * last, keeping those cachelines hot. For init_on_alloc, use + * kernel_init_pages() to avoid unnecessary cache flush overhead + * on architectures with virtually-indexed caches. + */ + if (init) { + if ((gfp_flags & __GFP_ZERO) && user_addr != USER_ADDR_NONE) + folio_zero_user(page_folio(page), user_addr); + else + kernel_init_pages(page, 1 << order); + } set_page_owner(page, order, gfp_flags); page_table_check_alloc(page, order); -- MST