Skip to content

Commit

Permalink
hugetlb: add an inline helper for finding hstate index
Browse files Browse the repository at this point in the history
Add an inline helper and use it in the code.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Hillf Danton <dhillf@gmail.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
kvaneesh authored and torvalds committed Aug 1, 2012
1 parent 76dcee7 commit 972dc4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions include/linux/hugetlb.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ static inline unsigned hstate_index_to_shift(unsigned index)
return hstates[index].order + PAGE_SHIFT;
}

static inline int hstate_index(struct hstate *h)
{
return h - hstates;
}

#else
struct hstate {};
#define alloc_huge_page_node(h, nid) NULL
Expand All @@ -320,6 +325,7 @@ static inline unsigned int pages_per_huge_page(struct hstate *h)
return 1;
}
#define hstate_index_to_shift(index) 0
#define hstate_index(h) 0
#endif

#endif /* _LINUX_HUGETLB_H */
20 changes: 11 additions & 9 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
struct attribute_group *hstate_attr_group)
{
int retval;
int hi = h - hstates;
int hi = hstate_index(h);

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

for_each_hstate(h)
if (nhs->hstate_kobjs[h - hstates]) {
kobject_put(nhs->hstate_kobjs[h - hstates]);
nhs->hstate_kobjs[h - hstates] = NULL;
for_each_hstate(h) {
int idx = hstate_index(h);
if (nhs->hstate_kobjs[idx]) {
kobject_put(nhs->hstate_kobjs[idx]);
nhs->hstate_kobjs[idx] = NULL;
}
}

kobject_put(nhs->hugepages_kobj);
nhs->hugepages_kobj = NULL;
Expand Down Expand Up @@ -1848,7 +1850,7 @@ static void __exit hugetlb_exit(void)
hugetlb_unregister_all_nodes();

for_each_hstate(h) {
kobject_put(hstate_kobjs[h - hstates]);
kobject_put(hstate_kobjs[hstate_index(h)]);
}

kobject_put(hugepages_kobj);
Expand All @@ -1869,7 +1871,7 @@ static int __init hugetlb_init(void)
if (!size_to_hstate(default_hstate_size))
hugetlb_add_hstate(HUGETLB_PAGE_ORDER);
}
default_hstate_idx = size_to_hstate(default_hstate_size) - hstates;
default_hstate_idx = hstate_index(size_to_hstate(default_hstate_size));
if (default_hstate_max_huge_pages)
default_hstate.max_huge_pages = default_hstate_max_huge_pages;

Expand Down Expand Up @@ -2687,7 +2689,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
*/
if (unlikely(PageHWPoison(page))) {
ret = VM_FAULT_HWPOISON |
VM_FAULT_SET_HINDEX(h - hstates);
VM_FAULT_SET_HINDEX(hstate_index(h));
goto backout_unlocked;
}
}
Expand Down Expand Up @@ -2760,7 +2762,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
return 0;
} else if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
return VM_FAULT_HWPOISON_LARGE |
VM_FAULT_SET_HINDEX(h - hstates);
VM_FAULT_SET_HINDEX(hstate_index(h));
}

ptep = huge_pte_alloc(mm, address, huge_page_size(h));
Expand Down

0 comments on commit 972dc4d

Please sign in to comment.