Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/huge_memory: add a common exit path to zap_huge_pmd()

Other than when we acquire the PTL, we always need to unlock the PTL, and
optionally need to flush on exit.

The code is currently very duplicated in this respect, so default
flush_needed to false, set it true in the case in which it's required,
then share the same logic for all exit paths.

This also makes flush_needed make more sense as a function-scope value (we
don't need to flush for the PFN map/mixed map, zero huge, error cases for
instance).

Link: https://lkml.kernel.org/r/6b281d8ed972dff0e89bdcbdd810c96c7ae8c9dc.1774029655.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nico Pache <npache@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
7217744e 70111406

+6 -9
+6 -9
mm/huge_memory.c
··· 2415 2415 pmd_t *pmd, unsigned long addr) 2416 2416 { 2417 2417 struct folio *folio = NULL; 2418 - bool flush_needed = true; 2418 + bool flush_needed = false; 2419 2419 spinlock_t *ptl; 2420 2420 pmd_t orig_pmd; 2421 2421 ··· 2437 2437 if (vma_is_special_huge(vma)) { 2438 2438 if (arch_needs_pgtable_deposit()) 2439 2439 zap_deposited_table(tlb->mm, pmd); 2440 - spin_unlock(ptl); 2441 - return true; 2440 + goto out; 2442 2441 } 2443 2442 if (is_huge_zero_pmd(orig_pmd)) { 2444 2443 if (!vma_is_dax(vma) || arch_needs_pgtable_deposit()) 2445 2444 zap_deposited_table(tlb->mm, pmd); 2446 - spin_unlock(ptl); 2447 - return true; 2445 + goto out; 2448 2446 } 2449 2447 2450 2448 if (pmd_present(orig_pmd)) { 2451 2449 struct page *page = pmd_page(orig_pmd); 2452 2450 2451 + flush_needed = true; 2453 2452 folio = page_folio(page); 2454 2453 folio_remove_rmap_pmd(folio, page, vma); 2455 2454 WARN_ON_ONCE(folio_mapcount(folio) < 0); ··· 2457 2458 const softleaf_t entry = softleaf_from_pmd(orig_pmd); 2458 2459 2459 2460 folio = softleaf_to_folio(entry); 2460 - flush_needed = false; 2461 2461 2462 2462 if (!thp_migration_supported()) 2463 2463 WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); 2464 2464 } else { 2465 2465 WARN_ON_ONCE(true); 2466 - spin_unlock(ptl); 2467 - return true; 2466 + goto out; 2468 2467 } 2469 2468 2470 2469 if (folio_test_anon(folio)) { ··· 2489 2492 folio_put(folio); 2490 2493 } 2491 2494 2495 + out: 2492 2496 spin_unlock(ptl); 2493 2497 if (flush_needed) 2494 2498 tlb_remove_page_size(tlb, &folio->page, HPAGE_PMD_SIZE); 2495 - 2496 2499 return true; 2497 2500 } 2498 2501