MM: Support more pagesizes for MAP_HUGETLB/SHM_HUGETLB v4
Subsystems (5)
PATCH 1/1 MM: Support more pagesizes for MAP_HUGETLB/SHM_HUGETLB v4
From: Andi Kleen <[email protected]>
There was some desire in large applications using MAP_HUGETLB/SHM_HUGETLB to use 1GB huge pages on some mappings, and stay with 2MB on others. This is useful together with NUMA policy: use 2MB interleaving on some mappings, but 1GB on local mappings.
This patch extends the IPC/SHM syscall interfaces slightly to allow specifying the page size.
It borrows some upper bits in the existing flag arguments and allows encoding the log of the desired page size in addition to the *_HUGETLB flag. When 0 is specified the default size is used, this makes the change fully compatible.
Extending the internal hugetlb code to handle this is straight forward. Instead of a single mount it just keeps an array of them and selects the right mount based on the specified page size. When no page size is specified it uses the mount of the default page size.
The change is not visible in /proc/mounts because internal mounts don't appear there. It also has very little overhead: the additional mounts just consume a super block, but not more memory when not used.
I also exported the new flags to the user headers (they were previously under __KERNEL__). Right now only symbols for x86 and some other architecture for 1GB and 2MB are defined. The interface should already work for all other architectures though. Only architectures that define multiple hugetlb sizes actually need it (that is currently x86, tile, powerpc). However tile and powerpc have user configurable hugetlb sizes, so it's not easy to add defines. A program on those architectures would need to query sysfs and use the appropiate log2.
v2: Port to new tree. Fix unmount.
v3: Ported to latest tree.
v4: Ported to latest tree. Minor changes for review feedback. Updated description.
--- arch/x86/include/asm/mman.h | 3 ++ fs/hugetlbfs/inode.c | 63 +++++++++++++++++++++++++++++++-------- include/linux/hugetlb.h | 12 ++++++- include/linux/shm.h | 19 ++++++++++++ include/uapi/asm-generic/mman.h | 13 ++++++++ ipc/shm.c | 3 +- mm/mmap.c | 5 ++- 7 files changed, 100 insertions(+), 18 deletions(-)
arch/x86/include/asm/mman.h +3 -0
@@ -3,6 +3,9 @@#define MAP_32BIT 0x40/* only give out 32bit addresses */ +#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) +#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT) +#include <asm-generic/mman.h> #endif /* _ASM_X86_MMAN_H */
fs/hugetlbfs/inode.c +50 -13
124 lines not on this page · raw message
include/linux/hugetlb.h +10 -2
@@ -183,7 +183,13 @@ extern const struct file_operations hugetlbfs_file_operations;extern const struct vm_operations_struct hugetlb_vm_ops;struct file *hugetlb_file_setup (const char *name,unsigned long addr,size_t size,vm_flags_t acct, -struct user_struct **user,int creat_flags); +struct user_struct **user,int creat_flags, +int page_size_log); +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta); + +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta);static inline int is_file_hugepages (struct file *file) {
@@ -195,12 +201,14 @@ static inline int is_file_hugepages(struct file *file) return 0; } +#else /* !CONFIG_HUGETLBFS */ #define is_file_hugepages (file) 0static inline struct file *hugetlb_file_setup (const char *name,unsigned long addr,size_t size, -vm_flags_t acctflag,struct user_struct **user,int creat_flags) +vm_flags_t acctflag,struct user_struct **user,int creat_flags, +int page_size_log) {return ERR_PTR (-ENOSYS ); }
include/linux/shm.h +19 -0
@@ -100,12 +100,31 @@ struct shmid_kernel /* private to the kernel */ struct task_struct *shm_creator; }; +#endif +/* shm_mode upper byte flags */ #define SHM_DEST 01000/* segment will be destroyed on last detach */ #define SHM_LOCKED 02000/* segment will not be swapped */ #define SHM_HUGETLB 04000/* segment will use huge TLB pages */ #define SHM_NORESERVE 010000/* don't check for reservations */ +/* Bits [26:31] are reserved */ + +/* +* When SHM_HUGETLB is set bits [26:31] encode the log2 of the huge page size. +* This gives us 6 bits, which is enough until someone invents 128 bit address +* spaces. +* +* Assume these are all power of twos. +* When 0 use the default page size. +*/ +#define SHM_HUGE_SHIFT 26 +#define SHM_HUGE_MASK 0x3f +#define SHM_HUGE_2MB (21 << SHM_HUGE_SHIFT) +#define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT) + +#ifdef __KERNEL__ +#ifdef CONFIG_SYSVIPC long do_shmat (int shmid,char __user *shmaddr,int shmflg,unsigned long *addr,unsigned long shmlba);
include/uapi/asm-generic/mman.h +13 -0
@@ -13,6 +13,19 @@#define MAP_STACK 0x20000/* give out an address that is best suited for process/thread stacks */ #define MAP_HUGETLB 0x40000/* create a huge page mapping */ +/* Bits [26:31] are reserved */ + +/* +* When MAP_HUGETLB is set bits [26:31] encode the log2 of the huge page size. +* This gives us 6 bits, which is enough until someone invents 128 bit address +* spaces. +* +* Assume these are all power of twos. +* When 0 use the default page size. +*/ +#define MAP_HUGE_SHIFT 26 +#define MAP_HUGE_MASK 0x3f +#define MCL_CURRENT 1/* lock all current mappings */ #define MCL_FUTURE 2/* lock all future mappings */
ipc/shm.c +2 -1
@@ -495,7 +495,8 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)if (shmflg &SHM_NORESERVE ) acctflag =VM_NORESERVE ; file =hugetlb_file_setup (name,0 , size, acctflag, - &shp->mlock_user,HUGETLB_SHMFS_INODE ); + &shp->mlock_user,HUGETLB_SHMFS_INODE , + (shmflg >>SHM_HUGE_SHIFT ) &SHM_HUGE_MASK ); }else {/* * Do not allow no accounting for OVERCOMMIT_NEVER, even
mm/mmap.c +3 -2
@@ -1151,8 +1151,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,* memory so no accounting is necessary */ file =hugetlb_file_setup (HUGETLB_ANON_FILE , addr, len, -VM_NORESERVE , &user, -HUGETLB_ANONHUGE_INODE ); +VM_NORESERVE , + &user,HUGETLB_ANONHUGE_INODE , + (flags >>MAP_HUGE_SHIFT ) &MAP_HUGE_MASK );if (IS_ERR (file))return PTR_ERR (file); }
Signature · 7 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Andi,
Quoted 6 lines · Andi Kleen
include/linux/hugetlb.h +0
-0@@ -183,7 +183,13 @@ extern const struct file_operations hugetlbfs_file_operations;extern const struct vm_operations_struct hugetlb_vm_ops;
include/linux/hugetlb.h extern const struct file_operations hugetlbfs_file_operations; · line 192
Quoted 10 lines
include/linux/hugetlb.h +7
-1struct file *hugetlb_file_setup (const char *name,unsigned long addr,size_t size,vm_flags_t acct, -struct user_struct **user,int creat_flags); +struct user_struct **user,int creat_flags, +int page_size_log); +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta); + +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta);
For what to add(twice) hugetlb_get/put_quota?
Hillf
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines
include/linux/hugetlb.h extern const struct file_operations hugetlbfs_file_operations; · line 192
Quoted 8 lines
include/linux/hugetlb.h +7
-1- struct user_struct **user, int creat_flags); + struct user_struct **user, int creat_flags, + int page_size_log); +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta); + +int hugetlb_get_quota (struct address_space *mapping,long delta); +void hugetlb_put_quota (struct address_space *mapping,long delta);For what to add(twice) hugetlb_get/put_quota?
Hmm probably a merge error. Thanks for catching.
I can repost or post the trivial incremential.
-Andi
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>