numa api: Add shared memory support
Subsystems (3)
PATCH 25/57 numa api: Add shared memory support
From: Andi Kleen <[email protected]>
Add support to tmpfs and hugetlbfs to support NUMA API. Shared memory is a bit of a special case for NUMA policy. Normally policy is associated to VMAs or to processes, but for a shared memory segment you really want to share the policy. The core NUMA API has code for that, this patch adds the necessary changes to tmpfs and hugetlbfs.
First it changes the custom swapping code in tmpfs to follow the policy set via VMAs.
It is also useful to have a "backing store" of policy that saves the policy even when nobody has the shared memory segment mapped. This allows command line tools to pre configure policy, which is then later used by programs.
Note that hugetlbfs needs more changes - it is also required to switch it to lazy allocation, otherwise the prefault prevents mbind() from working.
---
25-akpm/fs/hugetlbfs/inode.c | 46 ++++++++++++++++- 25-akpm/include/linux/hugetlb.h | 13 ++++ 25-akpm/include/linux/shmem_fs.h | 2 25-akpm/ipc/shm.c | 4 + 25-akpm/mm/shmem.c | 105 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 165 insertions(+), 5 deletions(-)
fs/hugetlbfs/inode.c renamed from fs/hugetlbfs/inode.c~numa-api-shared-memory-support +45 -1
@@ -377,6 +377,7 @@ static struct inode *hugetlbfs_get_inode inode =new_inode (sb);if (inode) { +struct hugetlbfs_inode_info *info; inode->i_mode = mode; inode->i_uid = uid; inode->i_gid = gid;
@@ -385,6 +386,8 @@ static struct inode *hugetlbfs_get_inode inode->i_mapping->a_ops = &hugetlbfs_aops; inode->i_mapping->backing_dev_info =&hugetlbfs_backing_dev_info; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; + info =HUGETLBFS_I (inode); +mpol_shared_policy_init (&info->policy);switch (mode &S_IFMT ) {default :init_special_inode (inode, mode, dev);
@@ -512,6 +515,33 @@ static void hugetlbfs_put_super(struct s } } +static kmem_cache_t *hugetlbfs_inode_cachep; + +static struct inode *hugetlbfs_alloc_inode (struct super_block *sb) +{ +struct hugetlbfs_inode_info *p; + + p =kmem_cache_alloc (hugetlbfs_inode_cachep,SLAB_KERNEL ); +if (!p) +return NULL ; +return &p->vfs_inode; +} + +static void init_once (void *foo,kmem_cache_t *cachep,unsigned long flags) +{ +struct hugetlbfs_inode_info *ei = (struct hugetlbfs_inode_info *)foo; + +if ((flags & (SLAB_CTOR_VERIFY |SLAB_CTOR_CONSTRUCTOR )) == +SLAB_CTOR_CONSTRUCTOR ) +inode_init_once (&ei->vfs_inode); +} + +static void hugetlbfs_destroy_inode (struct inode *inode) +{ +mpol_free_shared_policy (&HUGETLBFS_I (inode)->policy); +kmem_cache_free (hugetlbfs_inode_cachep,HUGETLBFS_I (inode)); +} +static struct address_space_operations hugetlbfs_aops = { .readpage = hugetlbfs_readpage, .prepare_write = hugetlbfs_prepare_write,
@@ -543,6 +573,8 @@ static struct inode_operations hugetlbfs };static struct super_operations hugetlbfs_ops = { + .alloc_inode = hugetlbfs_alloc_inode, + .destroy_inode = hugetlbfs_destroy_inode, .statfs = hugetlbfs_statfs, .drop_inode = hugetlbfs_drop_inode, .put_super = hugetlbfs_put_super,
@@ -763,9 +795,16 @@ static int __init init_hugetlbfs_fs(voidint error;struct vfsmount *vfsmount; + hugetlbfs_inode_cachep =kmem_cache_create ("hugetlbfs_inode_cache" , +sizeof (struct hugetlbfs_inode_info ), +0 ,SLAB_RECLAIM_ACCOUNT , + init_once,NULL ); +if (hugetlbfs_inode_cachep ==NULL ) +return -ENOMEM ; + error =register_filesystem (&hugetlbfs_fs_type);if (error) -return error; + goto out; vfsmount =kern_mount (&hugetlbfs_fs_type);
@@ -775,11 +814,16 @@ static int __init init_hugetlbfs_fs(void } error =PTR_ERR (vfsmount); + + out: +if (error) +kmem_cache_destroy (hugetlbfs_inode_cachep);return error; } static void __exit exit_hugetlbfs_fs(void) { +kmem_cache_destroy (hugetlbfs_inode_cachep);unregister_filesystem (&hugetlbfs_fs_type); }
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~numa-api-shared-memory-support +13 -0
@@ -3,6 +3,8 @@#ifdef CONFIG_HUGETLB_PAGE +#include <linux/mempolicy.h> +struct ctl_table ;static inline int is_vm_hugetlb_page (struct vm_area_struct *vma)
@@ -104,6 +106,17 @@ struct hugetlbfs_sb_info {spinlock_t stat_lock; }; + +struct hugetlbfs_inode_info { +struct shared_policy policy; +struct inode vfs_inode; +}; + +static inline struct hugetlbfs_inode_info *HUGETLBFS_I (struct inode *inode) +{ + return container_of(inode, struct hugetlbfs_inode_info, vfs_inode); +} +static inline struct hugetlbfs_sb_info *HUGETLBFS_SB (struct super_block *sb) {return sb->s_fs_info;
include/linux/shmem_fs.h renamed from include/linux/shmem_fs.h~numa-api-shared-memory-support +2 -0
@@ -2,6 +2,7 @@#define __SHMEM_FS_H#include <linux/swap.h> +#include <linux/mempolicy.h> /* inode in-kernel data */
@@ -15,6 +16,7 @@ struct shmem_inode_info {unsigned long alloced;/* data pages allocated to file */ unsigned long swapped;/* subtotal assigned to swap */ unsigned long flags; +struct shared_policy policy;struct list_head list;struct inode vfs_inode; };
ipc/shm.c renamed from ipc/shm.c~numa-api-shared-memory-support +4 -0
@@ -163,6 +163,10 @@ static struct vm_operations_struct shm_v .open = shm_open, /* callback for a new vm-area open */ .close = shm_close, /* callback for when the vm-area is released */ .nopage = shmem_nopage, +#ifdef CONFIG_NUMA + .set_policy = shmem_set_policy, + .get_policy = shmem_get_policy, +#endif };static int newseg (key_t key,int shmflg,size_t size)
mm/shmem.c renamed from mm/shmem.c~numa-api-shared-memory-support +101 -4
167 lines not on this page · raw message
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>