]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: memory: flatten alloc_anon_folio() retry loop
authorJohannes Weiner <hannes@cmpxchg.org>
Wed, 27 May 2026 20:45:15 +0000 (16:45 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 9 Jun 2026 01:21:25 +0000 (18:21 -0700)
alloc_anon_folio() uses a top-level if (folio) that buries the success
path four levels deep.  This makes for awkward long lines and wrapping.
The next patch will add more code here, so flatten this now to keep things
clean and simple.

The next label is already there, use it for !folio.

No functional change intended.

Link: https://lore.kernel.org/20260527204757.2544958-9-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Usama Arif <usama.arif@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nico Pache <npache@redhat.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memory.c

index 5a365492a9a2e7cb2ac63bc1dfec7376058c76f5..1d8e09d9b3c931a57b82b8199bbdd54ff3aebf09 100644 (file)
@@ -5215,24 +5215,24 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf)
        while (orders) {
                addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order);
                folio = vma_alloc_folio(gfp, order, vma, addr);
-               if (folio) {
-                       if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) {
-                               count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE);
-                               folio_put(folio);
-                               goto next;
-                       }
-                       folio_throttle_swaprate(folio, gfp);
-                       /*
-                        * When a folio is not zeroed during allocation
-                        * (__GFP_ZERO not used) or user folios require special
-                        * handling, folio_zero_user() is used to make sure
-                        * that the page corresponding to the faulting address
-                        * will be hot in the cache after zeroing.
-                        */
-                       if (user_alloc_needs_zeroing())
-                               folio_zero_user(folio, vmf->address);
-                       return folio;
+               if (!folio)
+                       goto next;
+               if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) {
+                       count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE);
+                       folio_put(folio);
+                       goto next;
                }
+               folio_throttle_swaprate(folio, gfp);
+               /*
+                * When a folio is not zeroed during allocation
+                * (__GFP_ZERO not used) or user folios require special
+                * handling, folio_zero_user() is used to make sure
+                * that the page corresponding to the faulting address
+                * will be hot in the cache after zeroing.
+                */
+               if (user_alloc_needs_zeroing())
+                       folio_zero_user(folio, vmf->address);
+               return folio;
 next:
                count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK);
                order = next_order(&orders, order);