Shared Policy Overview
Subsystems (19)
cover Shared Policy Overview
[RFC] Shared Policy Cleanup, Fixes and Mapped File Policy
At the Linux Plumber's conference, Andi Kleen encouraged me again to resubmit my automatic page migration patches because he thinks they will be useful for virtualization. Later, in the Virtualization mini-conf, the subject came up during a presentation about adding NUMA awareness to qemu/kvm. After the presentation, I discussed these series with Andrea Arcangeli and he also encouraged me to post them. My position within HP has changed such that I'm not sure how much time I'll have to spend on this area nor whether I'll have access to the larger NUMA platforms on which to test the patches thoroughly. However, here is the first of 4 series that comprise my shared policy enhancements and lazy/auto-migration enhancement.
I have rebased the patches against a recent mmotm tree. This rebase built cleanly, booted and passed a few ad hoc tests on x86_64. I've made a pass over the patch descriptions to update them. If there is sufficient interest in merging this, I'll do what I can to assist in the completion and testing of the series.
To follow:
2) Migrate-on-fault a.k.a Lazy Migration facility 3) Auto [as in "self"] migration facility 4) a Migration Cache -- originally written by Marcello Tosatti
I'll announce this series and the automatic/lazy migration series to follow on lkml, linux-mm, ... However, I'll limit the actual posting to linux-numa to avoid spamming the other lists.
I'm posting this shared policy series before the lazy and automatic migration series because the latter series are based atop this one in my tree. I want to send out a buildable, runnable set of patches and don't have the time to rebase the later series right now. And, although the later series do not functionally depend on this series, I think it provides some reasonable cleanup and finishes some, IMO, missing shared policy capabilities. But, ultimately it's not required for the auto/lazy-migration feature.
---
This series:
1) cleans up some shared policy variable naming,
2) reworks the shared policy internal interfaces to moved it from a "vma,address" orientation to an "policy, offset" one, where the offset is used for selected the node for an interleaved policy. This rework allows us to remove the last usage of a "pseudo-vma" to lookup or set mempolicy on a shared memory object.
3) reworks vma policy handling so that vmas are not split for shared memory policy because the shared policy infrastructure handles subrange mempolicies for the object. Thus there is no need to split vmas for different mempolicy on different ranges of the shared object.
4) Fixes a long standing issue with /proc/<pid>/numa_maps where one can see different mempolicies on shared memory objects depending on which task applied the policies. This occurs because Linux only split the vmas for the task applying the shared policy. Essentially, now numa_maps now looks into a shared object mapped by a single vma and reports any mempolicy on subranges of the object.
5) Hooks up the hugetlbfs back shmem regions [SHM_HUGE] to the shared mempolicy mechanism. The hugetlbfs inode has contained the shared policy structure for quite some time, but the vm ops were never hooked up. Optional behavior; default is current behavior -- no shared policy on SHM_HUGE regions.
6) Enhances shared, mmap()'ed regular files to support shared policy on the resulting memory object as long as it remains mmap()'ed. Optional behavior; default is current behavior -- no shared policy on shared, mmap()ed files [except tmpfs].
7) Builds cleanly [my .config, anyway] and passes ad hoc memtoy tests on x86_64. Has been built/tested on ia64 in the past but not recently.
---
Lee Schermerhorn
PATCH 1/14 Shared Policy: Miscellaneous Cleanup
Shared Policy - Miscellaneous shared policy cleanup
Some miscellaneous cleanup to use "sp" for shared policy in routines that take one as an arg. Prior use of "info" seemed misleading, as it also refers to the shm_inode_info. And use of "p" seemed just plain inconsistent.
Additional cleanup/reorg of the numa_memory_policy.txt doc.
This patch is in preparation for additional shared policy rework. I wanted to break the minor "cleanup" changes out into a separate patch.
Documentation/vm/numa_memory_policy.txt | 244 +++++++++++++++++--------------- include/linux/mempolicy.h | 10 - mm/mempolicy.c | 24 +-- 3 files changed, 156 insertions(+), 122 deletions(-)
mm/mempolicy.c +15 -9
@@ -2185,7 +2185,7 @@ put_mpol: } } -int mpol_set_shared_policy (struct shared_policy *info, +int mpol_set_shared_policy (struct shared_policy *sp,struct vm_area_struct *vma,struct mempolicy *npol) {int err;
@@ -2203,30 +2203,36 @@ int mpol_set_shared_policy(struct sharedif (!new)return -ENOMEM ; } - err =shared_policy_replace (info, vma->vm_pgoff, vma->vm_pgoff+sz, new); + err =shared_policy_replace (sp, vma->vm_pgoff, vma->vm_pgoff+sz, new);if (err && new)kmem_cache_free (sn_cache, new);return err; } -/* Free a backing policy store on inode delete. */ -void mpol_free_shared_policy (struct shared_policy *p) +/** +* mpol_free_shared_policy() - Free a backing policy store on inode delete. +* @sp - shared policy structure to free +* +* Frees the shared policy red-black tree, if any, before freeing the +* shared policy struct itself. +*/ +void mpol_free_shared_policy (struct shared_policy *sp) {struct sp_node *n;struct rb_node *next; -if (!p->root.rb_node) +if (!sp->root.rb_node)return ; -spin_lock (&p->lock); - next =rb_first (&p->root); +spin_lock (&sp->lock); + next =rb_first (&sp->root);while (next) { n = rb_entry(next, struct sp_node, nd); next =rb_next (&n->nd); -rb_erase (&n->nd, &p->root); +rb_erase (&n->nd, &sp->root);mpol_put (n->policy);kmem_cache_free (sn_cache, n); } -spin_unlock (&p->lock); +spin_unlock (&sp->lock); }/* assumes fs == KERNEL_DS */
include/linux/mempolicy.h +5 -5
@@ -81,7 +81,7 @@ struct mm_struct;* the process policy is used. Interrupts ignore the memory policy * of the current process. * -* Locking policy for interlave: +* Locking policy for interleave: * In process context there is no locking because only the process accesses * its own state. All vma manipulation is somewhat protected by a down_read on * mmap_sem.
@@ -192,10 +192,10 @@ struct shared_policy { };void mpol_shared_policy_init (struct shared_policy *sp,struct mempolicy *mpol); -int mpol_set_shared_policy (struct shared_policy *info, +int mpol_set_shared_policy (struct shared_policy *sp,struct vm_area_struct *vma,struct mempolicy *new); -void mpol_free_shared_policy (struct shared_policy *p); +void mpol_free_shared_policy (struct shared_policy *sp);struct mempolicy *mpol_shared_policy_lookup (struct shared_policy *sp,unsigned long idx);
@@ -284,7 +284,7 @@ static inline struct mempolicy *mpol_dupstruct shared_policy {}; -static inline int mpol_set_shared_policy (struct shared_policy *info, +static inline int mpol_set_shared_policy (struct shared_policy *sp,struct vm_area_struct *vma,struct mempolicy *new) {
@@ -296,7 +296,7 @@ static inline void mpol_shared_policy_in { } -static inline void mpol_free_shared_policy (struct shared_policy *p) +static inline void mpol_free_shared_policy (struct shared_policy *sp) { }
Documentation/vm/numa_memory_policy.txt +136 -108
306 lines not on this page · raw message
PATCH 2/14 Shared Policy: move shared policy to inode/mapping
In reply to Lee SchermerhornShared Policy Infrastructure - move shared policy to inode/mapping
This patch starts the process of cleaning the shmem shared [mem]policy infrastructure:
+ to eliminate use of on-stack pseudo-vmas for shmem allocations which will simplify several shmem internal APIs and functions.
+ for use with hugetlb shmem segments and
+ eventually, I hope, for use with generic mmap()ed files.
In this patch, the shared policy struct in the shmem and hugetlbfs extended inodes are moved to the generic address space struct where it will be available to any file type, and fixes up the existing code to accomodate this change.
Details:
1) create a shared_policy.h header and move the shared policy support from mempolicy.h to shared_policy.h.
2) add a struct shared_policy pointer to struct address_space This effectively adds it to each inode in i_data. get_policy vma ops will locate this via vma->vm_file->f_mapping->spolicy. Modify [temporarily] mpol_shared_policy_init() to initialize via a shared policy pointer arg.
A subsequent patch will replace this with a pointer to a dynamically allocated mempolicy and will make the pointer dependent on CONFIG_NUMA. Then, all accesses to spolicy will also be made dependent on CONFIG_NUMA via wrappers.
3) modify mpol_shared_policy_lookup() to return NULL if spolicy pointer contains NULL. get_vma_policy() will substitute the process policy, if any, else the default policy.
4) modify shmem, the only existing user of shared policy infrastructure, to work with changes above. At this point, just use the shared_policy embedded in the shmem inode info struct. A later patch will dynamically allocate the struct when needed.
Actually, hugetlbfs inodes also contain a shared policy, but the vma's get|set_policy ops are not hooked up. This patch modifies hugetlbfs_get_inode() to initialize the shared policy struct embedded in its info struct via the i_mapping's spolicy pointer. A later patch will "hook up" hugetlb mappings to the get|set_policy ops.
fs/hugetlbfs/inode.c | 3 + include/linux/fs.h | 2 + include/linux/mempolicy.h | 53 --------------------------------- include/linux/shared_policy.h | 66 ++++++++++++++++++++++++++++++++++++++++++ mm/mempolicy.c | 2 - mm/shmem.c | 37 ++++++++++++----------- 6 files changed, 92 insertions(+), 71 deletions(-)
include/linux/fs.h +2 -0
@@ -646,6 +646,8 @@ struct address_space {spinlock_t private_lock;/* for use by the address_space */ struct list_head private_list;/* ditto */ struct address_space *assoc_mapping;/* ditto */ + +struct shared_policy *spolicy; } __attribute__((aligned(sizeof(long))));/* * On most architectures that alignment is already the case; but
include/linux/mempolicy.h +1 -52
73 lines not on this page · raw message
include/linux/shared_policy.h new file +66 -0
66 lines not on this page · raw message
mm/mempolicy.c +1 -1
@@ -2053,7 +2053,7 @@ mpol_shared_policy_lookup(struct shared_struct mempolicy *pol =NULL ;struct sp_node *sn; -if (!sp->root.rb_node) +if (!sp || !sp->root.rb_node)return NULL ;spin_lock (&sp->lock); sn =sp_lookup (sp, idx, idx+1 );
mm/shmem.c +20 -17
@@ -1146,15 +1146,14 @@ static struct mempolicy *shmem_get_sbmpo }#endif /* CONFIG_TMPFS */ -static struct page *shmem_swapin (swp_entry_t entry,gfp_t gfp, -struct shmem_inode_info *info,unsigned long idx) +struct page *shmem_swapin (swp_entry_t entry,gfp_t gfp, +struct shared_policy *sp,unsigned long idx) {struct mempolicy mpol, *spol;struct vm_area_struct pvma;struct page *page; - spol =mpol_cond_copy (&mpol, -mpol_shared_policy_lookup (&info->policy, idx)); + spol =mpol_cond_copy (&mpol,mpol_shared_policy_lookup (sp, idx));/* Create a pseudo vma that just contains the policy */ pvma.vm_start =0 ;
@@ -1165,8 +1164,8 @@ static struct page *shmem_swapin(swp_entreturn page; } -static struct page *shmem_alloc_page (gfp_t gfp, -struct shmem_inode_info *info,unsigned long idx) +static struct page *shmem_alloc_page (gfp_t gfp,struct shared_policy *sp, +unsigned long idx) {struct vm_area_struct pvma;
@@ -1174,7 +1173,7 @@ static struct page *shmem_alloc_page(gfp pvma.vm_start =0 ; pvma.vm_pgoff = idx; pvma.vm_ops =NULL ; - pvma.vm_policy =mpol_shared_policy_lookup (&info->policy, idx); + pvma.vm_policy =mpol_shared_policy_lookup (sp, idx);/* * alloc_page_vma() will drop the shared policy reference
@@ -1188,14 +1187,14 @@ static inline void shmem_show_mpol(struc }#endif /* CONFIG_TMPFS */ -static inline struct page *shmem_swapin (swp_entry_t entry,gfp_t gfp, -struct shmem_inode_info *info,unsigned long idx) +static inline struct page *shmem_swapin (swp_entry_t entry,gfp_t gfp,void *sp, +unsigned long idx) {return swapin_readahead (entry, gfp,NULL ,0 ); } -static inline struct page *shmem_alloc_page (gfp_t gfp, -struct shmem_inode_info *info,unsigned long idx) +static inline struct page *shmem_alloc_page (gfp_t gfp,void *sp, +unsigned long idx) {return alloc_page (gfp); }
@@ -1260,7 +1259,7 @@ repeat:radix_tree_preload_end ();if (sgp !=SGP_READ && !prealloc_page) {/* We don't care if this fails */ - prealloc_page =shmem_alloc_page (gfp, info, idx); + prealloc_page =shmem_alloc_page (gfp, mapping->spolicy, idx);if (prealloc_page) {if (mem_cgroup_cache_charge (prealloc_page, current->mm,GFP_KERNEL )) {
@@ -1293,7 +1292,8 @@ repeat: *type |=VM_FAULT_MAJOR ; }spin_unlock (&info->lock); - swappage =shmem_swapin (swap, gfp, info, idx); + swappage =shmem_swapin (swap, gfp, mapping->spolicy, + idx);if (!swappage) {spin_lock (&info->lock); entry =shmem_swp_alloc (info, idx, sgp);
@@ -1420,7 +1420,7 @@ repeat:if (!prealloc_page) {spin_unlock (&info->lock); - filepage =shmem_alloc_page (gfp, info, idx); + filepage =shmem_alloc_page (gfp, mapping->spolicy, idx);if (!filepage) {shmem_unacct_blocks (info->flags,1 );shmem_free_blocks (inode,1 );
@@ -1608,7 +1608,8 @@ static struct inode *shmem_get_inode(str inode->i_mapping->a_ops = &shmem_aops; inode->i_op = &shmem_inode_operations; inode->i_fop = &shmem_file_operations; -mpol_shared_policy_init (&info->policy, + inode->i_mapping->spolicy = &info->policy; +mpol_shared_policy_init (inode->i_mapping->spolicy,shmem_get_sbmpol (sbinfo));break ;case S_IFDIR :
@@ -1623,7 +1624,9 @@ static struct inode *shmem_get_inode(str* Must not load anything in the rbtree, * mpol_free_shared_policy will not be called. */ -mpol_shared_policy_init (&info->policy,NULL ); + inode->i_mapping->spolicy = &info->policy; +mpol_shared_policy_init (inode->i_mapping->spolicy, +NULL );break ; } }else
@@ -2419,7 +2422,7 @@ static void shmem_destroy_inode(struct i {if ((inode->i_mode &S_IFMT ) ==S_IFREG ) {/* only struct inode is valid if it's an inline symlink */ -mpol_free_shared_policy (&SHMEM_I (inode)->policy); +mpol_free_shared_policy (inode->i_mapping->spolicy); }kmem_cache_free (shmem_inode_cachep,SHMEM_I (inode)); }
fs/hugetlbfs/inode.c +2 -1
@@ -472,7 +472,8 @@ static struct inode *hugetlbfs_get_inode* call mpol_free_shared_policy() it will just return because * the rb tree will still be empty. */ -mpol_shared_policy_init (&info->policy,NULL ); + inode->i_mapping->spolicy = &info->policy; +mpol_shared_policy_init (inode->i_mapping->spolicy,NULL );switch (mode &S_IFMT ) {default :init_special_inode (inode, mode, dev);
PATCH 3/14 Shared Policy: allocate shared policies as needed
In reply to Lee SchermerhornShared Policy Infrastructure - dynamically alloc shared policies
Remove shared policy structs from shmem and hugetlbfs inode info structs and dynamically allocate them as needed.
Make shared policy pointer in address_space dependent on CONFIG_NUMA to avoid burdening configs that don't need/want NUMA support. Access [get/set] the shared_policy via wrappers that also depend on 'NUMA [to avoid excessive #ifdef in .c files].
Initialize shmem and hugetlbfs inode/address_space spolicy pointer to null, unless superblock [mount] specifies a non-default policy. Null shared policy pointer will cause 'get policy'--e.g., for page allocations--to fall back to task policy, if any, else to system default policy. Just like NULL vma policies.
set_policy() ops must create shared_policy struct from a new kmem cache when a new policy is installed and no spolicy exists. mpol_shared_policy_init() replaced with mpol_shared_policy_new() to accomplish this.
shmem must create/initialize a shared_policy when it allocates an inode if the tmpfs super-block/mount point specifies a non-default policy.
mpol_free_shared_policy() must free the spolicy, if any, when inode is destroyed.
NOTE: along with the previous patch in the series, this patch adds a single pointer to the generic address_space struct and thus to all inodes. Last I looked, this did not decrease the inodes/slab for x86_64 [and ia64 FWIW]. Other arcs need to be checked. If this extra pointer is problematic, I believe we could over load the non-linear pointer and use as_flags to detect.
fs/hugetlbfs/inode.c | 19 ++---- fs/inode.c | 1 include/linux/fs.h | 27 ++++++++ include/linux/hugetlb.h | 1 include/linux/shared_policy.h | 24 ++++--- include/linux/shmem_fs.h | 1 mm/mempolicy.c | 128 ++++++++++++++++++++++++++++-------------- mm/shmem.c | 49 ++++++++++------ 8 files changed, 168 insertions(+), 82 deletions(-)
include/linux/shared_policy.h +14 -10
@@ -1,6 +1,7 @@#ifndef _LINUX_SHARED_POLICY_H#define _LINUX_SHARED_POLICY_H 1 +#include <linux/fs.h> #include <linux/spinlock.h> #include <linux/rbtree.h>
@@ -28,13 +29,15 @@ struct shared_policy { spinlock_t lock; /* protects rb tree */ }; -void mpol_shared_policy_init (struct shared_policy *sp,struct mempolicy *mpol); -int mpol_set_shared_policy (struct shared_policy *, -struct vm_area_struct *, -struct mempolicy *); -void mpol_free_shared_policy (struct shared_policy *); -struct mempolicy *mpol_shared_policy_lookup (struct shared_policy *, -unsigned long ); +extern struct shared_policy *mpol_shared_policy_new ( +struct address_space *mapping, +struct mempolicy *mpol); +extern int mpol_set_shared_policy (struct shared_policy *, +struct vm_area_struct *, +struct mempolicy *); +extern void mpol_free_shared_policy (struct address_space *); +extern struct mempolicy *mpol_shared_policy_lookup (struct shared_policy *, +unsigned long );#else /* !NUMA */
@@ -47,12 +50,12 @@ static inline int mpol_set_shared_policyreturn -EINVAL ; } -static inline void mpol_shared_policy_init (struct shared_policy *sp, -struct mempolicy *mpol) +static inline struct shared_policy * +mpol_shared_policy_new (struct address_space *mapping,struct mempolicy *mpol) { } -static inline void mpol_free_shared_policy (struct shared_policy *p) +static inline void mpol_free_shared_policy (struct shared_policy *sp) { }
@@ -61,6 +64,7 @@ mpol_shared_policy_lookup(struct shared_ {return NULL ; } +#endif #endif /* _LINUX_SHARED_POLICY_H */
mm/mempolicy.c +87 -41
179 lines not on this page · raw message
mm/shmem.c +32 -17
100 lines not on this page · raw message
fs/hugetlbfs/inode.c +7 -12
@@ -448,14 +448,13 @@ static int hugetlbfs_setattr(struct dentreturn 0 ; } -static struct inode *hugetlbfs_get_inode (struct super_block *sb,uid_t uid, +static struct inode *hugetlbfs_get_inode (struct super_block *sb,uid_t uid,gid_t gid,int mode,dev_t dev) {struct inode *inode; inode =new_inode (sb);if (inode) { -struct hugetlbfs_inode_info *info; inode->i_ino =get_next_ino (); inode->i_mode = mode; inode->i_uid = uid;
@@ -464,16 +463,9 @@ static struct inode *hugetlbfs_get_inode inode->i_mapping->backing_dev_info =&hugetlbfs_backing_dev_info; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;INIT_LIST_HEAD (&inode->i_mapping->private_list); - info =HUGETLBFS_I (inode);/* -* The policy is initialized here even if we are creating a -* private inode because initialization simply creates an -* an empty rb tree and calls spin_lock_init(), later when we -* call mpol_free_shared_policy() it will just return because -* the rb tree will still be empty. +* leave i_mapping->spolicy NULL [default policy] */ - inode->i_mapping->spolicy = &info->policy; -mpol_shared_policy_init (inode->i_mapping->spolicy,NULL );switch (mode &S_IFMT ) {default :init_special_inode (inode, mode, dev);
@@ -486,7 +478,10 @@ static struct inode *hugetlbfs_get_inode inode->i_op = &hugetlbfs_dir_inode_operations; inode->i_fop = &simple_dir_operations; -/* directory inodes start off with i_nlink == 2 (for "." entry) */ +/* +* directory inodes start off with i_nlink == 2 +* (for "." entry) +*/ inc_nlink (inode);break ;case S_IFLNK :
@@ -667,7 +662,7 @@ static struct inode *hugetlbfs_alloc_inostatic void hugetlbfs_destroy_inode (struct inode *inode) {hugetlbfs_inc_free_inodes (HUGETLBFS_SB (inode->i_sb)); -mpol_free_shared_policy (&HUGETLBFS_I (inode)->policy); +mpol_free_shared_policy (inode->i_mapping);kmem_cache_free (hugetlbfs_inode_cachep,HUGETLBFS_I (inode)); }
include/linux/hugetlb.h +0 -1
@@ -152,7 +152,6 @@ struct hugetlbfs_sb_info {struct hugetlbfs_inode_info { -struct shared_policy policy;struct inode vfs_inode; };
include/linux/shmem_fs.h +0 -1
@@ -15,7 +15,6 @@ struct shmem_inode_info {unsigned long alloced;/* data pages alloced to file */ unsigned long swapped;/* subtotal assigned to swap */ unsigned long next_index;/* highest alloced index + 1 */ -struct shared_policy policy;/* NUMA memory alloc policy */ struct page *i_indirect;/* top indirect blocks page */ swp_entry_t i_direct[SHMEM_NR_DIRECT ];/* first blocks */ struct list_head swaplist;/* chain of maybes on swap */
fs/inode.c +1 -0
@@ -215,6 +215,7 @@ int inode_init_always(struct super_block mapping->backing_dev_info = bdi; } inode->i_private =NULL ; +set_mapping_shared_policy (mapping,NULL ); inode->i_mapping = mapping;#ifdef CONFIG_FS_POSIX_ACL inode->i_acl = inode->i_default_acl =ACL_NOT_CACHED ;
include/linux/fs.h +27 -0
@@ -647,7 +647,9 @@ struct address_space {struct list_head private_list;/* ditto */ struct address_space *assoc_mapping;/* ditto */ +#ifdef CONFIG_NUMA struct shared_policy *spolicy; +#endif } __attribute__((aligned(sizeof(long))));/* * On most architectures that alignment is already the case; but
@@ -655,6 +657,31 @@ struct address_space {* of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. */ +#ifdef CONFIG_NUMA +static inline struct shared_policy * +mapping_shared_policy (struct address_space *mapping) +{ +return mapping->spolicy; +} + +static inline void set_mapping_shared_policy (struct address_space *mapping, +struct shared_policy *sp) +{ + mapping->spolicy = sp; +} + +#else +static inline struct shared_policy * +mapping_shared_policy (struct address_space *mapping) +{ +return NULL ; +} + +static inline void set_mapping_shared_policy (struct address_space *mapping, +struct shared_policy *sp) +{ } +#endif +struct block_device {dev_t bd_dev;/* not a kdev_t - it's a search key */ struct inode * bd_inode;/* will die */
PATCH 4/14 Shared Policy: let vma policy ops handle sub-vma policies
In reply to Lee SchermerhornShared Policy Infrastructure - let vma policy ops handle sub-vma policies
Shared policies can handle subranges of an object. No need to split the vma for these mappings. So, ...
Add a vm_mpol_flag member to vm_area_struct with flags to control the vma splitting behavior.
Note: Perhaps there is another field where these flags could go?
Modify mbind_range() and policy_vma() to call the set_policy vma op, if one exists, for vma's with VMPOL_F_NOSPLIT set, instead of splitting the vma for the mempolicy range. However, if vma is VM_SHARED and we would be splitting the vma--don't! This policy will just be ignored and numa_maps would be [currently are] misleading.
Now, we don't want private mappings mucking with the shared policy of the mapped file, if any, so use vma policy for private mappings. We'll still split vmas for private mappings.
As a result, this patch enforces a defined semantic for set|get_policy()
ops: they only get called for linear, shared mappings, and in that case we don't split the vma. Only shmem currently has set|get_policy() ops, and this seems an appropriate semantic for shared objects, in general. It also matches current behavior.
Now, since the vma start and end addresses no longer specify the range to which a new policy applies, we need to add start,end address args to the vma policy ops. The set_policy op/handler just calls into mpol_set_shared_policy() to do the real work, so we could just pass the start and end address, along with the vma, down to that function. However, to eliminate the need for the pseudo-vma on the stack when initializing the shared policy for an inode with non-default "superblock policy", we change the interface to mpol_set_shared_policy() to take a page offset and size in pages. We compute the page offset and size in the shmem set_policy handler from the vma and the address range.
NOTE: Added helper function "vma_mpol_pgoff()" for computing page offset for interleaving. This is similar to [linear_]page_index() but does not offset by the PAGE_CACHE_SHIFT so that it can be used for calculating page indices for interleaving for both base pages and huge pages [subsequent patch]. Perhaps this can be merged with other similar functions?
A word about non-linear mappings:
Shared policy ops do and always have installed and looked up shared policies at a given (vma, address) by computing a page offset and size into the backing file from the (vma, address) assuming a linear mapping from virtual addresses to file page offsets. Therefore this patch series restricts shared policies to linearly mapped shared file mappings. This is nominally a change in behavior.
I don't know whether anyone is attempting to use memory policies with non-linearly mapped shared memory areas or hugetlbfs mappings. If so, I don't understand what behavior they expect. Since different tasks could establish different mappings to the shared files, pages and mempolicies that show up at one offset in one task, can show up at a different offset in another task. However, if this is a required feature, and we can come up with reasonable semantics for supporting shared policies with nonlinear mappings, I can try to support it.
Note: although this patch removed the splitting of the vma when a shared policy is installed in a sub-range of the shared area, I will defer updating the documentation to the following patch, which fixes the numa_maps display.
fs/sysfs/bin.c | 5 + include/linux/mempolicy.h | 16 +++++ include/linux/mm.h | 13 ++++ include/linux/mm_types.h | 1 include/linux/shared_policy.h | 7 +- ipc/shm.c | 5 + mm/mempolicy.c | 119 ++++++++++++++++++++++++++++++++---------- mm/shmem.c | 16 +++-- 8 files changed, 140 insertions(+), 42 deletions(-)
include/linux/mm_types.h +1 -0
@@ -182,6 +182,7 @@ struct vm_area_struct {#endif #ifdef CONFIG_NUMA struct mempolicy *vm_policy;/* NUMA policy for the VMA */ +int vm_mpol_flags;/* NOSPLIT, ... */ #endif };
include/linux/mempolicy.h +16 -0
@@ -110,6 +110,13 @@ struct mempolicy { };/* +* vma memory policy flags +*/ +enum vm_mpol_flags { +VMPOL_F_NOSPLIT =0x00000001 ,/* don't split vma for mempolicy */ +}; + +/* * Support for managing mempolicy data objects (clone, copy, destroy) * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. */
@@ -157,6 +164,11 @@ static inline struct mempolicy *mpol_dup#define vma_policy (vma) ((vma)->vm_policy)#define vma_set_policy (vma, pol) ((vma)->vm_policy = (pol)) +static inline void mpol_set_vma_nosplit (struct vm_area_struct *vma) +{ + (vma)->vm_mpol_flags |=VMPOL_F_NOSPLIT ; +} +static inline void mpol_get (struct mempolicy *pol) {if (pol)
@@ -258,6 +270,10 @@ static inline struct mempolicy *mpol_dup#define vma_policy (vma) NULL#define vma_set_policy (vma, pol) do {} while(0) +static inline void mpol_set_vma_nosplit (struct vm_area_struct *vma) +{ +} +static inline void numa_policy_init (void ) { }
include/linux/mm.h +12 -1
@@ -212,7 +212,8 @@ struct vm_operations_struct {* install a MPOL_DEFAULT policy, nor the task or system default * mempolicy. */ -int (*set_policy)(struct vm_area_struct *vma,struct mempolicy *new); +int (*set_policy)(struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct mempolicy *new);/* * get_policy() op must add reference [mpol_get()] to any policy at
@@ -1232,6 +1233,16 @@ extern int after_bootmem;extern void setup_per_cpu_pageset (void ); +/* +* Address to offset for policy lookup and interleave calculation. +* Placed here because it needs struct vma definition. +*/ +static inline pgoff_t vma_mpol_pgoff (struct vm_area_struct *vma, +unsigned long addr) +{ +return ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; +} +extern void zone_pcp_update (struct zone *zone);/* nommu.c */
include/linux/shared_policy.h +3 -4
@@ -32,9 +32,8 @@ struct shared_policy {extern struct shared_policy *mpol_shared_policy_new (struct address_space *mapping,struct mempolicy *mpol); -extern int mpol_set_shared_policy (struct shared_policy *, -struct vm_area_struct *, -struct mempolicy *); +extern int mpol_set_shared_policy (struct shared_policy *,pgoff_t , +unsigned long ,struct mempolicy *);extern void mpol_free_shared_policy (struct address_space *);extern struct mempolicy *mpol_shared_policy_lookup (struct shared_policy *,unsigned long );
@@ -44,7 +43,7 @@ extern struct mempolicy *mpol_shared_polstruct shared_policy {};static inline int mpol_set_shared_policy (struct shared_policy *info, -struct vm_area_struct *vma, +pgoff_t pgoff,unsigned long sz,struct mempolicy *new) {return -EINVAL ;
mm/shmem.c +9 -7
@@ -1158,7 +1158,7 @@ struct page *shmem_swapin(swp_entry_t en/* Create a pseudo vma that just contains the policy */ pvma.vm_start =0 ; pvma.vm_pgoff = idx; - pvma.vm_ops =NULL ; + pvma.vm_file =NULL ; pvma.vm_policy = spol; page =swapin_readahead (entry, gfp, &pvma,0 );return page;
@@ -1172,7 +1172,7 @@ static struct page *shmem_alloc_page(gfp/* Create a pseudo vma that just contains the policy */ pvma.vm_start =0 ; pvma.vm_pgoff = idx; - pvma.vm_ops =NULL ; + pvma.vm_file =NULL ; pvma.vm_policy =mpol_shared_policy_lookup (sp, idx);/*
@@ -1525,7 +1525,8 @@ static int shmem_fault(struct vm_area_st }#ifdef CONFIG_NUMA -static int shmem_set_policy (struct vm_area_struct *vma,struct mempolicy *new) +static int shmem_set_policy (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct mempolicy *new) {struct address_space *mapping = vma->vm_file->f_mapping;struct shared_policy *sp =mapping_shared_policy (mapping);
@@ -1535,7 +1536,8 @@ static int shmem_set_policy(struct vm_arif (IS_ERR (sp))return PTR_ERR (sp); } -return mpol_set_shared_policy (sp, vma, new); +return mpol_set_shared_policy (sp,vma_mpol_pgoff (vma, start), + (end - start) >>PAGE_SHIFT , new); } static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
@@ -1543,12 +1545,10 @@ static struct mempolicy *shmem_get_polic {struct address_space *mapping = vma->vm_file->f_mapping;struct shared_policy *sp =mapping_shared_policy (mapping); -unsigned long idx;if (!sp)return NULL ;/* == default policy */ - idx = ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; -return mpol_shared_policy_lookup (sp, idx); +return mpol_shared_policy_lookup (sp,vma_mpol_pgoff (vma, addr)); }#endif
@@ -1583,6 +1583,7 @@ static int shmem_mmap(struct file *file,file_accessed (file); vma->vm_ops = &shmem_vm_ops; vma->vm_flags |=VM_CAN_NONLINEAR ; +mpol_set_vma_nosplit (vma);return 0 ; }
@@ -2802,5 +2803,6 @@ int shmem_zero_setup(struct vm_area_strufput (vma->vm_file); vma->vm_file = file; vma->vm_ops = &shmem_vm_ops; +mpol_set_vma_nosplit (vma);return 0 ; }
ipc/shm.c +3 -2
@@ -223,13 +223,14 @@ static int shm_fault(struct vm_area_stru }#ifdef CONFIG_NUMA -static int shm_set_policy (struct vm_area_struct *vma,struct mempolicy *new) +int shm_set_policy (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct mempolicy *new) {struct file *file = vma->vm_file;struct shm_file_data *sfd =shm_file_data (file);int err =0 ;if (sfd->vm_ops->set_policy) - err = sfd->vm_ops->set_policy (vma, new); + err = sfd->vm_ops->set_policy (vma, start, end, new);return err; }
mm/mempolicy.c +93 -26
172 lines not on this page · raw message
fs/sysfs/bin.c +3 -2
@@ -256,7 +256,8 @@ static int bin_access(struct vm_area_str }#ifdef CONFIG_NUMA -static int bin_set_policy (struct vm_area_struct *vma,struct mempolicy *new) +static int bin_set_policy (struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct mempolicy *new) {struct file *file = vma->vm_file;struct bin_buffer *bb = file->private_data;
@@ -271,7 +272,7 @@ static int bin_set_policy(struct vm_area ret =0 ;if (bb->vm_ops->set_policy) - ret = bb->vm_ops->set_policy (vma, new); + ret = bb->vm_ops->set_policy (vma, start, end, new);sysfs_put_active (attr_sd);return ret;
PATCH 5/14 Shared Policy: fix show_numa_maps()
In reply to Lee SchermerhornShared Policy Infrastructure - fix show_numa_maps()
This patch updates the procfs numa_maps display to handle multiple shared policy ranges on a single vma. numa_maps() still uses the procfs task maps infrastructure, but provides wrappers around the maps seq_file ops to handle shared policy "submaps", if any.
This fixes a problem with numa_maps for shared mappings:
Before this [shared policy] patch series, numa_maps could show you different results for shared mappings depending on which task you examined. A task which has installed shared policies on sub-ranges of the shared region will show the policies on the sub-ranges, as the vmas for that task were split when the policies were installed. Another task that shares the region, but didn't install any policies, or installed policies on a different region or set of regions will show a different policy/range or set thereof, based on the VMAs of that task. By displaying the policies directly from the shared policy structure, we now see the same info--the correct effective mempolicy for each address range--from each task that maps the segment.
The patch expands the proc_maps_private struct [#ifdef CONFIG_NUMA] to track the existence of and progress through a submap for the "current" vma. For vmas with shared policy submaps, a new function--get_numa_submap()--in mm/mempolicy.c allocates and populates an array of the policy ranges in the shared policy. To facilitate this, the shared policy struct tracks the number of ranges [sp_nodes] in the tree.
The nm_* numa_map seq_file wrappers pass the range to be displayed to show_numa_map() via the saddr and eaddr members added to the proc_maps_private struct. The patch modifies show_numa_map() to use these members, where appropriate, instead of vm_start, vm_end.
As before, once the internal page size buffer is full, seq_read() suspends the display, drops the mmap_sem and exits the read. During this time the vma list can change. However, even within a single seq_read(), the shared_policy "submap" can be changed by other mappers. We could prevent this by holding the shared policy spin_lock or otherwise holding off other mappers. That would also hold off other tasks faulting in pages, attempting to look up the policy for that offset, unless we convert the lock to reader/writer.
It doesn't seem worth the effort, as the numa_map is only a snap_shot in any case. So, this patch makes a best effort [at least as good as unpatched task map code, I think] to perform a single scan over the address space, displaying the policies and page state/location for policy ranges "snapped" under spin lock into the "submap" array mentioned above.
NOTE: this patch adds a fair bit of code to the numa maps display. If necessary, I can make numa_maps a separately configurable option. E.g., in support of, say, embedded systems that use numa [sh?] and want/need /proc, but don't need numa_maps nor want the overhead.
Documentation/vm/numa_memory_policy.txt | 20 +-- fs/proc/task_mmu.c | 186 +++++++++++++++++++++++++++++++- include/linux/mempolicy.h | 5 include/linux/mm.h | 6 + include/linux/proc_fs.h | 12 ++ include/linux/shared_policy.h | 3 mm/mempolicy.c | 58 +++++++++ 7 files changed, 271 insertions(+), 19 deletions(-)
include/linux/proc_fs.h +12 -0
@@ -286,12 +286,24 @@ static inline struct net *PDE_NET(struct return pde->parent->data; } +struct mpol_range { +unsigned long saddr; +unsigned long eaddr; +}; +struct proc_maps_private {struct pid *pid;struct task_struct *task;#ifdef CONFIG_MMU struct vm_area_struct *tail_vma;#endif + +#ifdef CONFIG_NUMA +struct vm_area_struct *vma;/* preserved over seq_reads */ +unsigned long saddr; +unsigned long eaddr;/* preserved over seq_reads */ +struct mpol_range *range, *ranges;/* preserved ... */ +#endif };#endif /* _LINUX_PROC_FS_H */
include/linux/mm.h +6 -0
@@ -1243,6 +1243,12 @@ static inline pgoff_t vma_mpol_pgoff(strreturn ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; } +static inline pgoff_t vma_mpol_addr (struct vm_area_struct *vma, +pgoff_t pgoff) +{ +return ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ) + vma->vm_start; +} +extern void zone_pcp_update (struct zone *zone);/* nommu.c */
include/linux/mempolicy.h +5 -0
@@ -235,6 +235,11 @@ static inline int vma_migratable(struct return 1; } +struct seq_file ; +extern int show_numa_map (struct seq_file *,void *); +struct mpol_range ; +extern struct mpol_range *get_numa_submap (struct vm_area_struct *); +#else struct mempolicy {};
include/linux/shared_policy.h +2 -1
@@ -26,7 +26,8 @@ struct sp_node {struct shared_policy {struct rb_root root; -spinlock_t lock;/* protects rb tree */ +spinlock_t lock;/* protects rb tree */ +int nr_sp_nodes;/* for numa_maps */ }; extern struct shared_policy *mpol_shared_policy_new(
mm/mempolicy.c +54 -4
96 lines not on this page · raw message
fs/proc/task_mmu.c +182 -4
194 lines not on this page · raw message
Documentation/vm/numa_memory_policy.txt +10 -10
@@ -130,16 +130,16 @@ most general to most specific: task policy, if any, else System Default Policy. The shared policy infrastructure supports different policies on subset - ranges of the shared object. However, Linux still splits the VMA of - the task that installs the policy for each range of distinct policy. - Thus, different tasks that attach to a shared memory object can have - different VMA configurations mapping that one shared object. This - can be seen by examining the /proc/<pid>/numa_maps of tasks sharing - a shared memory region. When one task has installed shared policy on - one or more ranges of the region, the numa_maps of that task will - show different policies than the numa_maps of other tasks mapping the - shared object. However, the installed shared policy with be used for - all pages allocated for the shared object by any of the attached tasks. + ranges of the shared object. However, before Linux 2.6.XX, the kernel + still split the VMA of the task that installed the policy for each + range of distinct policy. Thus, different tasks that attach to a + shared memory segment could have different VMA configurations mapping + that one shared object. This was visible by examining the + /proc/<pid>/numa_maps of tasks sharing the shared memory region. + As of 2.6.XX, Linux no longer splits the VMA that maps a shared object + to install a memory policy on a sub-range of the object. The + /proc/<pid>/numa_maps of all tasks sharing a shared memory region now + show the same set of memory policy ranges. When installing shared policy on a shared object, the virtual address range specified can be viewed as a "direct mapped", linear window onto
PATCH 6/14 Shared Policy: Factor alloc_page_pol routine
In reply to Lee SchermerhornShared Policy Infrastructure - Factor alloc_page_pol routine
Implement alloc_page_pol() to allocate a page given a policy and an offset [for interleaving]. No vma nor addr needed. This function will be used to allocate page_cache pages--e.g., for tmpfs files--given the policy at a given page offset, simplifying the shmem page allocation functions.
Revise alloc_page_vma() to simply call alloc_page_pol() after looking up the vma policy, to eliminate duplicate code. This change rippled into the interleaving functions. I was able to eliminate interleave_nid() by computing the offset at the call sites where it was not already available and calling [modified] offset_il_node() directly.
removed vma arg from offset_il_node(), as it wasn't used and is not available when called from alloc_page_pol().
Note: re: alloc_page_vma() -- can be called w/ vma == NULL via read_swap_cache_async() from try_to_unuse(). Can't compute a page offset in this case. This means that pages read by "swapoff" don't/can't follow vma policy. This is current behavior. Similarly, swapin readahead reads multiple swap pages, almost certainly associated with different tasks, with the vma from the first swap page read--the one that caused the fault. Again, we can't compute the correct policy for those pages, and this is current behavior.
include/linux/gfp.h | 3 + include/linux/mm.h | 12 ++++- mm/hugetlb.c | 10 ++++ mm/mempolicy.c | 107 ++++++++++++++++++++++++++++------------------------ 4 files changed, 81 insertions(+), 51 deletions(-)
include/linux/gfp.h +3 -0
@@ -327,10 +327,13 @@ alloc_pages(gfp_t gfp_mask, unsigned int }extern struct page *alloc_page_vma (gfp_t gfp_mask,struct vm_area_struct *vma,unsigned long addr); +struct mempolicy ; +extern struct page *alloc_page_pol (gfp_t ,struct mempolicy *,pgoff_t );#else #define alloc_pages (gfp_mask, order) \ alloc_pages_node(numa_node_id(), gfp_mask, order)#define alloc_page_vma (gfp_mask, vma, addr) alloc_pages(gfp_mask, 0) +#define alloc_page_pol (gfp_mask, pol, off) alloc_pages(gfp_mask, 0)#endif #define alloc_page (gfp_mask) alloc_pages(gfp_mask, 0)
include/linux/mm.h +10 -2
@@ -1235,15 +1235,23 @@ extern void setup_per_cpu_pageset(void);/* * Address to offset for policy lookup and interleave calculation. -* Placed here because it needs struct vma definition. +* Placed here because it needs struct vma definition and we +* can't easily include mm.h in mempolicy.h, nor can we include +* hugetlb.h here. Thus, the extern below. */ static inline pgoff_t vma_mpol_pgoff (struct vm_area_struct *vma,unsigned long addr) { +extern pgoff_t vma_huge_mpol_offset (struct vm_area_struct *, +unsigned long ); + +if (unlikely (vma->vm_flags &VM_HUGETLB )) +return vma_huge_mpol_offset (vma, addr); +return ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; } -static inline pgoff_t vma_mpol_addr (struct vm_area_struct *vma, +static inline unsigned long vma_mpol_addr (struct vm_area_struct *vma,pgoff_t pgoff) {return ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ) + vma->vm_start;
mm/mempolicy.c +58 -49
176 lines not on this page · raw message
mm/hugetlb.c +10 -0
@@ -230,6 +230,16 @@ pgoff_t linear_hugepage_index(struct vm_ }/* +* As above, given just vma and address. +* For computing huge page offset for interleave mempolicy +*/ +pgoff_t vma_huge_mpol_offset (struct vm_area_struct *vma, +unsigned long address) +{ +return vma_hugecache_offset (hstate_vma (vma), vma, address); +} + +/* * Return the size of the pages allocated when backing a VMA. In the majority * cases this will be same size as used by the page table entries. */
PATCH 7/14 Shared Policy: use shared policy for page cache allocations
In reply to Lee SchermerhornShared Policy Infrastructure - use shared policy for page cache allocations
This patch implements a "get_file_policy()" function, analogous to get_vma_policy(), but for a given file[inode/mapping] at at specified offset, using the shared_policy, if any, in the file's address_space. If no shared policy, returns the process policy of the argument task [to match get_vma_policy() args] or default policy, if no process policy.
Note that for a file policy to exist [on other than shmem segments] the file must currently be mmap()ed into a task's address space with MAP_SHARED, with the policy installed via mbind().
A later patch will hook up the generic file mempolicy vm_ops and define a per cpuset control file to enable this semantic. Default will be same as current behavior-- no policy on shared file mapping.
Details:
Revert [__]page_cache_alloc() to take mapping argument as it once used to. I need that to locate the shared policy. Add pgoff_t argument. Fix up page_cache_alloc() and page_cache_alloc_cold() in pagemap.h and all direct callers of __page_cache_alloc() accordingly.
Modify __page_cache_alloc() to use get_file_policy() and alloc_page_pol(). Again, without generic file mempolicy, this behaves the same as alloc_page_current()
page_cache_alloc*() now take an additional offset/index argument, available at all call sites, to lookup the appropriate policy and to compute interleave node for interleave policy. The patches fixes all in-tree users of the modified interfaces.
Re: interaction with cpusets page spread: if the file has a shared policy structure attached, that policy takes precedence over spreading.
Now that we have get_file_policy() and alloc_page_pol(), we can eliminate another case of a pseudo-vma on the stack and use the new infrastructure to allocate shmem pages. This will be done in subsequent patches.
Re: ceph fs calls to __page_cache_alloc(): these are the only calls where an inode/mapping and page offset/index are not available. As such, they don't seem to be bona fide page cache allocations. So, I've replaced them with direct calls to alloc_page() as this is what page_cache_alloc() evaluated to before this series.
fs/btrfs/compression.c | 4 +-- fs/cachefiles/rdwr.c | 6 +++-- fs/ntfs/file.c | 2 - fs/splice.c | 2 - include/linux/mempolicy.h | 8 +++++++ include/linux/pagemap.h | 18 ++++++++++------ mm/filemap.c | 50 +++++++++++++++++++++++++++++++++++----------- mm/mempolicy.c | 25 +++++++++++++++++++++-- mm/readahead.c | 2 - net/ceph/messenger.c | 2 - net/ceph/pagelist.c | 4 +-- net/ceph/pagevec.c | 2 - 12 files changed, 94 insertions(+), 31 deletions(-)
mm/filemap.c +39 -11
@@ -35,6 +35,8 @@#include <linux/memcontrol.h> #include <linux/mm_inline.h> /* for page_is_file_cache() */ #include <linux/cleancache.h> +#include <linux/mempolicy.h> +#include "internal.h" /*
@@ -472,19 +474,43 @@ int add_to_page_cache_lru(struct page *pEXPORT_SYMBOL_GPL (add_to_page_cache_lru);#ifdef CONFIG_NUMA -struct page *__page_cache_alloc (gfp_t gfp) +/** +* __page_cache_alloc - allocate a page cache page +* @mapping - address_space for which page will be allocated +* @pgoff - page index in mapping -- for mem policy +* @gfp - gfp flags +* +* If the mapping does not contain a shared policy, and page cache spreading +* is enabled for the current context's cpuset, allocate a page from the node +* indicated by page cache spreading. +* +* Otherwise, fetch the memory policy at the indicated pgoff and allocate +* a page according to that policy. Note that if the mapping does not +* have a shared policy, the allocation will use the task policy, if any, +* else the system default policy. +* +* All allocations will use the specified gfp mask. +*/ +struct page *__page_cache_alloc (struct address_space *mapping,pgoff_t pgoff, +gfp_t gfp) { -int n; +struct mempolicy *pol;struct page *page; +int n; -if (cpuset_do_page_mem_spread ()) { +/* +* Consider spreading only if no shared_policy +*/ +if (!mapping->spolicy &&cpuset_do_page_mem_spread ()) {get_mems_allowed (); n =cpuset_mem_spread_node (); page =alloc_pages_exact_node (n, gfp,0 );put_mems_allowed ();return page; - } -return alloc_pages (gfp,0 ); + }else + pol =get_file_policy (mapping, pgoff); + +return alloc_page_pol (gfp, pol, pgoff); }EXPORT_SYMBOL (__page_cache_alloc);#endif
@@ -733,7 +759,7 @@ struct page *find_or_create_page(struct repeat: page =find_lock_page (mapping, index);if (!page) { - page =__page_cache_alloc (gfp_mask); + page =__page_cache_alloc (mapping, index, gfp_mask);if (!page)return NULL ;/*
@@ -951,7 +977,8 @@ grab_cache_page_nowait(struct address_sppage_cache_release (page);return NULL ; } - page =__page_cache_alloc (mapping_gfp_mask (mapping) & ~__GFP_FS); + page =__page_cache_alloc (mapping, index, +mapping_gfp_mask (mapping) & ~__GFP_FS);if (page &&add_to_page_cache_lru (page, mapping, index,GFP_NOFS )) {page_cache_release (page); page =NULL ;
@@ -1182,7 +1209,7 @@ no_cached_page:* Ok, it wasn't cached, so we need to create a new * page.. */ - page =page_cache_alloc_cold (mapping); + page =page_cache_alloc_cold (mapping, index);if (!page) { desc->error = -ENOMEM ; goto out;
@@ -1440,7 +1467,7 @@ static int page_cache_read(struct file *int ret; do { - page = page_cache_alloc_cold(mapping); + page = page_cache_alloc_cold(mapping, offset); if (!page) return -ENOMEM;
@@ -1709,7 +1736,7 @@ static struct page *__read_cache_page(st repeat: page =find_get_page (mapping, index);if (!page) { - page =__page_cache_alloc (gfp | __GFP_COLD); + page =page_cache_alloc_cold (mapping, index);if (!page)return ERR_PTR (-ENOMEM ); err =add_to_page_cache_lru (page, mapping, index,GFP_KERNEL );
@@ -2234,7 +2261,8 @@ repeat:if (likely (page))return page; - page =__page_cache_alloc (mapping_gfp_mask (mapping) & ~gfp_notmask); + page =__page_cache_alloc (mapping, index, +mapping_gfp_mask (mapping) & ~gfp_notmask);if (!page)return NULL ; status = add_to_page_cache_lru(page, mapping, index,
include/linux/pagemap.h +11 -7
@@ -201,22 +201,26 @@ static inline void page_unfreeze_refs(st }#ifdef CONFIG_NUMA -extern struct page *__page_cache_alloc (gfp_t gfp); +extern struct page *__page_cache_alloc (struct address_space *,pgoff_t , +gfp_t );#else -static inline struct page *__page_cache_alloc (gfp_t gfp) +static inline struct page *__page_cache_alloc (struct address_space *mapping, +pgoff_t off,gfp_t gfp) { -return alloc_pages (gfp,0 ); +return alloc_pages (mapping_gfp_mask (mapping)); }#endif -static inline struct page *page_cache_alloc (struct address_space *x) +static inline struct page *page_cache_alloc (struct address_space *mapping, +pgoff_t off) { -return __page_cache_alloc (mapping_gfp_mask (x)); +return __page_cache_alloc (mapping, off,mapping_gfp_mask (mapping)); } -static inline struct page *page_cache_alloc_cold (struct address_space *x) +static inline struct page *page_cache_alloc_cold (struct address_space *mapping, +pgoff_t off) { -return __page_cache_alloc (mapping_gfp_mask (x)|__GFP_COLD); +return __page_cache_alloc (mapping, off,mapping_gfp_mask (mapping) | __GFP_COLD); }typedef int filler_t (void *,struct page *);
fs/splice.c +1 -1
@@ -349,7 +349,7 @@ __generic_file_splice_read(struct file */* * page didn't exist, allocate one. */ - page =page_cache_alloc_cold (mapping); + page =page_cache_alloc_cold (mapping, index);if (!page)break ;
mm/readahead.c +1 -1
@@ -174,7 +174,7 @@ __do_page_cache_readahead(struct addressif (page)continue ; - page =page_cache_alloc_cold (mapping); + page =page_cache_alloc_cold (mapping, page_offset);if (!page)break ; page->index = page_offset;
fs/ntfs/file.c +1 -1
@@ -415,7 +415,7 @@ static inline int __ntfs_grab_cache_page pages[nr] =find_lock_page (mapping, index);if (!pages[nr]) {if (!*cached_page) { - *cached_page =page_cache_alloc (mapping); + *cached_page =page_cache_alloc (mapping, index);if (unlikely (!*cached_page)) { err = -ENOMEM ; goto err_out;
include/linux/mempolicy.h +8 -0
@@ -109,6 +109,8 @@ struct mempolicy { } w; }; +extern struct mempolicy default_policy; +/* * vma memory policy flags */
@@ -191,6 +193,7 @@ extern void mpol_rebind_task(struct taskextern void mpol_rebind_mm (struct mm_struct *mm,nodemask_t *new);extern void mpol_fix_fork_child_flag (struct task_struct *p); +extern struct mempolicy *get_file_policy (struct address_space *,pgoff_t );extern struct zonelist *huge_zonelist (struct vm_area_struct *vma,unsigned long addr,gfp_t gfp_flags,struct mempolicy **mpol,nodemask_t **nodemask);
@@ -321,6 +324,11 @@ static inline bool mempolicy_nodemask_inreturn false; } +static inline struct mempolicy *get_file_policy (struct address_space *,pgoff_t ) +{ +return NULL ; +} +static inline int do_migrate_pages (struct mm_struct *mm,const nodemask_t *from_nodes,const nodemask_t *to_nodes,int flags)
mm/mempolicy.c +23 -2
@@ -1534,8 +1534,29 @@ asmlinkage long compat_sys_mbind(compat_#endif -/* -* get_vma_policy(@task, @vma, @addr) +/** +* get_file_policy - Return effective policy for @mapping at @pgoff +* @mapping - file's address_space that might contain shared policy +* @pgoff - page offset into file/object +* +* Falls back to task or system default policy, as necessary. +*/ +struct mempolicy *get_file_policy (struct address_space *mapping,pgoff_t pgoff) +{ +struct shared_policy *sp = mapping->spolicy; +struct mempolicy *pol =NULL ; + +if (unlikely (sp)) + pol =mpol_shared_policy_lookup (sp, pgoff); +else if (likely (current)) + pol = current->mempolicy; +if (likely (!pol)) + pol = &default_policy; +return pol; +} + +/** +* get_vma_policy * @task - task for fallback if vma policy == default * @vma - virtual memory area whose policy is sought * @addr - address in @vma for shared policy lookup
fs/cachefiles/rdwr.c +4 -2
@@ -258,7 +258,8 @@ static int cachefiles_read_backing_file_ goto backing_page_already_present;if (!newpage) { - newpage =page_cache_alloc_cold (bmapping); + newpage =page_cache_alloc_cold (bmapping, + netpage->index);if (!newpage) goto nomem_monitor; }
@@ -500,7 +501,8 @@ static int cachefiles_read_backing_file( goto backing_page_already_present;if (!newpage) { - newpage =page_cache_alloc_cold (bmapping); + newpage =page_cache_alloc_cold (bmapping, + netpage->index);if (!newpage) goto nomem; }
fs/btrfs/compression.c +2 -2
@@ -474,8 +474,8 @@ static noinline int add_ra_bio_pages(str goto next; } - page =__page_cache_alloc (mapping_gfp_mask (mapping) & - ~__GFP_FS); + page =__page_cache_alloc (mapping, page_index, +mapping_gfp_mask (mapping) & ~__GFP_FS);if (!page)break ;
net/ceph/messenger.c +1 -1
@@ -2111,7 +2111,7 @@ struct ceph_messenger *ceph_messenger_cr/* the zero page is needed if a request is "canceled" while the message * is being written over the socket */ - msgr->zero_page =__page_cache_alloc (GFP_KERNEL | __GFP_ZERO); + msgr->zero_page =alloc_page (GFP_KERNEL | __GFP_ZERO);if (!msgr->zero_page) {kfree (msgr);return ERR_PTR (-ENOMEM );
net/ceph/pagelist.c +2 -2
@@ -33,7 +33,7 @@ static int ceph_pagelist_addpage(structstruct page *page;if (!pl->num_pages_free) { - page =__page_cache_alloc (GFP_NOFS ); + page =alloc_page (GFP_NOFS ); }else { page = list_first_entry(&pl->free_list, struct page, lru);list_del (&page->lru);
@@ -85,7 +85,7 @@ int ceph_pagelist_reserve(struct ceph_pa space = (space +PAGE_SIZE -1 ) >>PAGE_SHIFT ;/* conv to num pages */ while (space > pl->num_pages_free) { -struct page *page =__page_cache_alloc (GFP_NOFS ); +struct page *page =alloc_page (GFP_NOFS );if (!page)return -ENOMEM ;list_add_tail (&page->lru, &pl->free_list);
net/ceph/pagevec.c +1 -1
@@ -69,7 +69,7 @@ struct page **ceph_alloc_page_vector(intif (!pages)return ERR_PTR (-ENOMEM );for (i =0 ; i < num_pages; i++) { - pages[i] =__page_cache_alloc (flags); + pages[i] =alloc_page (flags);if (pages[i] ==NULL ) {ceph_release_page_vector (pages, i);return ERR_PTR (-ENOMEM );
PATCH 8/14 Shared Policy: use alloc_page_pol for swap and shmempages
In reply to Lee SchermerhornShared Policy Infrastructure - use alloc_page_pol() for shmem and swap cache allocations
Now that we have the alloc_page_pol() to allocate a page given a policy, we can use it to "simplify" shmem and swap cache page allocations. This eliminates the need for pseudo-vmas on stack for shmem page allocations and moves us towards a "policy + offset" model for page cache allocations, rather that a "vma + address" model. The vma+address are not [both] available everywhere we would like to do policy-based page allocation, whereas the policy and pgoff usually are. However, this does mean, however, that we need to be aware of mempolicy reference counting in swapin read-ahead.
read_swap_cache_async() and swapin_readahead() have been changed to take a policy and page offset [for interleaving] instead of a vma and address. swapin_readahead() passes the policy and pgoff to read_swap_cache_async() to do the read. read_swap_cache_async() now uses alloc_page_pol() with the policy and offset, instead of alloc_page_vma().
Note that the pgoff used by swapin_readahead() is essentially bogus for all but the first read. This was already the case for the 'address' argument before this patch. With this patch, swapin_readahead() holds pgoff constant to select the same node for each readahead page, in the case of interleave policy. This preserves pre-existing behavior.
shmem_swapin() now uses get_file_policy() directly to look up the shared policy on the shmem pseudo-file which it passes to swapin_readahead(). swapin_readahead() can call read_swap_cache_async() multiple times in a loop before the final tail call. read_swap_cache_async() itself may loop to retry [in case of swapin races?]. To avoid multiple "frees" of the shared policy, swapin_readahead() makes a "conditional unshared" copy of the policy on stack via mpol_cond_assign(). This releases the extra ref for a shared policy, and is effectively a no-op for non-shared policy. Because the copy is non-shared, alloc_page_pol() will not attempt to decrement the reference count.
Note that get_vma_policy() becomes an in-kernel global for use outside of mempolicy.c, like get_file_policy(), to lookup vma based policy for other calls to swapin_readahead(). Again, use of get_vma_policy() balances reference counts with mpol_cond_assign() in swapin_readahead().
include/linux/mempolicy.h | 8 ++++++ include/linux/swap.h | 6 ++-- mm/memory.c | 5 +++ mm/mempolicy.c | 2 - mm/shmem.c | 58 +++++++++++++++------------------------------- mm/swap_state.c | 31 +++++++++++++++++------- mm/swapfile.c | 14 ++++++++--- 7 files changed, 68 insertions(+), 56 deletions(-)
mm/swap_state.c +22 -9
@@ -17,6 +17,7 @@#include <linux/buffer_head.h> #include <linux/backing-dev.h> #include <linux/pagevec.h> +#include <linux/mempolicy.h> #include <linux/migrate.h> #include <linux/page_cgroup.h>
@@ -275,9 +276,11 @@ struct page * lookup_swap_cache(swp_entr* and reading the disk if it is not already cached. * A failure return means that either the page allocation failed or that * the swap entry is no longer in use. +* +* This function will drop any incoming conditional reference on @pol. */ struct page *read_swap_cache_async (swp_entry_t entry,gfp_t gfp_mask, -struct vm_area_struct *vma,unsigned long addr) +struct mempolicy *pol,pgoff_t pgoff) {struct page *found_page, *new_page =NULL ;int err;
@@ -296,7 +299,8 @@ struct page *read_swap_cache_async(swp_e* Get a new page to read into from swap. */ if (!new_page) { - new_page =alloc_page_vma (gfp_mask, vma, addr); + new_page =alloc_page_pol (GFP_HIGHUSER_MOVABLE , + pol, pgoff);if (!new_page)break ;/* Out of memory */ }
@@ -353,8 +357,8 @@ struct page *read_swap_cache_async(swp_e* swapin_readahead - swap in pages in hope we need them soon * @entry: swap entry of this memory * @gfp_mask: memory allocation flags -* @vma: user vma this address belongs to -* @addr: target address for mempolicy +* @pol: mempolicy that controls allocation. +* @pgoff: page offset for interleave policy * * Returns the struct page for entry and addr, after queueing swapin. *
@@ -369,29 +373,38 @@ struct page *read_swap_cache_async(swp_e* Caller must hold down_read on the vma->vm_mm if vma is not NULL. */ struct page *swapin_readahead (swp_entry_t entry,gfp_t gfp_mask, -struct vm_area_struct *vma,unsigned long addr) +struct mempolicy *pol,pgoff_t pgoff) { -int nr_pages; +struct mempolicy mpol;struct page *page;unsigned long offset;unsigned long end_offset; +int nr_pages; + +/* +* make a non-shared copy of pol and release incoming ref, if +* necessary, for read ahead loop and read_swap_cache_async() +* retry loop. +*/ + pol =mpol_cond_copy (&mpol, pol);/* * Get starting offset for readaround, and number of pages to read. * Adjust starting address by readbehind (for NUMA interleave case)? * No, it's very unlikely that swap layout would follow vma layout, * more likely that neighbouring swap pages came from the same node: -* so use the same "addr" to choose the same node for each swap read. +* so use the same "pgoff" to choose the same node for each swap read. */ nr_pages =valid_swaphandles (entry, &offset);for (end_offset = offset + nr_pages; offset < end_offset; offset++) { +/* Ok, do the async read-ahead now */ page =read_swap_cache_async (swp_entry (swp_type (entry), offset), - gfp_mask, vma, addr); + gfp_mask, pol, pgoff);if (!page)break ;page_cache_release (page); }lru_add_drain ();/* Push any new pages onto the LRU now */ -return read_swap_cache_async (entry, gfp_mask, vma, addr); +return read_swap_cache_async (entry, gfp_mask, pol, pgoff); }
include/linux/swap.h +3 -3
@@ -317,9 +317,9 @@ extern void free_page_and_swap_cache(strextern void free_pages_and_swap_cache (struct page **,int );extern struct page *lookup_swap_cache (swp_entry_t );extern struct page *read_swap_cache_async (swp_entry_t ,gfp_t , -struct vm_area_struct *vma,unsigned long addr); +struct mempolicy *,pgoff_t );extern struct page *swapin_readahead (swp_entry_t ,gfp_t , -struct vm_area_struct *vma,unsigned long addr); +struct mempolicy *,pgoff_t );/* linux/mm/swapfile.c */ extern long nr_swap_pages;
@@ -427,7 +427,7 @@ static inline void swapcache_free(swp_en }static inline struct page *swapin_readahead (swp_entry_t swp,gfp_t gfp_mask, -struct vm_area_struct *vma,unsigned long addr) +struct mempolicy *pol,pgoff_t pgoff) {return NULL ; }
mm/mempolicy.c +1 -1
@@ -1571,7 +1571,7 @@ struct mempolicy *get_file_policy(struct* freeing by another task. It is the caller's responsibility to free the * extra reference for shared policies. */ -static struct mempolicy *get_vma_policy (struct task_struct *task, +struct mempolicy *get_vma_policy (struct task_struct *task,struct vm_area_struct *vma,unsigned long addr) {struct mempolicy *pol = task->mempolicy;
include/linux/mempolicy.h +8 -0
@@ -193,6 +193,8 @@ extern void mpol_rebind_task(struct taskextern void mpol_rebind_mm (struct mm_struct *mm,nodemask_t *new);extern void mpol_fix_fork_child_flag (struct task_struct *p); +extern struct mempolicy *get_vma_policy (struct task_struct *, +struct vm_area_struct *,unsigned long );extern struct mempolicy *get_file_policy (struct address_space *,pgoff_t ); extern struct zonelist *huge_zonelist(struct vm_area_struct *vma, unsigned long addr, gfp_t gfp_flags,
@@ -324,6 +326,12 @@ static inline bool mempolicy_nodemask_inreturn false; } +static inline struct mempolicy *get_vma_policy (struct task_struct *task, +struct vm_area_struct *vma,unsigned long addr) +{ +return NULL ; +} +static inline struct mempolicy *get_file_policy (struct address_space *,pgoff_t ) {return NULL ;
mm/swapfile.c +11 -3
@@ -31,6 +31,7 @@#include <linux/syscalls.h> #include <linux/memcontrol.h> #include <linux/poll.h> +#include <linux/mempolicy.h> #include <asm/pgtable.h> #include <asm/tlbflush.h>
@@ -1096,6 +1097,7 @@ static int try_to_unuse(unsigned int typstruct mm_struct *start_mm;unsigned char *swap_map;unsigned char swcount; +struct mempolicy *pol;struct page *page;swp_entry_t entry;unsigned int i =0 ;
@@ -1132,12 +1134,18 @@ static int try_to_unuse(unsigned int typ/* * Get a page for the entry, using the existing swap * cache page if there is one. Otherwise, get a clean -* page and read the swap into it. +* page and read the swap into it. Use dummy policy +* [current task's policy or system default] with swap +* cache index for interleaving to allocate new page. +* Note: read_swap_cache_async() drops reference on policy. +* need to refetch policy for each call. Not a +* performance concern in this loop. */ swap_map = &si->swap_map[i]; entry =swp_entry (type, i); - page =read_swap_cache_async (entry, -GFP_HIGHUSER_MOVABLE ,NULL ,0 ); + pol =get_vma_policy (current,NULL ,0 ); + page =read_swap_cache_async (entry,GFP_HIGHUSER_MOVABLE , + pol, i);if (!page) {/* * Either swap_duplicate() failed because entry
mm/memory.c +4 -1
@@ -2651,9 +2651,12 @@ static int do_swap_page(struct mm_structdelayacct_set_flag (DELAYACCT_PF_SWAPIN ); page =lookup_swap_cache (entry);if (!page) { +struct mempolicy *pol =get_vma_policy (current, vma, address); +pgoff_t pgoff =vma_mpol_pgoff (vma, address); +grab_swap_token (mm);/* Contend for token _before_ read-in */ page =swapin_readahead (entry, -GFP_HIGHUSER_MOVABLE , vma, address); +GFP_HIGHUSER_MOVABLE , pol, pgoff);if (!page) {/* * Back out if somebody else faulted in this pte
mm/shmem.c +19 -39
98 lines not on this page · raw message
PATCH 9/14 Shared Policy: per cpuset huge file policy control
In reply to Lee SchermerhornShared Policy Infrastructure - add cpuset control for huge page shared policy
Add a per cpuset "shared_huge_policy" control file to enable shared hugetlbfs file policy for tasks in the cpuset. Default is disabled, resulting in the old behavior--i.e., we continue to use any task private vma policy, falling back to task or system default policy if none, on address ranges backed by shared hugetlbfs file mappings. The "shared_huge_policy" file depends on CONFIG_NUMA.
This patch adapts and renames the cpuset_update_task_spread_flag() function and related mechanisms to update the cpusetcontrolled flags of the tasks in the cpuset when "shared_huge_policy" is changes.
Why a "per cpuset" control? cpusets are numa-aware task groupings and memory policy is a numa concept. Applications that need/want shared hugetlbfs file policy can be grouped in a cpuset with this feature enabled, while other applications in other cpusets need not see this feature. Alternatively, the behavior may be enabled for the entire system by setting the control file in the top level cpuset.
This use of cpusets to control NUMA-related behavior, vs. a separate controller, might be worth a side discussion?
The default may be overridden--e.g., to enabled--on the kernel command line using the "shared_huge_policy_default" parameter. When cpusets are configured, this policy sets the default value of "shared_huge_policy" for the top cpuset, which is then inherited by all subsequently created descendant cpusets. When cpusets are not configured, this parameter sets the "shared_huge_policy_enabled" flag for the init process, which is then inherited by all descendant processes.
A subsequent patch "hooks up" the shared file .{set|get}_policy vm_ops to install or lookup a shared policy on a memory mapped hugetlbfs file if the capability has been enabled for the caller's cpuset, or for the system in the case of no cpusets.
include/linux/cpuset.h | 27 +++++++++++++++++ include/linux/sched.h | 20 ++++++++++++ include/linux/shared_policy.h | 4 ++ kernel/cpuset.c | 66 +++++++++++++++++++++++++++++++++++------- mm/mempolicy.c | 26 +++++++++++++++- 5 files changed, 131 insertions(+), 12 deletions(-)
include/linux/sched.h +20 -0
@@ -1455,6 +1455,7 @@ struct task_struct {#ifdef CONFIG_NUMA struct mempolicy *mempolicy;/* Protected by alloc_lock */ short il_next; +short shared_huge_policy_enabled;#endif atomic_t fs_excl;/* holding fs exclusive resources */ struct rcu_head rcu;
@@ -1870,6 +1871,25 @@ extern void sched_exec(void);extern void sched_clock_idle_sleep_event (void );extern void sched_clock_idle_wakeup_event (u64 delta_ns); +#ifdef CONFIG_NUMA +static inline void set_shared_huge_policy_enabled (struct task_struct *tsk, +int val) +{ + tsk->shared_huge_policy_enabled = !!val; +} +static inline int shared_huge_policy_enabled (struct task_struct *tsk) +{ +return tsk->shared_huge_policy_enabled; +} + +#else +static void set_shared_huge_policy_enabled (struct task_struct *tsk,int val) { } +static int shared_huge_policy_enabled (struct task_struct *tsk) +{ +return 0 ; +} +#endif +#ifdef CONFIG_HOTPLUG_CPU extern void move_task_off_dead_cpu (int dead_cpu,struct task_struct *p);extern void idle_task_exit (void );
kernel/cpuset.c +55 -11
174 lines not on this page · raw message
include/linux/cpuset.h +27 -0
@@ -128,6 +128,28 @@ static inline void set_mems_allowed(node task_unlock(current); } +#ifdef CONFIG_NUMA +static inline int add_shared_xxx_policy_file (struct cgroup *cg, +struct cgroup_subsys *ss, +struct cftype *cft) +{ +return cgroup_add_file (cg, ss, cft); +} + +#else +/* +* don't expose "shared_huge_policy" file if !NUMA +*/ +static inline int add_shared_xxx_policy_file (struct cgroup *cg, +struct cgroup_subsys *ss, +struct cftype *cft) +{ +return 0 ; +} +#endif + +extern void __init cpuset_init_shared_huge_policy (int dflt); +#else /* !CONFIG_CPUSETS */ static inline int cpuset_init (void ) {return 0 ; }
@@ -242,6 +264,11 @@ static inline void put_mems_allowed(void { } +static inline void cpuset_init_shared_huge_policy (int dflt) +{ + current->shared_file_policy_enabled = dflt; +} +#endif /* !CONFIG_CPUSETS */ #endif /* _LINUX_CPUSET_H */
mm/mempolicy.c +25 -1
@@ -2079,7 +2079,25 @@ int __mpol_equal(struct mempolicy *a, st/* * Shared memory backing store policy support. -* +*/ + +/* +* default state of per cpuset shared_huge_policy enablement +*/ +int shared_huge_policy_default;/* default: disabled */ + +static int __init setup_shared_huge_policy_default (char *str) +{ +int ret, val; + ret =get_option (&str, &val); +if (!ret) +return 0 ; + shared_huge_policy_default = !!val; +return 1 ; +} +__setup ("shared_huge_policy_default=" , setup_shared_huge_policy_default); + +/* * Remember policies even when nobody has shared memory mapped. * The policies are kept in Red-Black tree linked from the inode. * They are protected by the sp->lock spinlock, which should be held
@@ -2423,6 +2441,12 @@ void __init numa_policy_init(void)if (do_set_mempolicy (MPOL_INTERLEAVE ,0 , &interleave_nodes))printk ("numa_policy_init: interleaving failed\n" ); + +/* +* initialize per cpuset shared huge policy enablement +* from default. +*/ +cpuset_init_shared_huge_policy (shared_huge_policy_default); }/* Reset policy of current process to default */
include/linux/shared_policy.h +4 -0
@@ -30,6 +30,8 @@ struct shared_policy {int nr_sp_nodes;/* for numa_maps */ }; +extern int shared_file_policy_default; +extern struct shared_policy *mpol_shared_policy_new (struct address_space *mapping,struct mempolicy *mpol);
@@ -43,6 +45,8 @@ extern struct mempolicy *mpol_shared_polstruct shared_policy {}; +#define shared_file_policy_default 0 +static inline int mpol_set_shared_policy (struct shared_policy *info,pgoff_t pgoff,unsigned long sz,struct mempolicy *new)
PATCH 10/14 Shared Policy: Add hugepage shmem policy vm_ops
In reply to Lee SchermerhornShared Policy Infrastructure - Add hugepage shmem policy vm_ops
Hugetlb shmem segments have always had a shared policy structure in their 'info' struct. With this series, like all file mappings on a CONFIG_NUMA kernel, the segments' address_space structures now have a pointer to a dynamically allocated shared_policy struct. The shared policy struct will only be allocated when a shared policy is installed. However, currently, the hugetlbfs vm_operations do not support mempolicy set/get ops to install and lookup shared policies.
This patch hooks up the hugepage shmem segment's {set|get}_policy vm_ops so that shmem segments created with the SHM_HUGETLB flag will install policies specified via the mbind() syscall into the shared policy of the shared segment. This capability is possible now that hugetlb pages are faulted in on demand.
Restore the shmem_{set|get}_policy prototypes to mm.h--removed back ~23-rc1-mm2 :-(.
The shared policy infrastructure maintains memory policies on "base page size" ranges. To ensure that policies installed on a hugetlb shmem segment cover entire huge pages, this patch enhances do_mbind() to enforce huge page alignment if the policy range starts within a hugetlb segment. The enforcement is down in check_range() because we need the vma to determine whether or not the range starts in a hugetlb segment.
We could just silently round the start address down to a hugepage alignment. This would be safe and, some might think, convenient for the application programmer, but it is inconsistent with the treatement of base page ranges which MUST be page aligned.
Set VMPOL_F_NOSPLIT in hugetlbfs_file_mmap() to prevent splitting of hugetlbfs vmas when applying mempolicy to subset range of the segment.
This patch depends on the numa_maps fixes and related shared policy infrastructure clean up earlier in the series to prevent hangs when displaying [via cat] the numa_maps of a task that has attached a huge page shmem segment.
Documentation/vm/numa_memory_policy.txt | 16 +++++++++------- fs/hugetlbfs/inode.c | 1 + include/linux/mm.h | 6 ++++++ mm/hugetlb.c | 4 ++++ mm/mempolicy.c | 19 +++++++++++++++++-- mm/shmem.c | 20 ++++++++++++++++++-- 6 files changed, 55 insertions(+), 11 deletions(-)
mm/hugetlb.c +4 -0
@@ -2143,6 +2143,10 @@ const struct vm_operations_struct hugetl .fault = hugetlb_vm_op_fault, .open = hugetlb_vm_op_open, .close = hugetlb_vm_op_close, +#ifdef CONFIG_NUMA + .set_policy = shmem_set_policy, + .get_policy = shmem_get_policy, +#endif }; static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
mm/mempolicy.c +17 -2
@@ -581,6 +581,15 @@ check_range(struct mm_struct *mm, unsign first =find_vma (mm, start);if (!first)return ERR_PTR (-EFAULT ); + +/* +* need vma for hugetlb check +*/ +if (is_vm_hugetlb_page (first)) { +if (start & ~HPAGE_MASK ) +return ERR_PTR (-EINVAL ); + } + prev =NULL ;for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {if (!(flags &MPOL_MF_DISCONTIG_OK )) {
@@ -589,8 +598,14 @@ check_range(struct mm_struct *mm, unsignif (prev && prev->vm_end < vma->vm_start)return ERR_PTR (-EFAULT ); } -if (!is_vm_hugetlb_page (vma) && - ((flags &MPOL_MF_STRICT ) || +if (is_vm_hugetlb_page (vma)) { +/* +* round end up to hugepage alignment if +* it falls in a hugetlb vma. +*/ +if (end < vma->vm_end) + end = (end +HPAGE_MASK ) &HPAGE_MASK ; + }else if (((flags &MPOL_MF_STRICT ) || ((flags & (MPOL_MF_MOVE |MPOL_MF_MOVE_ALL )) &&vma_migratable (vma)))) {unsigned long endvma = vma->vm_end;
include/linux/mm.h +6 -0
@@ -748,6 +748,10 @@ extern void show_free_areas(void);int shmem_lock (struct file *file,int lock,struct user_struct *user);struct file *shmem_file_setup (const char *name,loff_t size,unsigned long flags);int shmem_zero_setup (struct vm_area_struct *); +int shmem_set_policy (struct vm_area_struct *vma, +unsigned long start,unsigned long end,struct mempolicy *new); +struct mempolicy *shmem_get_policy (struct vm_area_struct *vma, +unsigned long addr);#ifndef CONFIG_MMU extern unsigned long shmem_get_unmapped_area(struct file *file,
@@ -1251,6 +1255,8 @@ static inline pgoff_t vma_mpol_pgoff(strreturn ((addr - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; } +// TODO: is this OK for huge pages? Or do I need inverse of +// vma_huge_mpol_offset? static inline unsigned long vma_mpol_addr (struct vm_area_struct *vma,pgoff_t pgoff) {
mm/shmem.c +18 -2
@@ -1505,7 +1505,7 @@ static int shmem_fault(struct vm_area_st }#ifdef CONFIG_NUMA -static int shmem_set_policy (struct vm_area_struct *vma,unsigned long start, +int shmem_set_policy (struct vm_area_struct *vma,unsigned long start,unsigned long end,struct mempolicy *new) {struct address_space *mapping = vma->vm_file->f_mapping;
@@ -1520,7 +1520,7 @@ static int shmem_set_policy(struct vm_ar (end - start) >> PAGE_SHIFT, new); } -static struct mempolicy *shmem_get_policy (struct vm_area_struct *vma, +struct mempolicy *shmem_get_policy (struct vm_area_struct *vma,unsigned long addr) {struct address_space *mapping = vma->vm_file->f_mapping;
@@ -1530,6 +1530,7 @@ static struct mempolicy *shmem_get_policreturn NULL ;/* == default policy */ return mpol_shared_policy_lookup(sp, vma_mpol_pgoff(vma, addr)); } +#define HAVE_SHMEM_XET_POLICY #endif int shmem_lock (struct file *file,int lock,struct user_struct *user)
@@ -2700,6 +2701,21 @@ out:#endif /* CONFIG_SHMEM */ +#ifndef HAVE_SHMEM_XET_POLICY +int shmem_set_policy (struct vm_area_struct *vma, +struct mempolicy *new) +{ +return 0 ; +} + +struct mempolicy *shmem_get_policy (struct vm_area_struct *vma, +unsigned long addr) +{ +return NULL ; +} +#endif + +/* common code */ /**
fs/hugetlbfs/inode.c +1 -0
@@ -93,6 +93,7 @@ static int hugetlbfs_file_mmap(struct fi*/ vma->vm_flags |=VM_HUGETLB |VM_RESERVED ; vma->vm_ops = &hugetlb_vm_ops; +mpol_set_vma_nosplit (vma);if (vma->vm_pgoff & ~(huge_page_mask (h) >>PAGE_SHIFT ))return -EINVAL ;
Documentation/vm/numa_memory_policy.txt +9 -7
@@ -114,13 +114,15 @@ most general to most specific: by any task, will obey the shared policy. As of 2.6.28, only shared memory segments, created by shmget() or - mmap(MAP_ANONYMOUS|MAP_SHARED), support shared policy. When shared - policy support was added to Linux, the associated data structures were - added to hugetlbfs shmem segments. At the time, hugetlbfs did not - support allocation at fault time--a.k.a lazy allocation--so hugetlbfs - shmem segments were never "hooked up" to the shared policy support. - Although hugetlbfs segments now support lazy allocation, their support - for shared policy has not been completed. + mmap(MAP_ANONYMOUS|MAP_SHARED), support shared policy. Prior to + 2.6.XX, shared segments backed by huge pages did not support shared + policy. In fact, different tasks could install different policies + for the same ranges of a shared huge page segment. The policy of + any given page was determined by which task touched it first--always + the case for local allocation. As of 2.6.XX, Linux supports shared + policies on huge pages shared segments, just as for regular sized + pages. To preserve existing behavior for applications that might + care, this new behavior must be enabled on a per-cpuset basis. As mentioned above [re: VMA policies], allocations of page cache pages for regular files mmap()ed with MAP_SHARED ignore any VMA
PATCH 11/14 Shared Policy: fix migration of private mappings
In reply to Lee SchermerhornShared Policy Infrastructure - fix migration of private mappings
This patch is in preparation for subsequent patch to add shared policy {get|set}_policy ops to generic files. At that point, we'll have "memory objects" that can be mapped shared in some tasks and have shared policy applied, but mapped private in other tasks. Unlikely, perhaps, be we need to handle it in some fashion.
Now, if we installed a vma policy on the private mapping, it will be ignored for cache pages. If we specified MPOL_MF_MOVE_ALL on the vma range, we don't want the private mapping's vma policy to affect the cache pages--especially when the file has a shared policy. Rather, we want only to migrate any private, anon copies that the task has "COWed". This will preserve existing behavior for private mappings.
Define a new internal flag--MPOL_MF_MOVE_ANON_ONLY--that we set in check_range() for private mappings of files with shared policy. Then, migrate_page_add() will skip cache [non-anon] pages when this flag is set.
May also be able to use this flag to force unmapping of anon pages that may be shared with relatives during automigrate on internode task migration--e.g., by using:
MPOL_MF_MOVE_ALL|MPOL_MF_MOVE_ANON_ONLY
But, that's the subject of a different patch series.
mm/mempolicy.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
mm/mempolicy.c +17 -3
@@ -101,6 +101,7 @@#define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0)/* Skip checks for continuous vmas */ #define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1)/* Invert check for nodemask */ #define MPOL_MF_STATS (MPOL_MF_INTERNAL << 2)/* Gather statistics */ +#define MPOL_MF_MOVE_ANON_ONLY (MPOL_MF_INTERNAL << 3)static struct kmem_cache *policy_cache;static struct kmem_cache *sp_cache;
@@ -609,13 +610,24 @@ check_range(struct mm_struct *mm, unsign ((flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) && vma_migratable(vma)))) {unsigned long endvma = vma->vm_end; +unsigned long anononly =0 ;if (endvma > end) endvma = end;if (vma->vm_start > start) start = vma->vm_start; + +/* +* Non-SHARED file mapping with shared policy installed: +* migrate only COWed anon pages as shared pages follow +* the shared policy. +*/ +if (vma->vm_file && !(vma->vm_flags &VM_SHARED ) && + vma->vm_file->f_mapping->spolicy) + anononly =MPOL_MF_MOVE_ANON_ONLY ; + err =check_pgd_range (vma, start, endvma, nodes, - flags, private); + flags|anononly, private);if (err) { first =ERR_PTR (err);break ;
@@ -977,9 +989,11 @@ static void migrate_page_add(struct page unsigned long flags) {/* -* Avoid migrating a page that is shared with others. +* Avoid migrating a file backed page in a private mapping or +* a page that is shared with others. */ -if ((flags &MPOL_MF_MOVE_ALL ) ||page_mapcount (page) ==1 ) { +if ((!(flags &MPOL_MF_MOVE_ANON_ONLY ) ||PageAnon (page)) && + ((flags &MPOL_MF_MOVE_ALL ) ||page_mapcount (page) ==1 )) {if (!isolate_lru_page (page)) {list_add_tail (&page->lru, pagelist); inc_zone_page_state(page, NR_ISOLATED_ANON +
PATCH 12/14 Shared Policy: mapped file policy persistence model
In reply to Lee SchermerhornShared Policy Infrastructure - define mapped file policy persistence model
This patch starts the process of supporting optional shared policy on shared memory mapped files.
Mapped file policy applies to a range of a linearly memory mapped file mmap()ed with the MAP_SHARED flag. The mapping serves as a linear window onto the mapped range. Retain the shared policy until the last shared mapping is removed, so that cached files do not retain policies installed by defunct applications.
Use rcu deferred free to close possible race between last shared mapper removing the shared policy and non-mmap page cache access.
Shmem segments [including SHM_HUGETLB segments] look like shared mapped files to the shared policy infrastructure. The policy persistence model for shmem segments is that once a shared policy is applied, it remains as long as the segment exists. To retain this behavior, define a shared policy persistence flag--SPOL_F_PERSIST--and set this flag when allocating a shared policy for a shmem segment.
Now, we can push the freeing any shmem/hugetlbfs persistent shared policy when the segment is deleted down into the fs-independent inode cleanup path.
fs/hugetlbfs/inode.c | 1 fs/inode.c | 7 ++++ include/linux/shared_policy.h | 11 ++++-- mm/mempolicy.c | 70 ++++++++++++++++++++++++++++++++---------- mm/mmap.c | 11 ++++++ mm/shmem.c | 5 --- 6 files changed, 81 insertions(+), 24 deletions(-)
fs/hugetlbfs/inode.c +0 -1
@@ -663,7 +663,6 @@ static struct inode *hugetlbfs_alloc_inostatic void hugetlbfs_destroy_inode (struct inode *inode) {hugetlbfs_inc_free_inodes (HUGETLBFS_SB (inode->i_sb)); -mpol_free_shared_policy (inode->i_mapping);kmem_cache_free (hugetlbfs_inode_cachep,HUGETLBFS_I (inode)); }
fs/inode.c +7 -0
@@ -25,6 +25,7 @@#include <linux/async.h> #include <linux/posix_acl.h> #include <linux/ima.h> +#include <linux/shared_policy.h> /* * This is needed for the following functions:
@@ -305,6 +306,12 @@ void inode_init_once(struct inode *inode#ifdef CONFIG_FSNOTIFY INIT_HLIST_HEAD (&inode->i_fsnotify_marks);#endif +/* +* free any shared policy +*/ +if ((inode->i_mode &S_IFMT ) ==S_IFREG ) +mpol_free_shared_policy (inode->i_mapping); + }EXPORT_SYMBOL (inode_init_once);
mm/shmem.c +1 -4
@@ -1516,6 +1516,7 @@ int shmem_set_policy(struct vm_area_struif (IS_ERR (sp))return PTR_ERR (sp); } + sp->sp_flags |=SPOL_F_PERSIST ;return mpol_set_shared_policy (sp,vma_mpol_pgoff (vma, start), (end - start) >>PAGE_SHIFT , new); }
@@ -2417,10 +2418,6 @@ static struct inode *shmem_alloc_inode(sstatic void shmem_destroy_inode (struct inode *inode) { -if ((inode->i_mode &S_IFMT ) ==S_IFREG ) { -/* only struct inode is valid if it's an inline symlink */ -mpol_free_shared_policy (inode->i_mapping); - }kmem_cache_free (shmem_inode_cachep,SHMEM_I (inode)); }
mm/mmap.c +11 -0
@@ -198,6 +198,17 @@ static void __remove_shared_vm_struct(stif (vma->vm_flags &VM_SHARED ) mapping->i_mmap_writable--; +if (!mapping->i_mmap_writable) { +/* +* shared mmap()ed file policy persistence model: +* remove policy when removing last shared mapping, +* unless marked as persistent--e.g., shmem +*/ +struct shared_policy *sp =mapping_shared_policy (mapping); +if (sp && !(sp->sp_flags &SPOL_F_PERSIST )) +mpol_free_shared_policy (mapping); + } +flush_dcache_mmap_lock (mapping);if (unlikely (vma->vm_flags &VM_NONLINEAR ))list_del_init (&vma->shared.vm_set.list);
include/linux/shared_policy.h +8 -3
@@ -4,6 +4,7 @@#include <linux/fs.h> #include <linux/spinlock.h> #include <linux/rbtree.h> +#include <linux/rcupdate.h> /* * Tree of shared policies for a shared memory regions and memory
@@ -25,11 +26,15 @@ struct sp_node { };struct shared_policy { -struct rb_root root; -spinlock_t lock;/* protects rb tree */ -int nr_sp_nodes;/* for numa_maps */ +struct rb_root root; +spinlock_t lock;/* protects rb tree, nr_sp_nodes */ +int nr_sp_nodes;/* for numa_maps */ +int sp_flags;/* persistence, ... */ +struct rcu_head sp_rcu;/* deferred reclaim */ }; +#define SPOL_F_PERSIST 0x01/* for shmem use */ +extern int shared_file_policy_default; extern struct shared_policy *mpol_shared_policy_new(
mm/mempolicy.c +54 -16
125 lines not on this page · raw message
PATCH 13/14 Shared Policy: per cpuset mapped file policy control
In reply to Lee SchermerhornShared Policy Infrastracture - per cpuset mapped file policy control
As for shared hugetlbfs file mappings, add a per cpuset "shared_file_policy" control file to enable shared file policy for tasks in the cpuset. Default is disabled, resulting in the old behavior--i.e., we continue to ignore mbind() on address ranges backed by shared file mappings. The "shared_file_policy" file depends on CONFIG_NUMA.
Why "per cpuset"? cpusets are numa-aware task groupings and memory policy is a numa concept. Applications that need/want shared file policy can be grouped in a cpuset with this feature enabled, while other applications in other cpusets need not see this feature.
The default may be overridden--e.g., to enabled--on the kernel command line using the "shared_file_policy_default" parameter. When cpusets are configured, this policy sets the default value of "shared_file_policy" for the top cpuset, which is then inherited by all subsequently created descendant cpusets. When cpusets are not configured, this parameter sets the "shared_file_policy_enabled" flag for the init process, which is then inherited by all descendant processes.
A subsequent patch will "hook up" generic file .{set|get}_policy vm_ops to install a shared policy on a memory mapped file if the capability has been enabled for the caller's cpuset, or for the system in the case of no cpusets.
include/linux/cpuset.h | 6 ++++++ include/linux/sched.h | 19 ++++++++++++++++++- include/linux/shared_policy.h | 2 ++ kernel/cpuset.c | 42 +++++++++++++++++++++++++++++++++++++++++- mm/mempolicy.c | 20 +++++++++++++++++++- 5 files changed, 86 insertions(+), 3 deletions(-)
include/linux/sched.h +18 -1
@@ -1455,7 +1455,8 @@ struct task_struct {#ifdef CONFIG_NUMA struct mempolicy *mempolicy;/* Protected by alloc_lock */ short il_next; -short shared_huge_policy_enabled; + short shared_huge_policy_enabled:1; + short shared_file_policy_enabled:1;#endif atomic_t fs_excl;/* holding fs exclusive resources */ struct rcu_head rcu;
@@ -1882,12 +1883,28 @@ static inline int shared_huge_policy_ena return tsk->shared_huge_policy_enabled; } +static inline void set_shared_file_policy_enabled (struct task_struct *tsk, +int val) +{ + tsk->shared_file_policy_enabled = !!val; +} +static inline int shared_file_policy_enabled (struct task_struct *tsk) +{ +return tsk->shared_file_policy_enabled; +} +#else static void set_shared_huge_policy_enabled (struct task_struct *tsk,int val) { }static int shared_huge_policy_enabled (struct task_struct *tsk) {return 0 ; } + +static void set_shared_file_policy_enabled (struct task_struct *tsk,int val) { } +static int shared_file_policy_enabled (struct task_struct *tsk) +{ +return 0 ; +}#endif #ifdef CONFIG_HOTPLUG_CPU
kernel/cpuset.c +41 -1
108 lines not on this page · raw message
include/linux/cpuset.h +6 -0
@@ -149,6 +149,7 @@ static inline int add_shared_xxx_policy_#endif extern void __init cpuset_init_shared_huge_policy (int dflt); +extern void __init cpuset_init_shared_file_policy (int dflt);#else /* !CONFIG_CPUSETS */
@@ -268,6 +269,11 @@ static inline void cpuset_init_shared_hu { current->shared_file_policy_enabled = dflt; } + +static inline void cpuset_init_shared_file_policy (int dflt) +{ + current->shared_file_policy_enabled = dflt; +}#endif /* !CONFIG_CPUSETS */
mm/mempolicy.c +19 -1
@@ -2131,6 +2131,23 @@ static int __init setup_shared_huge_poli__setup ("shared_huge_policy_default=" , setup_shared_huge_policy_default);/* +* default state of per cpuset shared_file_policy_enablement +*/ +int shared_file_policy_default; + +static int __init setup_shared_file_policy_default (char *str) +{ +int ret, val; + ret =get_option (&str, &val); +if (!ret) +return 0 ; + shared_file_policy_default = !!val; +return 1 ; +} +__setup ("shared_file_policy_default=" , setup_shared_file_policy_default); + + +/* * Remember policies even when nobody has shared memory mapped. * The policies are kept in Red-Black tree linked from the inode. * They are protected by the sp->lock spinlock, which should be held
@@ -2510,10 +2527,11 @@ void __init numa_policy_init(void)printk ("numa_policy_init: interleaving failed\n" );/* -* initialize per cpuset shared huge policy enablement +* initialize per cpuset shared [huge] file policy enablement * from default. */ cpuset_init_shared_huge_policy (shared_huge_policy_default); +cpuset_init_shared_file_policy (shared_file_policy_default); }/* Reset policy of current process to default */
include/linux/shared_policy.h +2 -0
@@ -36,6 +36,7 @@ struct shared_policy {#define SPOL_F_PERSIST 0x01/* for shmem use */ extern int shared_file_policy_default; +extern int shared_file_policy_default; extern struct shared_policy *mpol_shared_policy_new( struct address_space *mapping,
@@ -51,6 +52,7 @@ extern struct mempolicy *mpol_shared_polstruct shared_policy {};#define shared_file_policy_default 0 +#define shared_file_policy_default 0 static inline int mpol_set_shared_policy(struct shared_policy *info, pgoff_t pgoff, unsigned long sz,
PATCH 14/14 Shared Policy: add generic file set/get policy vm ops
In reply to Lee SchermerhornShared Policy Infrastructure - add generic file set/get policy vm ops
Add set/get policy vm ops to generic_file_vm_ops in support of mmap()ed file memory policies. This patch effectively "hooks up" shared file mappings to the NUMA shared policy infrastructure. However, a task will only use a shared policy if it has been enabled
by the task's cpuset's "shared_file_policy" control file. Default is
disabled--i.e., existing behaviors.
To ensure that applications do not get surprised by unrelated applications applying shared policy to their files, allow only the owner of a file to apply shared policy. Note that we could make this enforcement conditional on a per-cpuset "shared_policy_enforce_ownership" file.
NOTE: may be able to unify with shmem_{get|set}_policy.
Updated numa_memory_policy.txt to document this behavior.
Documentation/vm/numa_memory_policy.txt | 47 ++++++++++++++++++----------- mm/filemap.c | 51 ++++++++++++++++++++++++++++++++ mm/mempolicy.c | 35 +++++++++++++++++---- mm/shmem.c | 4 +- 4 files changed, 110 insertions(+), 27 deletions(-)
mm/filemap.c +51 -0
@@ -513,6 +513,47 @@ struct page *__page_cache_alloc(struct areturn alloc_page_pol (gfp, pol, pgoff); }EXPORT_SYMBOL (__page_cache_alloc); + +static int generic_file_set_policy (struct vm_area_struct *vma, +unsigned long start,unsigned long end, +struct mempolicy *new) +{ +struct address_space *mapping; +struct shared_policy *sp; +int ret; + + mapping = vma->vm_file->f_mapping; + +/* +* Only owner or privileged task can set shared policy on shared +* regular file mappings. +*/ +if (!is_owner_or_cap (mapping->host)) +return -EPERM ; + + sp = mapping->spolicy; +if (!sp) { + sp =mpol_shared_policy_new (mapping,NULL ); +if (IS_ERR (sp)) +return PTR_ERR (sp); + } + + ret =mpol_set_shared_policy (sp,vma_mpol_pgoff (vma, start), + (end - start) >>PAGE_SHIFT , new); +if (!ret) +mpol_set_vma_nosplit (vma); +return ret; +} + +static struct mempolicy * +generic_file_get_policy (struct vm_area_struct *vma,unsigned long addr) +{ +struct shared_policy *sp = vma->vm_file->f_mapping->spolicy; +if (!sp) +return NULL ; + +return mpol_shared_policy_lookup (sp,vma_mpol_pgoff (vma, addr)); +}#endif static int __sleep_on_page_lock (void *word)
@@ -1686,6 +1727,10 @@ EXPORT_SYMBOL(filemap_fault);const struct vm_operations_struct generic_file_vm_ops = { .fault = filemap_fault, +#ifdef CONFIG_NUMA + .set_policy = generic_file_set_policy, + .get_policy = generic_file_get_policy, +#endif };/* This is used for a general mmap of a disk file */
@@ -1699,6 +1744,12 @@ int generic_file_mmap(struct file * filefile_accessed (file); vma->vm_ops = &generic_file_vm_ops; vma->vm_flags |=VM_CAN_NONLINEAR ; + +/* +* shared policies and non-linear mappings are mutually exclusive +*/ +if ((vma->vm_flags &VM_SHARED ) &&mapping_shared_policy (mapping)) +mpol_set_vma_nosplit (vma);return 0 ; }
mm/mempolicy.c +28 -7
@@ -638,18 +638,38 @@ check_range(struct mm_struct *mm, unsignreturn first; } +/* +* helper functions for deciding whether to split vmas on set_policy +* or to use the vma policy op for set/get. Note that we only get +* into these if the vma represents a shared, linear, file mapping, +* including shmem. +*/ static bool vma_is_shared_linear (struct vm_area_struct *vma) {return ((vma->vm_flags & (VM_SHARED |VM_NONLINEAR )) ==VM_SHARED ); } -static bool mpol_nosplit_vma (struct vm_area_struct *vma) +static bool has_set_policy_op (struct vm_area_struct *vma) +{ +return (vma->vm_ops && vma->vm_ops->set_policy); +} + +/* +* We don't split vmas on set_policy if VMPOL_F_NOSPLIT is set or we have +* a shared, linear mapping, AND a set_policy() vm_op. VMPOL_F_NOSPLIT +* will be set for shmem segments and files mmap()ed SHARED if a shared +* policy has previously been applied to this file. +*/ +static int mpol_nosplit_vma (struct vm_area_struct *vma) {if (vma->vm_mpol_flags &VMPOL_F_NOSPLIT )return true; -if (vma_is_shared_linear (vma) && - vma->vm_ops && vma->vm_ops->set_policy) { +if (vma_is_shared_linear (vma) &&has_set_policy_op (vma) && +shared_file_policy_enabled (current)) { +/* +* short circuit future queries. +*/ vma->vm_mpol_flags |=VMPOL_F_NOSPLIT ;return true; }
@@ -701,7 +721,8 @@ static int policy_vma(struct vm_area_str/* Step 2: apply policy to a range and do splits. */ static int mbind_range (struct mm_struct *mm,unsigned long start, -unsigned long end,struct mempolicy *new_pol) +unsigned long end,struct mempolicy *new_pol, +unsigned long flags) {struct vm_area_struct *next;struct vm_area_struct *prev;
@@ -925,7 +946,7 @@ static long do_get_mempolicy(int *policyup_read (&mm->mmap_sem);return -EFAULT ; } -if (vma->vm_ops && vma->vm_ops->get_policy) +if (mpol_use_get_op (vma)) pol = vma->vm_ops->get_policy (vma, addr);else pol = vma->vm_policy;
@@ -1244,7 +1265,7 @@ static long do_mbind(unsigned long startif (!IS_ERR (vma)) {int nr_failed =0 ; - err =mbind_range (mm, start, end, new); + err =mbind_range (mm, start, end, new, flags);if (!list_empty (&pagelist)) { nr_failed = migrate_pages(&pagelist, new_vma_page,
@@ -1611,7 +1632,7 @@ struct mempolicy *get_vma_policy(structif (vma) {/* -* use get_policy op, if any, for shared mappings +* use get_policy op, if applicable, for shared mappings */ if (mpol_use_get_op (vma)) { struct mempolicy *vpol = vma->vm_ops->get_policy(vma,
mm/shmem.c +2 -2
@@ -219,7 +219,7 @@ static const struct file_operations shmestatic const struct inode_operations shmem_inode_operations;static const struct inode_operations shmem_dir_inode_operations;static const struct inode_operations shmem_special_inode_operations; -static const struct vm_operations_struct shmem_vm_ops; +const struct vm_operations_struct shmem_vm_ops;static struct backing_dev_info shmem_backing_dev_info__read_mostly = { .ra_pages =0 ,/* No readahead */
@@ -2526,7 +2526,7 @@ static const struct super_operations shm .put_super = shmem_put_super, }; -static const struct vm_operations_struct shmem_vm_ops = { +const struct vm_operations_struct shmem_vm_ops = { .fault = shmem_fault, #ifdef CONFIG_NUMA .set_policy = shmem_set_policy,
Documentation/vm/numa_memory_policy.txt +29 -18
71 lines not on this page · raw message
Quoted 3 lines
I'll announce this series and the automatic/lazy migration series to follow on lkml, linux-mm, ... However, I'll limit the actual posting to linux-numa to avoid spamming the other lists.
Thanks for posting Lee. Yes I think the patchkit is very interesting.
Quick comment on the list: I think linux-mm is better as the main list where all the MM hackers are; linux-numa is really mostly about the user space code.
-Andi
Quoted 10 lines · Andi Kleen
Quoted 3 lines
I'll announce this series and the automatic/lazy migration series to follow on lkml, linux-mm, ... However, I'll limit the actual posting to linux-numa to avoid spamming the other lists.
Thanks for posting Lee. Yes I think the patchkit is very interesting.
Quick comment on the list: I think linux-mm is better as the main list where all the MM hackers are; linux-numa is really mostly about the user space code.
Andi:
I will announce the patches there with links to the threads. If this moves beyond RFC we can move it to -mm if you like. I used linux-numa because I thought that was most appropriate, thinking it more general than just user space code.
Lee