Skip to content

Commit cd39d4e

Browse files
Muchun Songtorvalds
authored andcommitted
mm: hugetlb: gather discrete indexes of tail page
For HugeTLB page, there are more metadata to save in the struct page. But the head struct page cannot meet our needs, so we have to abuse other tail struct page to store the metadata. In order to avoid conflicts caused by subsequent use of more tail struct pages, we can gather these discrete indexes of tail struct page. In this case, it will be easier to add a new tail page index later. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muchun Song <[email protected]> Reviewed-by: Oscar Salvador <[email protected]> Reviewed-by: Miaohe Lin <[email protected]> Tested-by: Chen Huang <[email protected]> Tested-by: Bodeddula Balasubramaniam <[email protected]> Acked-by: Michal Hocko <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: Balbir Singh <[email protected]> Cc: Barry Song <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: HORIGUCHI NAOYA <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Joao Martins <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mina Almasry <[email protected]> Cc: Oliver Neukum <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Pawan Gupta <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Xiongchun Duan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6be24be commit cd39d4e

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

include/linux/hugetlb.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ typedef struct { unsigned long pd; } hugepd_t;
2929
#include <linux/shm.h>
3030
#include <asm/tlbflush.h>
3131

32+
/*
33+
* For HugeTLB page, there are more metadata to save in the struct page. But
34+
* the head struct page cannot meet our needs, so we have to abuse other tail
35+
* struct page to store the metadata. In order to avoid conflicts caused by
36+
* subsequent use of more tail struct pages, we gather these discrete indexes
37+
* of tail struct page here.
38+
*/
39+
enum {
40+
SUBPAGE_INDEX_SUBPOOL = 1, /* reuse page->private */
41+
#ifdef CONFIG_CGROUP_HUGETLB
42+
SUBPAGE_INDEX_CGROUP, /* reuse page->private */
43+
SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */
44+
__MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD,
45+
#endif
46+
__NR_USED_SUBPAGE,
47+
};
48+
3249
struct hugepage_subpool {
3350
spinlock_t lock;
3451
long count;
@@ -635,13 +652,13 @@ extern unsigned int default_hstate_idx;
635652
*/
636653
static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
637654
{
638-
return (struct hugepage_subpool *)(hpage+1)->private;
655+
return (void *)page_private(hpage + SUBPAGE_INDEX_SUBPOOL);
639656
}
640657

641658
static inline void hugetlb_set_page_subpool(struct page *hpage,
642659
struct hugepage_subpool *subpool)
643660
{
644-
set_page_private(hpage+1, (unsigned long)subpool);
661+
set_page_private(hpage + SUBPAGE_INDEX_SUBPOOL, (unsigned long)subpool);
645662
}
646663

647664
static inline struct hstate *hstate_file(struct file *f)

include/linux/hugetlb_cgroup.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ struct hugetlb_cgroup;
2121
struct resv_map;
2222
struct file_region;
2323

24+
#ifdef CONFIG_CGROUP_HUGETLB
2425
/*
2526
* Minimum page order trackable by hugetlb cgroup.
2627
* At least 4 pages are necessary for all the tracking information.
27-
* The second tail page (hpage[2]) is the fault usage cgroup.
28-
* The third tail page (hpage[3]) is the reservation usage cgroup.
28+
* The second tail page (hpage[SUBPAGE_INDEX_CGROUP]) is the fault
29+
* usage cgroup. The third tail page (hpage[SUBPAGE_INDEX_CGROUP_RSVD])
30+
* is the reservation usage cgroup.
2931
*/
30-
#define HUGETLB_CGROUP_MIN_ORDER 2
32+
#define HUGETLB_CGROUP_MIN_ORDER order_base_2(__MAX_CGROUP_SUBPAGE_INDEX + 1)
3133

32-
#ifdef CONFIG_CGROUP_HUGETLB
3334
enum hugetlb_memory_event {
3435
HUGETLB_MAX,
3536
HUGETLB_NR_MEMORY_EVENTS,
@@ -66,9 +67,9 @@ __hugetlb_cgroup_from_page(struct page *page, bool rsvd)
6667
if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
6768
return NULL;
6869
if (rsvd)
69-
return (struct hugetlb_cgroup *)page[3].private;
70+
return (void *)page_private(page + SUBPAGE_INDEX_CGROUP_RSVD);
7071
else
71-
return (struct hugetlb_cgroup *)page[2].private;
72+
return (void *)page_private(page + SUBPAGE_INDEX_CGROUP);
7273
}
7374

7475
static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
@@ -90,9 +91,11 @@ static inline int __set_hugetlb_cgroup(struct page *page,
9091
if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
9192
return -1;
9293
if (rsvd)
93-
page[3].private = (unsigned long)h_cg;
94+
set_page_private(page + SUBPAGE_INDEX_CGROUP_RSVD,
95+
(unsigned long)h_cg);
9496
else
95-
page[2].private = (unsigned long)h_cg;
97+
set_page_private(page + SUBPAGE_INDEX_CGROUP,
98+
(unsigned long)h_cg);
9699
return 0;
97100
}
98101

0 commit comments

Comments
 (0)