Skip to content

Commit 972dc4d

Browse files
kvaneeshtorvalds
authored andcommitted
hugetlb: add an inline helper for finding hstate index
Add an inline helper and use it in the code. Signed-off-by: Aneesh Kumar K.V <[email protected]> Acked-by: David Rientjes <[email protected]> Acked-by: Michal Hocko <[email protected]> Reviewed-by: KAMEZAWA Hiroyuki <[email protected]> Cc: Hillf Danton <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 76dcee7 commit 972dc4d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

include/linux/hugetlb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ static inline unsigned hstate_index_to_shift(unsigned index)
302302
return hstates[index].order + PAGE_SHIFT;
303303
}
304304

305+
static inline int hstate_index(struct hstate *h)
306+
{
307+
return h - hstates;
308+
}
309+
305310
#else
306311
struct hstate {};
307312
#define alloc_huge_page_node(h, nid) NULL
@@ -320,6 +325,7 @@ static inline unsigned int pages_per_huge_page(struct hstate *h)
320325
return 1;
321326
}
322327
#define hstate_index_to_shift(index) 0
328+
#define hstate_index(h) 0
323329
#endif
324330

325331
#endif /* _LINUX_HUGETLB_H */

mm/hugetlb.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
16461646
struct attribute_group *hstate_attr_group)
16471647
{
16481648
int retval;
1649-
int hi = h - hstates;
1649+
int hi = hstate_index(h);
16501650

16511651
hstate_kobjs[hi] = kobject_create_and_add(h->name, parent);
16521652
if (!hstate_kobjs[hi])
@@ -1741,11 +1741,13 @@ void hugetlb_unregister_node(struct node *node)
17411741
if (!nhs->hugepages_kobj)
17421742
return; /* no hstate attributes */
17431743

1744-
for_each_hstate(h)
1745-
if (nhs->hstate_kobjs[h - hstates]) {
1746-
kobject_put(nhs->hstate_kobjs[h - hstates]);
1747-
nhs->hstate_kobjs[h - hstates] = NULL;
1744+
for_each_hstate(h) {
1745+
int idx = hstate_index(h);
1746+
if (nhs->hstate_kobjs[idx]) {
1747+
kobject_put(nhs->hstate_kobjs[idx]);
1748+
nhs->hstate_kobjs[idx] = NULL;
17481749
}
1750+
}
17491751

17501752
kobject_put(nhs->hugepages_kobj);
17511753
nhs->hugepages_kobj = NULL;
@@ -1848,7 +1850,7 @@ static void __exit hugetlb_exit(void)
18481850
hugetlb_unregister_all_nodes();
18491851

18501852
for_each_hstate(h) {
1851-
kobject_put(hstate_kobjs[h - hstates]);
1853+
kobject_put(hstate_kobjs[hstate_index(h)]);
18521854
}
18531855

18541856
kobject_put(hugepages_kobj);
@@ -1869,7 +1871,7 @@ static int __init hugetlb_init(void)
18691871
if (!size_to_hstate(default_hstate_size))
18701872
hugetlb_add_hstate(HUGETLB_PAGE_ORDER);
18711873
}
1872-
default_hstate_idx = size_to_hstate(default_hstate_size) - hstates;
1874+
default_hstate_idx = hstate_index(size_to_hstate(default_hstate_size));
18731875
if (default_hstate_max_huge_pages)
18741876
default_hstate.max_huge_pages = default_hstate_max_huge_pages;
18751877

@@ -2687,7 +2689,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
26872689
*/
26882690
if (unlikely(PageHWPoison(page))) {
26892691
ret = VM_FAULT_HWPOISON |
2690-
VM_FAULT_SET_HINDEX(h - hstates);
2692+
VM_FAULT_SET_HINDEX(hstate_index(h));
26912693
goto backout_unlocked;
26922694
}
26932695
}
@@ -2760,7 +2762,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
27602762
return 0;
27612763
} else if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
27622764
return VM_FAULT_HWPOISON_LARGE |
2763-
VM_FAULT_SET_HINDEX(h - hstates);
2765+
VM_FAULT_SET_HINDEX(hstate_index(h));
27642766
}
27652767

27662768
ptep = huge_pte_alloc(mm, address, huge_page_size(h));

0 commit comments

Comments
 (0)