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 A5D803B19BC for ; Mon, 8 Jun 2026 08:35:21 +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=1780907727; cv=none; b=qX2hDV63FijWBx4XhXIvLnD2z5gm5d4LB3eoYwkkKgyuP1De3JrgYR5qDm1B4LBMl57wKwJxAx+ByoolCB7cpLFpTHA0cb24z/U3HKOUqzShoFGPlfwxqO1vvBCeb86dfVENpY2D/95S4Qszg7+oEwaynat4NjVzAAj310qKo14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907727; c=relaxed/simple; bh=WqVTVeEY5sjLY71Wx43CJrvkZxe/1qqCM34phrgRwA4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fNyba5WA6U7cCujjCCUA29VLwO1//1RnJyW7FL4vIpWPWlnhCXWq/H4gz5W6/lrTv+J7QLnw55lzd3Vu0b7S9o20Bbvz6xj4fo93amhM54mnqKz0++9fs6TxLMz56N8Enct5qhfVseOpiZb7ZS+4XwINBCzRcaEpoFExvzyuvL0= 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=HGRFKGFA; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=t1JKegBe; 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="HGRFKGFA"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="t1JKegBe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907720; 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=QTsyEmHKpfx3QY2xerCkWdwHjor0zxZF5cs8sc/X2mI=; b=HGRFKGFApOfq18NwQKmtYNxiBhOw8LdW+qFXo6OnpwQTfwaK1gjhjMEw/OlpT0twdhnAf3 0nlcbzBrQs2xYhsmpng9/Mwg4ca3t/BOrftwsRJHJtFfrkJ3KDMVcbxWUdojRq7YpWrOXs fkc4+lO/Po4M+7dyoumIh4LyJc16QFo= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-xr4kFDYxOpKc1BNPlM_UYQ-1; Mon, 08 Jun 2026 04:35:19 -0400 X-MC-Unique: xr4kFDYxOpKc1BNPlM_UYQ-1 X-Mimecast-MFC-AGG-ID: xr4kFDYxOpKc1BNPlM_UYQ_1780907718 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490a767b782so32495355e9.2 for ; Mon, 08 Jun 2026 01:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907718; x=1781512518; 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=QTsyEmHKpfx3QY2xerCkWdwHjor0zxZF5cs8sc/X2mI=; b=t1JKegBe+ebRICH45pTeO42HMLB40kPtX2a+N+ZS+wmGfdGD/S2xEwDZnkAA61ofew VrRtu01qOT0BJUOtgEQgLjBnC0teddePzF/AarFpPNU/oIHb+zt+iBHwLTB65quft9wU HO1ESw71c2iYLN6RWHHtaeHGozvZfPICOYQTlfOTEJ+7yHTcy5Z4Av9UfOxRafrhgiqj 4V52J7M8+KrjYxDHRffJXTToc/HNVLcWO86rjQBSh/f58x/hd6On/pJHd1iehnCOGl0a UI8caLQSIcbkKZOpZ2q/0Nhece5nZZReCquTDI8c3hgacomERafKQekPcSEQD3eqCJiz OYbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907718; x=1781512518; 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=QTsyEmHKpfx3QY2xerCkWdwHjor0zxZF5cs8sc/X2mI=; b=fTpAcNzOqzGQg8CLqzdnwe5jaSrrakV8Jf8gtculDe18hxcieDWhEkkz4pQQY59rUn 7nc0tXuUhHSZroIeQ+s4FyBg8jhWPPMbvFqHOXkJiJ7XMI0F6VK/1kMJaZwAfPEHwNTn CbgCrUYw9jW82UKQflWO40Dopqu+Ja/AWwfjIQBj5+wbN1ULmB/8t1fqUh02ErKdLnDH wJg7MGJ2oOXx3itNghxL33kmimmFxoML2dO5lXgcBLCb4UTTUVVB8d0X6F6mfhp99sOq 27kSn7LO+ka2zqRvNcR2RhRbPTbDQBLF7lfF4ApF7TrUG3AVvl1qkmcjxjRLC2ZJs9a7 ZP/w== X-Gm-Message-State: AOJu0Yy2Aif3Y92AifYH2YVfpmWiJHg6/cvDRYx7DldwAfi2c1Nlsh7b 21hd/sy7vhc1ApGpXTdOSZbtWb3eb3XmOhDcfTpBRYeje4ZCHdZZZm6IOuttHurNqlb3M6O0/n+ ac/WTzHxcI/ZRlGIq4EL6nIan0rJUvXT0PJ4SuzMTLQtkFEv7xX0xCsbuHwLnJTD7fanapk82Pa P8u7DHaaOT05Q5LtgCTdqVTQfYVIPiGuwow4qiMZ/r/78= X-Gm-Gg: Acq92OEBvzJhhZZhrfwGhOapDAUiQDikICPqUT/iSAYUCTa4vfHpABcfNMMq+eEEv87 eeC3A4wFHP6vNWM4XHSAWnjR4UmuIEKhQb8Oz773mO41gjNGZFE7mpRqltjFXbpeHtetU6kn+T+ 6yYt7EGDl2+pNmA0ognBFgq+/qS5LxbLMdqlo9VcfZMuYrM6HGojcdOkqtwHCmZnkOyik2Zuswp +1DFmAWmGh/V0fcJF/GffykDiuC8ljdt1F2jSWfz0dTn8CIHHEMT9eEElapS8MILWBpFDneBeDe kW+DwdGrhF+uHejTkUTiYNGzwF4ChF+JQvVXcZluAJoicG1W4uvceEGC7JgQceWpCTzPIP+2nMJ 4saOoABny3hURLVot/Xc06Dg= X-Received: by 2002:a05:600c:19d3:b0:490:48df:2793 with SMTP id 5b1f17b1804b1-490c25fa410mr242691395e9.26.1780907718085; Mon, 08 Jun 2026 01:35:18 -0700 (PDT) X-Received: by 2002:a05:600c:19d3:b0:490:48df:2793 with SMTP id 5b1f17b1804b1-490c25fa410mr242690165e9.26.1780907717394; Mon, 08 Jun 2026 01:35:17 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490c2d37edbsm282225125e9.2.2026.06.08.01.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:35:16 -0700 (PDT) Date: Mon, 8 Jun 2026 04:35:05 -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 v10 06/37] mm: move vma_alloc_folio_noprof to page_alloc.c Message-ID: <5a3034dc7b3d5ea1edcc8b9baff63c980b7ae434.1780906288.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.51.2.2891.g4157995a80.dirty 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 d139b074a599..a1707ad498a8 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 8dae5b3f5876..6a605d05e8cd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5286,6 +5286,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