Skip to content

Commit b58323c

Browse files
sidkumar99Sasha Levin
authored andcommitted
mm/hugetlb: add folio support to hugetlb specific flag macros
[ Upstream commit d03c376 ] Patch series "begin converting hugetlb code to folios", v4. This patch series starts the conversion of the hugetlb code to operate on struct folios rather than struct pages. This removes the ambiguitiy of whether functions are operating on head pages, tail pages of compound pages, or base pages. This series passes the linux test project hugetlb test cases. Patch 1 adds hugeltb specific page macros that can operate on folios. Patch 2 adds the private field of the first tail page to struct page. For 32-bit, _private_1 alinging with page[1].private was confirmed by using pahole. Patch 3 introduces hugetlb subpool helper functions which operate on struct folios. These patches were tested using the hugepage-mmap.c selftest along with the migratepages command. Patch 4 converts hugetlb_delete_from_page_cache() to use folios. Patch 5 adds a folio_hstate() function to get hstate information from a folio and adds a user of folio_hstate(). Bpftrace was used to track time spent in the free_huge_pages function during the ltp test cases as it is a caller of the hugetlb subpool functions. From the histogram, the performance is similar before and after the patch series. Time spent in 'free_huge_page' 6.0.0-rc2.master.20220823 @nsecs: [256, 512) 14770 |@@@@@@@@@@@@@@@@@@@@@@@@@@@ |@@@@@@@@@@@@@@@@@@@@@@@@@ | [512, 1K) 155 | | [1K, 2K) 169 | | [2K, 4K) 50 | | [4K, 8K) 14 | | [8K, 16K) 3 | | [16K, 32K) 3 | | 6.0.0-rc2.master.20220823 + patch series @nsecs: [256, 512) 13678 |@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |@@@@@@@@@@@@@@@@@@@@@@@@@ | [512, 1K) 142 | | [1K, 2K) 199 | | [2K, 4K) 44 | | [4K, 8K) 13 | | [8K, 16K) 4 | | [16K, 32K) 1 | | This patch (of 5): Allow the macros which test, set, and clear hugetlb specific page flags to take a hugetlb folio as an input. The macrros are generated as folio_{test, set, clear}_hugetlb_{restore_reserve, migratable, temporary, freed, vmemmap_optimized, raw_hwp_unreliable}. Link: https://lkml.kernel.org/r/20220922154207.1575343-1-sidhartha.kumar@oracle.com Link: https://lkml.kernel.org/r/20220922154207.1575343-2-sidhartha.kumar@oracle.com Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Colin Cross <ccross@google.com> Cc: David Howells <dhowells@redhat.com> Cc: "Eric W . Biederman" <ebiederm@xmission.com> Cc: Hugh Dickins <hughd@google.com> Cc: kernel test robot <lkp@intel.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Peter Xu <peterx@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: William Kucharski <william.kucharski@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: b76b469 ("mm/hugetlb: fix missing hugetlb_lock for resv uncharge") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f5414f8 commit b58323c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

include/linux/hugetlb.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,26 +625,50 @@ enum hugetlb_page_flags {
625625
*/
626626
#ifdef CONFIG_HUGETLB_PAGE
627627
#define TESTHPAGEFLAG(uname, flname) \
628+
static __always_inline \
629+
bool folio_test_hugetlb_##flname(struct folio *folio) \
630+
{ void *private = &folio->private; \
631+
return test_bit(HPG_##flname, private); \
632+
} \
628633
static inline int HPage##uname(struct page *page) \
629634
{ return test_bit(HPG_##flname, &(page->private)); }
630635

631636
#define SETHPAGEFLAG(uname, flname) \
637+
static __always_inline \
638+
void folio_set_hugetlb_##flname(struct folio *folio) \
639+
{ void *private = &folio->private; \
640+
set_bit(HPG_##flname, private); \
641+
} \
632642
static inline void SetHPage##uname(struct page *page) \
633643
{ set_bit(HPG_##flname, &(page->private)); }
634644

635645
#define CLEARHPAGEFLAG(uname, flname) \
646+
static __always_inline \
647+
void folio_clear_hugetlb_##flname(struct folio *folio) \
648+
{ void *private = &folio->private; \
649+
clear_bit(HPG_##flname, private); \
650+
} \
636651
static inline void ClearHPage##uname(struct page *page) \
637652
{ clear_bit(HPG_##flname, &(page->private)); }
638653
#else
639654
#define TESTHPAGEFLAG(uname, flname) \
655+
static inline bool \
656+
folio_test_hugetlb_##flname(struct folio *folio) \
657+
{ return 0; } \
640658
static inline int HPage##uname(struct page *page) \
641659
{ return 0; }
642660

643661
#define SETHPAGEFLAG(uname, flname) \
662+
static inline void \
663+
folio_set_hugetlb_##flname(struct folio *folio) \
664+
{ } \
644665
static inline void SetHPage##uname(struct page *page) \
645666
{ }
646667

647668
#define CLEARHPAGEFLAG(uname, flname) \
669+
static inline void \
670+
folio_clear_hugetlb_##flname(struct folio *folio) \
671+
{ } \
648672
static inline void ClearHPage##uname(struct page *page) \
649673
{ }
650674
#endif

0 commit comments

Comments
 (0)