asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()

For most architectures that support >2 levels of page tables,
pmd_alloc_one() is a wrapper for __get_free_pages(), sometimes with
__GFP_ZERO and sometimes followed by memset(0) instead.

More elaborate versions on arm64 and x86 account memory for the user page
tables and call to pgtable_pmd_page_ctor() as the part of PMD page

Move the arm64 version to include/asm-generic/pgalloc.h and use the
generic version on several architectures.

The pgtable_pmd_page_ctor() is a NOP when ARCH_ENABLE_SPLIT_PMD_PTLOCK is
not enabled, so there is no functional change for most architectures
except of the addition of __GFP_ACCOUNT for allocation of user page

The pmd_free() is a wrapper for free_page() in all the cases, so no
functional change here.

Signed-off-by: Mike Rapoport <>
Signed-off-by: Andrew Morton <>
Reviewed-by: Pekka Enberg <>
Cc: Matthew Wilcox <>
Cc: Abdul Haleem <>
Cc: Andy Lutomirski <>
Cc: Arnd Bergmann <>
Cc: Christophe Leroy <>
Cc: Joerg Roedel <>
Cc: Joerg Roedel <>
Cc: Max Filippov <>
Cc: Peter Zijlstra (Intel) <>
Cc: Satheesh Rajendran <>
Cc: Stafford Horne <>
Cc: Stephen Rothwell <>
Cc: Steven Rostedt <>
Cc: Geert Uytterhoeven <>
Signed-off-by: Linus Torvalds <>
13 files changed