Re: [PATCH] Correct alignment of huge page requests.

From: Hillf Danton
Date: Sat Mar 03 2012 - 22:51:12 EST


On Fri, Mar 2, 2012 at 10:58 AM, Steven Truelove
<steven.truelove@xxxxxxxxxxx> wrote:
> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. ÂModified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. ÂChanged newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
>
> Signed-off-by: Steven Truelove <steven.truelove@xxxxxxxxxxx>

Acked-by: Hillf Danton <dhillf@xxxxxxxxx>

> ---
> Âfs/hugetlbfs/inode.c  Â|  12 ++++++++----
> Âinclude/linux/hugetlb.h | Â Â3 ++-
> Âipc/shm.c        |  Â2 +-
> Âmm/mmap.c        |  Â6 +++---
> Â4 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 1e85a7a..a97b7cc 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
> Â Â Â Âreturn capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
> Â}
>
> -struct file *hugetlb_file_setup(const char *name, size_t size,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âvm_flags_t acctflag,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct user_struct **user, int creat_flags)
> Â{
> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> Â Â Â Âstruct path path;
> Â Â Â Âstruct dentry *root;
> Â Â Â Âstruct qstr quick_string;
> + Â Â Â struct hstate *hstate;
> + Â Â Â int num_pages;
>
> Â Â Â Â*user = NULL;
> Â Â Â Âif (!hugetlbfs_vfsmount)
> @@ -967,10 +969,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> Â Â Â Âif (!inode)
> Â Â Â Â Â Â Â Âgoto out_dentry;
>
> + Â Â Â hstate = hstate_inode(inode);
> + Â Â Â size += addr & ~huge_page_mask(hstate);
> + Â Â Â num_pages = ALIGN(size, huge_page_size(hstate)) >>
> + Â Â Â Â Â Â Â Â Â Â Â huge_page_shift(hstate);
> Â Â Â Âerror = -ENOMEM;
> - Â Â Â if (hugetlb_reserve_pages(inode, 0,
> - Â Â Â Â Â Â Â Â Â Â Â size >> huge_page_shift(hstate_inode(inode)), NULL,
> - Â Â Â Â Â Â Â Â Â Â Â acctflag))
> + Â Â Â if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
> Â Â Â Â Â Â Â Âgoto out_inode;
>
> Â Â Â Âd_instantiate(path.dentry, inode);
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index d9d6c86..4b9e59d 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -164,7 +164,8 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
>
> Âextern const struct file_operations hugetlbfs_file_operations;
> Âextern const struct vm_operations_struct hugetlb_vm_ops;
> -struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t size, vm_flags_t acct,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct user_struct **user, int creat_flags);
> Âint hugetlb_get_quota(struct address_space *mapping, long delta);
> Âvoid hugetlb_put_quota(struct address_space *mapping, long delta);
> diff --git a/ipc/shm.c b/ipc/shm.c
> index b76be5b..406c5b2 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -482,7 +482,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
> Â Â Â Â Â Â Â Â/* hugetlb_file_setup applies strict accounting */
> Â Â Â Â Â Â Â Âif (shmflg & SHM_NORESERVE)
> Â Â Â Â Â Â Â Â Â Â Â Âacctflag = VM_NORESERVE;
> - Â Â Â Â Â Â Â file = hugetlb_file_setup(name, size, acctflag,
> + Â Â Â Â Â Â Â file = hugetlb_file_setup(name, 0, size, acctflag,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â&shp->mlock_user, HUGETLB_SHMFS_INODE);
> Â Â Â Â} else {
> Â Â Â Â Â Â Â Â/*
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3f758c7..4bf211a 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1099,9 +1099,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
> Â Â Â Â Â Â Â Â * A dummy user value is used because we are not locking
> Â Â Â Â Â Â Â Â * memory so no accounting is necessary
> Â Â Â Â Â Â Â Â */
> - Â Â Â Â Â Â Â len = ALIGN(len, huge_page_size(&default_hstate));
> - Â Â Â Â Â Â Â file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &user, HUGETLB_ANONHUGE_INODE);
> + Â Â Â Â Â Â Â file = hugetlb_file_setup(HUGETLB_ANON_FILE, addr, len,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â VM_NORESERVE, &user,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â HUGETLB_ANONHUGE_INODE);
> Â Â Â Â Â Â Â Âif (IS_ERR(file))
> Â Â Â Â Â Â Â Â Â Â Â Âreturn PTR_ERR(file);
> Â Â Â Â}
> --
> 1.7.3.4
>
> --
> 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/
>
>
--
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/