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: introduce is_pmd_order helper

In order to add mTHP support to khugepaged, we will often be checking if a
given order is (or is not) a PMD order. Some places in the kernel already
use this check, so lets create a simple helper function to keep the code
clean and readable.

Link: https://lkml.kernel.org/r/20260325114022.444081-3-npache@redhat.com
Signed-off-by: Nico Pache <npache@redhat.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: Barry Song <baohua@kernel.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Rafael Aquini <raquini@redhat.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shivank Garg <shivankg@amd.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Takashi Iwai (SUSE) <tiwai@suse.de>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Usama Arif <usamaarif642@gmail.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <yang@os.amperecomputing.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Nico Pache and committed by
Andrew Morton
b90c453d a91fd9f7

+14 -10
+5
include/linux/huge_mm.h
··· 771 771 } 772 772 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 773 773 774 + static inline bool is_pmd_order(unsigned int order) 775 + { 776 + return order == HPAGE_PMD_ORDER; 777 + } 778 + 774 779 static inline int split_folio_to_list_to_order(struct folio *folio, 775 780 struct list_head *list, int new_order) 776 781 {
+1 -1
mm/huge_memory.c
··· 4159 4159 i_mmap_unlock_read(mapping); 4160 4160 out: 4161 4161 xas_destroy(&xas); 4162 - if (old_order == HPAGE_PMD_ORDER) 4162 + if (is_pmd_order(old_order)) 4163 4163 count_vm_event(!ret ? THP_SPLIT_PAGE : THP_SPLIT_PAGE_FAILED); 4164 4164 count_mthp_stat(old_order, !ret ? MTHP_STAT_SPLIT : MTHP_STAT_SPLIT_FAILED); 4165 4165 return ret;
+3 -3
mm/khugepaged.c
··· 1540 1540 if (IS_ERR(folio)) 1541 1541 return SCAN_PAGE_NULL; 1542 1542 1543 - if (folio_order(folio) != HPAGE_PMD_ORDER) { 1543 + if (!is_pmd_order(folio_order(folio))) { 1544 1544 result = SCAN_PAGE_COMPOUND; 1545 1545 goto drop_folio; 1546 1546 } ··· 2023 2023 * we locked the first folio, then a THP might be there already. 2024 2024 * This will be discovered on the first iteration. 2025 2025 */ 2026 - if (folio_order(folio) == HPAGE_PMD_ORDER) { 2026 + if (is_pmd_order(folio_order(folio))) { 2027 2027 result = SCAN_PTE_MAPPED_HUGEPAGE; 2028 2028 goto out_unlock; 2029 2029 } ··· 2351 2351 continue; 2352 2352 } 2353 2353 2354 - if (folio_order(folio) == HPAGE_PMD_ORDER) { 2354 + if (is_pmd_order(folio_order(folio))) { 2355 2355 result = SCAN_PTE_MAPPED_HUGEPAGE; 2356 2356 /* 2357 2357 * PMD-sized THP implies that we can only try
+1 -1
mm/memory.c
··· 5435 5435 if (!thp_vma_suitable_order(vma, haddr, PMD_ORDER)) 5436 5436 return ret; 5437 5437 5438 - if (folio_order(folio) != HPAGE_PMD_ORDER) 5438 + if (!is_pmd_order(folio_order(folio))) 5439 5439 return ret; 5440 5440 page = &folio->page; 5441 5441
+1 -1
mm/mempolicy.c
··· 2449 2449 2450 2450 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && 2451 2451 /* filter "hugepage" allocation, unless from alloc_pages() */ 2452 - order == HPAGE_PMD_ORDER && ilx != NO_INTERLEAVE_INDEX) { 2452 + is_pmd_order(order) && ilx != NO_INTERLEAVE_INDEX) { 2453 2453 /* 2454 2454 * For hugepage allocation and non-interleave policy which 2455 2455 * allows the current node (or other explicitly preferred
+2 -2
mm/page_alloc.c
··· 651 651 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 652 652 bool movable; 653 653 if (order > PAGE_ALLOC_COSTLY_ORDER) { 654 - VM_BUG_ON(order != HPAGE_PMD_ORDER); 654 + VM_BUG_ON(!is_pmd_order(order)); 655 655 656 656 movable = migratetype == MIGRATE_MOVABLE; 657 657 ··· 683 683 if (order <= PAGE_ALLOC_COSTLY_ORDER) 684 684 return true; 685 685 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 686 - if (order == HPAGE_PMD_ORDER) 686 + if (is_pmd_order(order)) 687 687 return true; 688 688 #endif 689 689 return false;
+1 -2
mm/shmem.c
··· 5558 5558 spin_unlock(&huge_shmem_orders_lock); 5559 5559 } else if (sysfs_streq(buf, "inherit")) { 5560 5560 /* Do not override huge allocation policy with non-PMD sized mTHP */ 5561 - if (shmem_huge == SHMEM_HUGE_FORCE && 5562 - order != HPAGE_PMD_ORDER) 5561 + if (shmem_huge == SHMEM_HUGE_FORCE && !is_pmd_order(order)) 5563 5562 return -EINVAL; 5564 5563 5565 5564 spin_lock(&huge_shmem_orders_lock);