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 DD8563BAD80 for ; Mon, 11 May 2026 08:53:23 +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=1778489605; cv=none; b=ojKQfAl8cTqcA8wR2NxP2Zc1oswfk6UwI7NDR8ePi4QVD+FjsSUQXYyT+XFWmKXBCKSkHrY7N+POuM4jbTggQk2dm/qH7QqKjxj7uWph99+6bW+k6c67i6B8ra6UYd571TDHSSx/s6p/wp6vg4hqPrWk1sS3OJHPpSPUYvUQUBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778489605; 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=deEqFL5rKdILoxe8hg2H3o4uvY2JwQV0c/owuaa0aEFtidjA7t/0+J3dfxFQW1VAvXsVrjn56btLnz92ju6aPjuieYpCjFXnBULdCG54RC21Itp4mb0Sw9vHKWgNiHrbCPFP+Ib1rxZUOp6ti2OJmWAhCJnZP1v79OZiUZR4JMs= 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=QhjGNbLe; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=GF2BHTri; 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="QhjGNbLe"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="GF2BHTri" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778489603; 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=QhjGNbLegGDcqP2Wmh0hav3l4C1JKpp7vsQ/DDddoow6paqaykL3JVoo8kfbiBi59qJnaa AclpgvF4VjRcBqbyqSasGnGjB3KywAKb3jsMe/cMLqDEfQMdDBcnfSSSW4JK1HRnYqEBXW 7WJ5LQ+bu2302vsXLW6Mxm5uodaG7t8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-R5rQzk5cNuWc1d8PVFgInw-1; Mon, 11 May 2026 04:53:20 -0400 X-MC-Unique: R5rQzk5cNuWc1d8PVFgInw-1 X-Mimecast-MFC-AGG-ID: R5rQzk5cNuWc1d8PVFgInw_1778489600 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488d8deb75fso29934285e9.3 for ; Mon, 11 May 2026 01:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778489599; x=1779094399; 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=GF2BHTriEfMA4mK7+QIiue1pSZChdktpDgMGhI2fA9aOX+swOR+LZokhzKferOLG7L NggJfS/Z+izrgna2U3VbSVh3PhOWE0IgVEhg0RAiH1ZgyKEYf+vIzwLzeRitpgiW/v7a LMlRf4J2vHjaPTQUFIZT1Ij5xD8qKunD59plwgCk8ATJuX+6lSEtT95E64nny083GTJR g6sKuAwKnh3+in0x+Mjq1EndCudPIhzq7yliQFQ5nzlA/QrUx/Zp56LTCuz8c9dXwNCV 4eio3FIXl91WE4TNgi+HgolOAwK2GypfpJBciyhc1X16XPi129cBT8nrg5inuNfjzGRc 4WBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778489599; x=1779094399; 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=SHqbNvqzBbxO8mmlec/Zumo13ZCCVzVNGSrLK8rKcFyZ9IatfAlKYCmMQAomEM22Lz PM7Qtc34G0/e99+EIN0bmY74hmUHO8gO1jyhH/imm6vAJX70bowNEb2iMnT565NHyTq1 n3sCgtzBORwZccezzm8R3aDaeAkFjsC2jgKqQgeut4l7xg95si+pDG2h5MI5frYxgJ0r EhgSXaIFa8CCjwqHNVvNeQGQTuyqc5wHqg2rHF24C/YOk7lUjEBRUD8s7GNOPYD1A+H1 Ai7oe1lz6KKhtjfRtILnVzXn5hD9+KVfEOTwyL2OHpH82bFuazd0WHQW3xRePcf2ySSo XfQA== X-Gm-Message-State: AOJu0YxlkhOGkLfLCi1fGy11GEhuVULhhp5pFuv9TOc7Enfbptp0lMb0 hWGFttzbkAMKlEtsSQp6EwIv3CEIHX5Ht0g/u8yMg6ztYKVYZqU0hNvLqvCrx2lK139VM3b8XYN 4z2CRB97emxfO3WNwVjVS8OTDnmVraEZQPhYWtFLq/nh0mSx82Buw6CVuOx+XXpIteu8vLPn5QS vovpLLYgKXbf1C+FmdjNE/f6nLea9Rq/CunX5SjNZjpLmRuA== X-Gm-Gg: Acq92OFjRgN36/ri+JGa8L+2H98p1jKiBFa5S7OqM8oNE/aILVIca3VXbdc93x8tvuA sS/IaSNxIK3oxfhaDEnHav3yyuyC4YHAN/KcoEXtpxTmFj+EN8sgVx/1JHHDE6ZsvFQoPo0uNpz zGLlQ6ErGoYaX6VAKY+vSIuEzJQeTYkdOfVjE+5o36/+jJ7/mweUGebBTYrqYnLaU5TPU3Wroq4 6hVJhtyvdtr5lGAzjW66vFtH3ySiL/BVd5oiFNw+SDmovpqMm41BESHdUnTHregt0MiRtg7lFU4 oGUKSfvsauoAavMK++x1LNcWLNjIiel0vCqUuYPTkAE417WW9YzlBuL5niJcjVRXUUkokmNM0zy abTpFQO8qrL8tk/Ws1cRmqReBg0OHU9Az0UMK3qu4+ymzMv0NYa4= X-Received: by 2002:a05:600c:46d2:b0:485:364e:9328 with SMTP id 5b1f17b1804b1-48e51f32aebmr334680515e9.16.1778489599204; Mon, 11 May 2026 01:53:19 -0700 (PDT) X-Received: by 2002:a05:600c:46d2:b0:485:364e:9328 with SMTP id 5b1f17b1804b1-48e51f32aebmr334679535e9.16.1778489598330; Mon, 11 May 2026 01:53: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 5b1f17b1804b1-48e702e5516sm263733725e9.7.2026.05.11.01.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 01:53:17 -0700 (PDT) Date: Mon, 11 May 2026 04:53:13 -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 v6 06/30] mm: use folio_zero_user for user pages in post_alloc_hook Message-ID: <87e7ec6a9722ebe27a837a29781547d0d210147f.1778488966.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