Commit 4e52780d authored by Eric B Munson's avatar Eric B Munson Committed by Linus Torvalds
Browse files

hugetlb: add MAP_HUGETLB for mmaping pseudo-anonymous huge page regions

Add a flag for mmap that will be used to request a huge page region that
will look like anonymous memory to userspace.  This is accomplished by
using a file on the internal vfsmount.  MAP_HUGETLB is a modifier of
MAP_ANONYMOUS and so must be specified with it.  The region will behave
the same as a MAP_ANONYMOUS region using small pages.

[ fix arch definitions of MAP_HUGETLB]
Signed-off-by: default avatarEric B Munson <>
Acked-by: default avatarDavid Rientjes <>
Cc: Mel Gorman <>
Cc: Adam Litke <>
Cc: David Gibson <>
Cc: Lee Schermerhorn <>
Cc: Nick Piggin <>
Cc: Hugh Dickins <>
Cc: Arnd Bergmann <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 90f72aa5
......@@ -112,12 +112,19 @@ static inline void hugetlb_report_meminfo(struct seq_file *m)
#define HUGETLB_ANON_FILE "anon_hugepage"
enum {
* The file will be used as an shm file so shmfs accounting rules
* apply
* The file is being created on the internal vfs mount and shmfs
* accounting rules do not apply
......@@ -949,6 +949,24 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
if (mm->map_count > sysctl_max_map_count)
return -ENOMEM;
if (flags & MAP_HUGETLB) {
struct user_struct *user = NULL;
if (file)
return -EINVAL;
* VM_NORESERVE is used because the reservations will be
* taken when vm_ops->mmap() is called
* A dummy user value is used because we are not locking
* memory so no accounting is necessary
len = ALIGN(len, huge_page_size(&default_hstate));
file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
if (IS_ERR(file))
return PTR_ERR(file);
/* Obtain the address to map to. we verify (or select) it and ensure
* that it represents a valid section of the address space.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment