Re: [PATCH 1/3] hugetlbfs: Allow the creation of files suitable forMAP_PRIVATE on the vfs internal mount V3

From: David Rientjes
Date: Fri Aug 14 2009 - 15:19:19 EST


On Fri, 14 Aug 2009, Eric B Munson wrote:

> There are two means of creating mappings backed by huge pages:
>
> 1. mmap() a file created on hugetlbfs
> 2. Use shm which creates a file on an internal mount which essentially
> maps it MAP_SHARED
>
> The internal mount is only used for shared mappings but there is very
> little that stops it being used for private mappings. This patch extends
> hugetlbfs_file_setup() to deal with the creation of files that will be
> mapped MAP_PRIVATE on the internal hugetlbfs mount. This extended API is
> used in a subsequent patch to implement the MAP_HUGETLB mmap() flag.
>
> Signed-off-by: Eric Munson <ebmunson@xxxxxxxxxx>
> ---
> Changes from V2:
> Rebase to newest linux-2.6 tree
> Use base 10 value for HUGETLB_SHMFS_INODE instead of hex
>
> Changes from V1:
> Rebase to newest linux-2.6 tree
>
> fs/hugetlbfs/inode.c | 22 ++++++++++++++++++----
> include/linux/hugetlb.h | 10 +++++++++-
> ipc/shm.c | 3 ++-
> 3 files changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 941c842..361f536 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -506,6 +506,13 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, uid_t uid,
> 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.
> + */
> mpol_shared_policy_init(&info->policy, NULL);
> switch (mode & S_IFMT) {
> default:
> @@ -930,12 +937,19 @@ static struct file_system_type hugetlbfs_fs_type = {
>
> static struct vfsmount *hugetlbfs_vfsmount;
>
> -static int can_do_hugetlb_shm(void)
> +static int can_do_hugetlb_shm(int creat_flags)
> {
> - return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
> + if (!(creat_flags & HUGETLB_SHMFS_INODE))
> + return 0;

That should be

if (creat_flags != HUGETLB_SHMFS_INODE)
return 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/