linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memory: move mem_cgroup_charge() into alloc_anon_folio()
@ 2024-01-16  7:13 Kefeng Wang
  2024-01-16 14:35 ` Ryan Roberts
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kefeng Wang @ 2024-01-16  7:13 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel
  Cc: ryan.roberts, Matthew Wilcox, David Hildenbrand, Kefeng Wang

In order to allocate as much as possible of large folio, move
the mem charge into alloc_anon_folio() and try the next order
if mem_cgroup_charge() fails, also we change the GFP_KERNEL
to gfp to be consistent with PMD THP.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/memory.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 5e88d5379127..2e31a407e6f9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4206,15 +4206,21 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf)
 		addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order);
 		folio = vma_alloc_folio(gfp, order, vma, addr, true);
 		if (folio) {
+			if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) {
+				folio_put(folio);
+				goto next;
+			}
+			folio_throttle_swaprate(folio, gfp);
 			clear_huge_page(&folio->page, vmf->address, 1 << order);
 			return folio;
 		}
+next:
 		order = next_order(&orders, order);
 	}
 
 fallback:
 #endif
-	return vma_alloc_zeroed_movable_folio(vmf->vma, vmf->address);
+	return folio_prealloc(vma->vm_mm, vma, vmf->address, true);
 }
 
 /*
@@ -4281,10 +4287,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
 	nr_pages = folio_nr_pages(folio);
 	addr = ALIGN_DOWN(vmf->address, nr_pages * PAGE_SIZE);
 
-	if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL))
-		goto oom_free_page;
-	folio_throttle_swaprate(folio, GFP_KERNEL);
-
 	/*
 	 * The memory barrier inside __folio_mark_uptodate makes sure that
 	 * preceding stores to the page contents become visible before
@@ -4338,8 +4340,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
 release:
 	folio_put(folio);
 	goto unlock;
-oom_free_page:
-	folio_put(folio);
 oom:
 	return VM_FAULT_OOM;
 }
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-17  1:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16  7:13 [PATCH] mm: memory: move mem_cgroup_charge() into alloc_anon_folio() Kefeng Wang
2024-01-16 14:35 ` Ryan Roberts
2024-01-16 14:51   ` Matthew Wilcox
2024-01-16 15:07     ` Ryan Roberts
2024-01-17  1:34       ` Kefeng Wang
2024-01-16 21:26 ` kernel test robot
2024-01-17  1:02   ` Kefeng Wang
2024-01-16 23:41 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).