Skip to content

Commit 4eeec8c

Browse files
davidhildenbrandakpm00
authored andcommitted
mm: move hugetlb specific things in folio to page[3]
Let's just move the hugetlb specific stuff to a separate page, and stop letting it overlay other fields for now. This frees up some space in page[2], which we will use on 32bit to free up some space in page[1]. While we could move these things to page[3] instead, it's cleaner to just move the hugetlb specific things out of the way and pack the core-folio stuff as tight as possible. ... and we can minimize the work required in dump_folio. We can now avoid re-initializing &folio->_deferred_list in hugetlb code. Hopefully dynamically allocating "strut folio" in the future will further clean this up. Link: https://lkml.kernel.org/r/20250303163014.1128035-5-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Cc: Andy Lutomirks^H^Hski <luto@kernel.org> Cc: Borislav Betkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Lance Yang <ioworker0@gmail.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: Michal Koutn <mkoutny@suse.com> Cc: Muchun Song <muchun.song@linux.dev> Cc: tejun heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Zefan Li <lizefan.x@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4996fc5 commit 4eeec8c

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

include/linux/mm_types.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,23 @@ struct folio {
407407
unsigned long _flags_2;
408408
unsigned long _head_2;
409409
/* public: */
410-
void *_hugetlb_subpool;
411-
void *_hugetlb_cgroup;
412-
void *_hugetlb_cgroup_rsvd;
413-
void *_hugetlb_hwpoison;
410+
struct list_head _deferred_list;
414411
/* private: the union with struct page is transitional */
415412
};
413+
struct page __page_2;
414+
};
415+
union {
416416
struct {
417-
unsigned long _flags_2a;
418-
unsigned long _head_2a;
417+
unsigned long _flags_3;
418+
unsigned long _head_3;
419419
/* public: */
420-
struct list_head _deferred_list;
420+
void *_hugetlb_subpool;
421+
void *_hugetlb_cgroup;
422+
void *_hugetlb_cgroup_rsvd;
423+
void *_hugetlb_hwpoison;
421424
/* private: the union with struct page is transitional */
422425
};
423-
struct page __page_2;
426+
struct page __page_3;
424427
};
425428
};
426429

@@ -457,8 +460,12 @@ FOLIO_MATCH(_refcount, _refcount_1);
457460
offsetof(struct page, pg) + 2 * sizeof(struct page))
458461
FOLIO_MATCH(flags, _flags_2);
459462
FOLIO_MATCH(compound_head, _head_2);
460-
FOLIO_MATCH(flags, _flags_2a);
461-
FOLIO_MATCH(compound_head, _head_2a);
463+
#undef FOLIO_MATCH
464+
#define FOLIO_MATCH(pg, fl) \
465+
static_assert(offsetof(struct folio, fl) == \
466+
offsetof(struct page, pg) + 3 * sizeof(struct page))
467+
FOLIO_MATCH(flags, _flags_3);
468+
FOLIO_MATCH(compound_head, _head_3);
462469
#undef FOLIO_MATCH
463470

464471
/**

mm/hugetlb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,6 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
16491649

16501650
folio_ref_unfreeze(folio, 1);
16511651

1652-
INIT_LIST_HEAD(&folio->_deferred_list);
16531652
hugetlb_free_folio(folio);
16541653
}
16551654

mm/page_alloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,11 @@ static int free_tail_page_prepare(struct page *head_page, struct page *page)
971971
goto out;
972972
}
973973
break;
974+
case 3:
975+
/* the third tail page: hugetlb specifics overlap ->mappings */
976+
if (IS_ENABLED(CONFIG_HUGETLB_PAGE))
977+
break;
978+
fallthrough;
974979
default:
975980
if (page->mapping != TAIL_MAPPING) {
976981
bad_page(page, "corrupted mapping in tail page");

0 commit comments

Comments
 (0)