Eric,

Eric B Munson wrote:
> When the kernel supports MAP_HUGETLB use it for requesting
> a huge page backed area instead of creating a file descriptor.
> 
> Signed-off-by: Eric B Munson <[email protected]>
> ---
>  alloc.c |   42 ++++++++++++++++++++++++++++--------------
>  1 files changed, 28 insertions(+), 14 deletions(-)
> 
> diff --git a/alloc.c b/alloc.c
> index a7d37e5..3ba4813 100644
> --- a/alloc.c
> +++ b/alloc.c
> @@ -77,7 +77,7 @@ static void *fallback_base_pages(size_t len, ghp_t flags)
>  void *get_huge_pages(size_t len, ghp_t flags)
>  {
>       void *buf;
> -     int buf_fd;
> +     int buf_fd = -1;
>       int saved_error;
>       int mmap_reserve = __hugetlb_opts.no_reserve ? MAP_NORESERVE : 0;
>  
> @@ -85,30 +85,44 @@ void *get_huge_pages(size_t len, ghp_t flags)
>       if (flags & GHR_MASK)
>               ERROR("Improper use of GHR_* in get_huge_pages()\n");
>  
> -     /* Create a file descriptor for the new region */
> -     buf_fd = hugetlbfs_unlinked_fd();
> -     if (buf_fd < 0) {
> -             WARNING("Couldn't open hugetlbfs file for %zd-sized buffer\n",
> -                             len);
> -             return NULL;
> +     if (__hugetlb_opts.map_hugetlb) {

I wonder if this should also depend on gethugepageize() == 
kernel_default_hugepage_size()?  If the user has set the 
HUGETLB_DEFAULT_PAGE_SIZE environment variable s/he may expect get_huge_pages() 
to use the size s/he has specified.  (Apologies for not thinking of this the 
first time around.)

> +             /* Because we can use MAP_HUGETLB, we simply mmap the region */
> +             buf = mmap(NULL, len, PROT_READ|PROT_WRITE,
> +                     MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|mmap_reserve,
> +                     0, 0);
> +     } else {
> +             /* Create a file descriptor for the new region */
> +             buf_fd = hugetlbfs_unlinked_fd();

...snip...

-Andrew Hastings
 Cray Inc.

------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to