From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Eric B Munson <ebmunson@us.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-man@vger.kernel.org, mtk.manpages@gmail.com,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/3] Add MAP_LARGEPAGE for mmaping pseudo-anonymous huge page regions
Date: Wed, 12 Aug 2009 08:45:09 +0300 [thread overview]
Message-ID: <84144f020908112245g139564erbe56bac668a68bef@mail.gmail.com> (raw)
In-Reply-To: <a45eb555ca7d9e23e5eb051e27f757ae70a6b0c5.1249999949.git.ebmunson@us.ibm.com>
Hi Eric,
On Wed, Aug 12, 2009 at 1:13 AM, Eric B Munson<ebmunson@us.ibm.com> wrote:
> This patch adds a flag for mmap that will be used to request a huge
> page region that will look like anonymous memory to user space. This
> is accomplished by using a file on the internal vfsmount. MAP_LARGEPAGE
> is a modifier of MAP_ANONYMOUS and so must be specified with it. The
> region will behave the same as a MAP_ANONYMOUS region using small pages.
>
> Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
I would love to see something like this in the kernel. Huge pages are
useful for garbage collection and JIT text in the userspace but
unfortunately obtaining them is a real PITA at the moment.
Is there any way to drop the
CAP_IPC_LOCK/in_group_p(hugetlbfs_shm_group) requirement, btw? That
would make huge pages even more accessible to user-space virtual
machines.
Pekka
> ---
> include/asm-generic/mman-common.h | 1 +
> include/linux/hugetlb.h | 7 +++++++
> mm/mmap.c | 16 ++++++++++++++++
> 3 files changed, 24 insertions(+), 0 deletions(-)
>
> diff --git a/include/asm-generic/mman-common.h b/include/asm-generic/mman-common.h
> index 3b69ad3..60b6be7 100644
> --- a/include/asm-generic/mman-common.h
> +++ b/include/asm-generic/mman-common.h
> @@ -19,6 +19,7 @@
> #define MAP_TYPE 0x0f /* Mask for type of mapping */
> #define MAP_FIXED 0x10 /* Interpret addr exactly */
> #define MAP_ANONYMOUS 0x20 /* don't use a file */
> +#define MAP_LARGEPAGE 0x40 /* create a large page mapping */
>
> #define MS_ASYNC 1 /* sync memory asynchronously */
> #define MS_INVALIDATE 2 /* invalidate the caches */
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 78b6ddf..b84361c 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -109,12 +109,19 @@ static inline void hugetlb_report_meminfo(struct seq_file *m)
>
> #endif /* !CONFIG_HUGETLB_PAGE */
>
> +#define HUGETLB_ANON_FILE "anon_hugepage"
> +
> enum {
> /*
> * The file will be used as an shm file so shmfs accounting rules
> * apply
> */
> HUGETLB_SHMFS_INODE = 0x01,
> + /*
> + * The file is being created on the internal vfs mount and shmfs
> + * accounting rules do not apply
> + */
> + HUGETLB_ANONHUGE_INODE = 0x02,
> };
>
> #ifdef CONFIG_HUGETLBFS
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 34579b2..c2c729a 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -29,6 +29,7 @@
> #include <linux/rmap.h>
> #include <linux/mmu_notifier.h>
> #include <linux/perf_counter.h>
> +#include <linux/hugetlb.h>
>
> #include <asm/uaccess.h>
> #include <asm/cacheflush.h>
> @@ -954,6 +955,21 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
> if (mm->map_count > sysctl_max_map_count)
> return -ENOMEM;
>
> + if (flags & MAP_LARGEPAGE) {
> + if (file)
> + return -EINVAL;
> +
> + /*
> + * VM_NORESERVE is used because the reservations will be
> + * taken when vm_ops->mmap() is called
> + */
> + len = ALIGN(len, huge_page_size(&default_hstate));
> + file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
> + HUGETLB_ANONHUGE_INODE);
> + if (IS_ERR(file))
> + return -ENOMEM;
> + }
> +
> /* Obtain the address to map to. we verify (or select) it and ensure
> * that it represents a valid section of the address space.
> */
> --
> 1.6.3.2
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2009-08-12 5:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-11 22:13 [PATCH 0/3] Add pseudo-anonymous huge page mappings Eric B Munson
2009-08-11 22:13 ` [PATCH 1/3] hugetlbfs: Allow the creation of files suitable for MAP_PRIVATE on the vfs internal mount Eric B Munson
2009-08-11 22:13 ` [PATCH 2/3] Add MAP_LARGEPAGE for mmaping pseudo-anonymous huge page regions Eric B Munson
2009-08-11 22:13 ` [PATCH 3/3] Add MAP_LARGEPAGE example to vm/hugetlbpage.txt Eric B Munson
[not found] ` <a45eb555ca7d9e23e5eb051e27f757ae70a6b0c5.1249999949.git.ebmunson-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-12 5:07 ` [PATCH 2/3] Add MAP_LARGEPAGE for mmaping pseudo-anonymous huge page regions Michael Kerrisk
2009-08-12 9:08 ` Eric B Munson
2009-08-12 5:45 ` Pekka Enberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84144f020908112245g139564erbe56bac668a68bef@mail.gmail.com \
--to=penberg@cs.helsinki.fi \
--cc=akpm@linux-foundation.org \
--cc=ebmunson@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mtk.manpages@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).