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.133.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 090853BF66C for ; Wed, 20 May 2026 22:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315666; cv=none; b=KuJsIOPgHxd8Z4xCql1L6/0QdOH4MLPjQYsbaB/ajQPcDjzQzA8wr7C4Gjjg0pm6rFRJveVXAQV/2xtufcnKoGgfLZ3NHSyhDrn3EcNcL8UyngSej2ysfuPGpuS5YTaYBWY3uTjIaqwqR82lwiedCqUtNLB5TJ8x/NiRReqjExk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315666; c=relaxed/simple; bh=YV4jBXFQrQQpbg0jR4Mv8OiHoL2bzi28JLwzDY6BCc0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UN9kTdOoeFpRGy8xKpYHIbJAB+h1bZo2T3/rBZeJXILx76QD6/gMyh8hTc0fiMRujaozEJ9jIQsYvipbO/2MqfHgqHL0SC9yIUyiDaJ2hUUKc7UcAIeaM/JdNvZM5PWDzIAhjKBJthVg9mdwKSXob204i85sdFS24cyT3UwPK1g= 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=DkglxuUp; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MlEOHa9s; arc=none smtp.client-ip=170.10.133.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="DkglxuUp"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MlEOHa9s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315664; 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=Ri6YQ3HlLjUAH8mONUkbxIg9Wl46GlG+rJaCqygm0zg=; b=DkglxuUpa5QCWwADSGWgNKz1UUi9SClxRz4UALxthr2oeT9IbkwqcpokYpacE4nYu87MvC ka+7mHg9h3CT3+ThkkOyzXF6D9skRG6zwKGVmxrJ0LTG4nQO+2mwT1YxBMJBDRM5tnGgPY maLyptXMRi9YXJWB4G0ej6oaFh/mPJ0= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-iBIs-DH0MfaCSfWVnJdcHA-1; Wed, 20 May 2026 18:20:59 -0400 X-MC-Unique: iBIs-DH0MfaCSfWVnJdcHA-1 X-Mimecast-MFC-AGG-ID: iBIs-DH0MfaCSfWVnJdcHA_1779315658 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-393adad635dso32923331fa.3 for ; Wed, 20 May 2026 15:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315658; x=1779920458; 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=Ri6YQ3HlLjUAH8mONUkbxIg9Wl46GlG+rJaCqygm0zg=; b=MlEOHa9sAsc6B/+YqmfQpWEW4WnFSU/Yoy40oitKpB+kw5QKXfnIxOCzAozUXlY3fg Ljhi/QKCiaxz4o9L4u//SCAaitADD7V2NhUw1cR9B1nA0LhIYCDPhapS/EG+JQbNsTIw zGGWGFFxyHwSA8EcaDqTQYyFBTZJoSeNQHNnqwGPCBF5/QKOJou+x08XVepppUjSy8H2 g5WP24bGJa+RL7CvaskioWHIOyz4z8j1vBgBjFDzU13BtF/CyMijL5oZEMXHGVCHbtYF rD9+bZE5n5iurfteV5VcHQviGT9l/XGdNaBz24e1hDopaDaEypIGXgYbZl923FcvPH0+ r0yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315658; x=1779920458; 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=Ri6YQ3HlLjUAH8mONUkbxIg9Wl46GlG+rJaCqygm0zg=; b=cIB++tP+5vJXRVW8qPjstDI/Kj6f+MDTAg9ETm2WPFzR0BTaes+IfUNo2V97CIMo5r tUaEdlzT/3ZBZx4A6fLmwFSUAF7DlodXPXQL27zssJ6S5C4tsRjloC5QNMCrQJz4Ke2n JhZb8XI0Y946+b+7F8DMbe5l2l2wxoskiG/2Ipn4O1q0oSbIARyVVA5tNSsILXkxPxq5 BN7JDzhOI/ouWXAhEOr/L+Z5LiBLWmIpFczWNL70Mo0GC8A3yR/pZsY0j3JGWXTFFz5Z fr5L0xiuCwufNH4eB6a2Vw6axd8Go71au4LcXXwYMI7IWziUZQQf92cF+6FFfCZm60Dx bMLQ== X-Gm-Message-State: AOJu0YyVDZ2GFa6P/+JUxPS6ICxxuuioUpnLKRdr7kLYhvS3kFcyIWzb elwYCRbKMkhaeVvTpK6rHoLuYXNligmBoPX4PGt4shKW8ZnMu/FjoHKKZrJ20zDYh6zn2TWB3SO wAvMITk+Nf6bO2yCPxyetdCrk24K1AXAiGnkvdd4zhfthI6/QqeYoulkkkWhZX1rgvUZj0e2EXb zdTmcAhZfK5TJx8CoeK2LOArYfWd5prP3vmddTARxqn3g= X-Gm-Gg: Acq92OHwSgdvYTvVMZWJ0fema1bpI7n37UWI1xs+hRciizmWqk7uPPj7QU/3PT9l7fn PaAZTjXkRNzUVfrS2qDAGxy22N2AxEfdo6y28XtTI4OIPgy9gJvMxVhTyNekt9y6AAnZr6IrgS8 NPrpwOKIhoIGEUk0xySJYd/NDsHTKZZzvWyY9b9KlW3lOaElQinu7x8lNp9HYwdBm6XR4KBh642 F2zXmu7a/fhvun997qHC2UmEGMoNInOK6aMVxfhrC6dcV/SUGcmebRR7hEaWxrKWTKgJCzvUi7y HtviAJGxTB9eBH3rCmfW30kjevzwjuq0Fg5TPdhlSF3K0ZOtWmdODMdApa0bOFptwg2P6Ks/D3K C4TvRiEuAIehS5OS5fFXvLESf+dt2rEOy9Zro+spERGM= X-Received: by 2002:a05:651c:1512:b0:38a:45d6:c246 with SMTP id 38308e7fff4ca-395ca1dfb3emr1246721fa.8.1779315657849; Wed, 20 May 2026 15:20:57 -0700 (PDT) X-Received: by 2002:a05:651c:1512:b0:38a:45d6:c246 with SMTP id 38308e7fff4ca-395ca1dfb3emr1246201fa.8.1779315657241; Wed, 20 May 2026 15:20:57 -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 38308e7fff4ca-39588791302sm31998751fa.32.2026.05.20.15.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:20:55 -0700 (PDT) Date: Wed, 20 May 2026 18:20:48 -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 v8 06/37] mm: move vma_alloc_folio_noprof to page_alloc.c 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 Move vma_alloc_folio_noprof() from an inline in gfp.h (for !NUMA) and mempolicy.c (for NUMA) to page_alloc.c. This prepares for a subsequent patch that will thread user_addr through the allocator: having vma_alloc_folio_noprof in page_alloc.c means user_addr can be passed to the internal allocation path without changing public API signatures or duplicating plumbing in both gfp.h and mempolicy.c. The !NUMA path gains the VM_DROPPABLE -> __GFP_NOWARN check that the NUMA path already had. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/gfp.h | 9 ++------- mm/mempolicy.c | 32 -------------------------------- mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 51ef13ed756e..7ccbda35b9ad 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -318,13 +318,13 @@ static inline struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask, #define alloc_pages_node(...) alloc_hooks(alloc_pages_node_noprof(__VA_ARGS__)) +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr); #ifdef CONFIG_NUMA struct page *alloc_pages_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, struct mempolicy *mpol, pgoff_t ilx, int nid); -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_struct *vma, - unsigned long addr); #else static inline struct page *alloc_pages_noprof(gfp_t gfp_mask, unsigned int order) { @@ -339,11 +339,6 @@ static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int orde { return folio_alloc_noprof(gfp, order); } -static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, - struct vm_area_struct *vma, unsigned long addr) -{ - return folio_alloc_noprof(gfp, order); -} #endif #define alloc_pages(...) alloc_hooks(alloc_pages_noprof(__VA_ARGS__)) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b2c21ed1fd84..39e556e3d263 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2516,38 +2516,6 @@ struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, return page_rmappable_folio(page); } -/** - * vma_alloc_folio - Allocate a folio for a VMA. - * @gfp: GFP flags. - * @order: Order of the folio. - * @vma: Pointer to VMA. - * @addr: Virtual address of the allocation. Must be inside @vma. - * - * Allocate a folio for a specific address in @vma, using the appropriate - * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the - * VMA to prevent it from going away. Should be used for all allocations - * for folios that will be mapped into user space, excepting hugetlbfs, and - * excepting where direct use of folio_alloc_mpol() is more appropriate. - * - * Return: The folio on success or NULL if allocation fails. - */ -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_struct *vma, - unsigned long addr) -{ - struct mempolicy *pol; - pgoff_t ilx; - struct folio *folio; - - if (vma->vm_flags & VM_DROPPABLE) - gfp |= __GFP_NOWARN; - - pol = get_vma_policy(vma, addr, order, &ilx); - folio = folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); - mpol_cond_put(pol); - return folio; -} -EXPORT_SYMBOL(vma_alloc_folio_noprof); - struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order) { struct mempolicy *pol = &default_policy; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1192c4e47da4..0c4f4c678233 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5288,6 +5288,49 @@ struct folio *__folio_alloc_noprof(gfp_t gfp, unsigned int order, int preferred_ } EXPORT_SYMBOL(__folio_alloc_noprof); +#ifdef CONFIG_NUMA +/** + * vma_alloc_folio - Allocate a folio for a VMA. + * @gfp: GFP flags. + * @order: Order of the folio. + * @vma: Pointer to VMA. + * @addr: Virtual address of the allocation. Must be inside @vma. + * + * Allocate a folio for a specific address in @vma, using the appropriate + * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the + * VMA to prevent it from going away. Should be used for all allocations + * for folios that will be mapped into user space, excepting hugetlbfs, and + * excepting where direct use of folio_alloc_mpol() is more appropriate. + * + * Return: The folio on success or NULL if allocation fails. + */ +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + struct mempolicy *pol; + pgoff_t ilx; + struct folio *folio; + + if (vma->vm_flags & VM_DROPPABLE) + gfp |= __GFP_NOWARN; + + pol = get_vma_policy(vma, addr, order, &ilx); + folio = folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); + mpol_cond_put(pol); + return folio; +} +#else +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + if (vma->vm_flags & VM_DROPPABLE) + gfp |= __GFP_NOWARN; + + return folio_alloc_noprof(gfp, order); +} +#endif +EXPORT_SYMBOL(vma_alloc_folio_noprof); + /* * Common helper functions. Never use with __GFP_HIGHMEM because the returned * address cannot represent highmem pages. Use alloc_pages and then kmap if -- MST