mm/hugetlb: correct demote page offset logic

With gigantic pages it may not be true that struct page structures are
contiguous across the entire gigantic page.  The nth_page macro is used
here in place of direct pointer arithmetic to correct for this.

Mike said:

: This error could cause addressing exceptions.  However, this is only
: possible in configurations where CONFIG_SPARSEMEM &&
: !CONFIG_SPARSEMEM_VMEMMAP.  Such a configuration option is rare and
: unknown to be the default anywhere.

Fixes: 8531fc6f52f5 ("hugetlb: add hugetlb demote page support")
Signed-off-by: Doug Berger <>
Reviewed-by: Mike Kravetz <>
Reviewed-by: Oscar Salvador <>
Reviewed-by: Anshuman Khandual <>
Cc: Muchun Song <>
Cc: <>
Signed-off-by: Andrew Morton <>
1 file changed