Skip to content

Commit aafd456

Browse files
mjkravetztorvalds
authored andcommitted
mm: arch: consolidate mmap hugetlb size encodings
A non-default huge page size can be encoded in the flags argument of the mmap system call. The definitions for these encodings are in arch specific header files. However, all architectures use the same values. Consolidate all the definitions in the primary user header file (uapi/linux/mman.h). Include definitions for all known huge page sizes. Use the generic encoding definitions in hugetlb_encode.h as the basis for these definitions. Link: http://lkml.kernel.org/r/1501527386-10736-3-git-send-email-mike.kravetz@oracle.com Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e652f69 commit aafd456

8 files changed

Lines changed: 22 additions & 74 deletions

File tree

‎arch/alpha/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@
6767
/* compatibility flags */
6868
#define MAP_FILE 0
6969

70-
/*
71-
* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
72-
* This gives us 6 bits, which is enough until someone invents 128 bit address
73-
* spaces.
74-
*
75-
* Assume these are all power of twos.
76-
* When 0 use the default page size.
77-
*/
78-
#define MAP_HUGE_SHIFT 26
79-
#define MAP_HUGE_MASK 0x3f
80-
8170
#define PKEY_DISABLE_ACCESS 0x1
8271
#define PKEY_DISABLE_WRITE 0x2
8372
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

‎arch/mips/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,6 @@
9494
/* compatibility flags */
9595
#define MAP_FILE 0
9696

97-
/*
98-
* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
99-
* This gives us 6 bits, which is enough until someone invents 128 bit address
100-
* spaces.
101-
*
102-
* Assume these are all power of twos.
103-
* When 0 use the default page size.
104-
*/
105-
#define MAP_HUGE_SHIFT 26
106-
#define MAP_HUGE_MASK 0x3f
107-
10897
#define PKEY_DISABLE_ACCESS 0x1
10998
#define PKEY_DISABLE_WRITE 0x2
11099
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

‎arch/parisc/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@
6464
#define MAP_FILE 0
6565
#define MAP_VARIABLE 0
6666

67-
/*
68-
* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
69-
* This gives us 6 bits, which is enough until someone invents 128 bit address
70-
* spaces.
71-
*
72-
* Assume these are all power of twos.
73-
* When 0 use the default page size.
74-
*/
75-
#define MAP_HUGE_SHIFT 26
76-
#define MAP_HUGE_MASK 0x3f
77-
7867
#define PKEY_DISABLE_ACCESS 0x1
7968
#define PKEY_DISABLE_WRITE 0x2
8069
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

‎arch/powerpc/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,4 @@
2929
#define MAP_STACK 0x20000 /* give out an address that is best suited for process/thread stacks */
3030
#define MAP_HUGETLB 0x40000 /* create a huge page mapping */
3131

32-
/*
33-
* When MAP_HUGETLB is set, bits [26:31] of the flags argument to mmap(2),
34-
* encode the log2 of the huge page size. A value of zero indicates that the
35-
* default huge page size should be used. To use a non-default huge page size,
36-
* one of these defines can be used, or the size can be encoded by hand. Note
37-
* that on most systems only a subset, or possibly none, of these sizes will be
38-
* available.
39-
*/
40-
#define MAP_HUGE_512KB (19 << MAP_HUGE_SHIFT) /* 512KB HugeTLB Page */
41-
#define MAP_HUGE_1MB (20 << MAP_HUGE_SHIFT) /* 1MB HugeTLB Page */
42-
#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) /* 2MB HugeTLB Page */
43-
#define MAP_HUGE_8MB (23 << MAP_HUGE_SHIFT) /* 8MB HugeTLB Page */
44-
#define MAP_HUGE_16MB (24 << MAP_HUGE_SHIFT) /* 16MB HugeTLB Page */
45-
#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT) /* 1GB HugeTLB Page */
46-
#define MAP_HUGE_16GB (34 << MAP_HUGE_SHIFT) /* 16GB HugeTLB Page */
47-
4832
#endif /* _UAPI_ASM_POWERPC_MMAN_H */

‎arch/x86/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
#define MAP_32BIT 0x40 /* only give out 32bit addresses */
55

6-
#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT)
7-
#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
8-
96
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
107
/*
118
* Take the 4 protection key bits out of the vma->vm_flags

‎arch/xtensa/include/uapi/asm/mman.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@
106106
/* compatibility flags */
107107
#define MAP_FILE 0
108108

109-
/*
110-
* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
111-
* This gives us 6 bits, which is enough until someone invents 128 bit address
112-
* spaces.
113-
*
114-
* Assume these are all power of twos.
115-
* When 0 use the default page size.
116-
*/
117-
#define MAP_HUGE_SHIFT 26
118-
#define MAP_HUGE_MASK 0x3f
119-
120109
#define PKEY_DISABLE_ACCESS 0x1
121110
#define PKEY_DISABLE_WRITE 0x2
122111
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

‎include/uapi/asm-generic/mman-common.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@
6161
/* compatibility flags */
6262
#define MAP_FILE 0
6363

64-
/*
65-
* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
66-
* This gives us 6 bits, which is enough until someone invents 128 bit address
67-
* spaces.
68-
*
69-
* Assume these are all power of twos.
70-
* When 0 use the default page size.
71-
*/
72-
#define MAP_HUGE_SHIFT 26
73-
#define MAP_HUGE_MASK 0x3f
74-
7564
#define PKEY_DISABLE_ACCESS 0x1
7665
#define PKEY_DISABLE_WRITE 0x2
7766
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\

‎include/uapi/linux/mman.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _UAPI_LINUX_MMAN_H
33

44
#include <asm/mman.h>
5+
#include <asm-generic/hugetlb_encode.h>
56

67
#define MREMAP_MAYMOVE 1
78
#define MREMAP_FIXED 2
@@ -10,4 +11,25 @@
1011
#define OVERCOMMIT_ALWAYS 1
1112
#define OVERCOMMIT_NEVER 2
1213

14+
/*
15+
* Huge page size encoding when MAP_HUGETLB is specified, and a huge page
16+
* size other than the default is desired. See hugetlb_encode.h.
17+
* All known huge page size encodings are provided here. It is the
18+
* responsibility of the application to know which sizes are supported on
19+
* the running system. See mmap(2) man page for details.
20+
*/
21+
#define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
22+
#define MAP_HUGE_MASK HUGETLB_FLAG_ENCODE_MASK
23+
24+
#define MAP_HUGE_64KB HUGETLB_FLAG_ENCODE_64KB
25+
#define MAP_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
26+
#define MAP_HUGE_1MB HUGETLB_FLAG_ENCODE_1MB
27+
#define MAP_HUGE_2MB HUGETLB_FLAG_ENCODE_2MB
28+
#define MAP_HUGE_8MB HUGETLB_FLAG_ENCODE_8MB
29+
#define MAP_HUGE_16MB HUGETLB_FLAG_ENCODE_16MB
30+
#define MAP_HUGE_256MB HUGETLB_FLAG_ENCODE_256MB
31+
#define MAP_HUGE_1GB HUGETLB_FLAG_ENCODE_1GB
32+
#define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB
33+
#define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB
34+
1335
#endif /* _UAPI_LINUX_MMAN_H */

0 commit comments

Comments
 (0)