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 and use has_deposited_pgtable()

Rather than thread has_deposited through zap_huge_pmd(), make things
clearer by adding has_deposited_pgtable() with comments describing why in
each case.

[ljs@kernel.org: fix folio_put()-before-recheck issue, per Sashiko]
Link: https://lkml.kernel.org/r/0a917f80-902f-49b0-a75f-1bbaf23d7f94@lucifer.local
Link: https://lkml.kernel.org/r/f9db59ca90937e39913d50ecb4f662e2bad17bbb.1774029655.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.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
bf263bca d80a9cb1

+25 -9
+25 -9
mm/huge_memory.c
··· 2403 2403 } 2404 2404 2405 2405 static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma, 2406 - pmd_t pmdval, struct folio *folio, bool is_present, 2407 - bool *has_deposit) 2406 + pmd_t pmdval, struct folio *folio, bool is_present) 2408 2407 { 2409 2408 const bool is_device_private = folio_is_device_private(folio); 2410 2409 ··· 2412 2413 folio_remove_rmap_pmd(folio, &folio->page, vma); 2413 2414 2414 2415 if (folio_test_anon(folio)) { 2415 - *has_deposit = true; 2416 2416 add_mm_counter(mm, MM_ANONPAGES, -HPAGE_PMD_NR); 2417 2417 } else { 2418 2418 add_mm_counter(mm, mm_counter_file(folio), ··· 2438 2440 return pmd_to_softleaf_folio(pmdval); 2439 2441 } 2440 2442 2443 + static bool has_deposited_pgtable(struct vm_area_struct *vma, pmd_t pmdval, 2444 + struct folio *folio) 2445 + { 2446 + /* Some architectures require unconditional depositing. */ 2447 + if (arch_needs_pgtable_deposit()) 2448 + return true; 2449 + 2450 + /* 2451 + * Huge zero always deposited except for DAX which handles itself, see 2452 + * set_huge_zero_folio(). 2453 + */ 2454 + if (is_huge_zero_pmd(pmdval)) 2455 + return !vma_is_dax(vma); 2456 + 2457 + /* 2458 + * Otherwise, only anonymous folios are deposited, see 2459 + * __do_huge_pmd_anonymous_page(). 2460 + */ 2461 + return folio && folio_test_anon(folio); 2462 + } 2463 + 2441 2464 /** 2442 2465 * zap_huge_pmd - Zap a huge THP which is of PMD size. 2443 2466 * @tlb: The MMU gather TLB state associated with the operation. ··· 2471 2452 bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, 2472 2453 pmd_t *pmd, unsigned long addr) 2473 2454 { 2474 - bool has_deposit = arch_needs_pgtable_deposit(); 2475 2455 struct mm_struct *mm = tlb->mm; 2476 2456 struct folio *folio = NULL; 2477 2457 bool is_present = false; 2458 + bool has_deposit; 2478 2459 spinlock_t *ptl; 2479 2460 pmd_t orig_pmd; 2480 2461 ··· 2496 2477 2497 2478 is_present = pmd_present(orig_pmd); 2498 2479 folio = normal_or_softleaf_folio_pmd(vma, addr, orig_pmd, is_present); 2480 + has_deposit = has_deposited_pgtable(vma, orig_pmd, folio); 2499 2481 if (folio) 2500 - zap_huge_pmd_folio(mm, vma, orig_pmd, folio, is_present, 2501 - &has_deposit); 2502 - else if (is_huge_zero_pmd(orig_pmd)) 2503 - has_deposit = has_deposit || !vma_is_dax(vma); 2504 - 2482 + zap_huge_pmd_folio(mm, vma, orig_pmd, folio, is_present); 2505 2483 if (has_deposit) 2506 2484 zap_deposited_table(mm, pmd); 2507 2485