Mel Gorman wrote: > The get_huge_pages() API is a close-to-kernel interface for the direct > allocation of hugepages. This forces the caller to deal with alignment and > fallback to base pages where suitable. For the casual user of hugepages > that does not care for such things, this patch adds get_hugepage_region(). > It allocates regions of memory that are backed by hugepages where possible > but callers are not required to align their length and can request fallback > to base pages. > > Signed-off-by: Mel Gorman <[EMAIL PROTECTED]> > --- > Makefile | 5 +- > alloc.c | 58 +++++++++++++++++++- > hugetlbfs.h | 23 +++++++- > man/get_huge_pages.3 | 2 + > man/get_hugepage_region.3 | 79 ++++++++++++++++++++++++++ > tests/Makefile | 4 +- > tests/get_hugepage_region.c | 129 > +++++++++++++++++++++++++++++++++++++++++++ > tests/run_tests.sh | 3 + > version.lds | 2 + > 9 files changed, 300 insertions(+), 5 deletions(-) > create mode 100644 man/get_hugepage_region.3 > create mode 100644 tests/get_hugepage_region.c > > diff --git a/Makefile b/Makefile > index 4554154..40c8c45 100644 > --- a/Makefile > +++ b/Makefile > @@ -8,7 +8,8 @@ BIN_OBJ_DIR=obj > INSTALL_BIN = hugectl hugeedit hugeadm pagesize > INSTALL_HEADERS = hugetlbfs.h > INSTALL_MAN1 = pagesize.1 > -INSTALL_MAN3 = get_huge_pages.3 gethugepagesizes.3 getpagesizes.3 > +INSTALL_MAN3 = get_huge_pages.3 get_hugepage_region.3 \ > + gethugepagesizes.3 getpagesizes.3 > INSTALL_MAN7 = libhugetlbfs.7 > INSTALL_MAN8 = hugectl.8 hugeedit.8 hugeadm.8 > LDSCRIPT_TYPES = B BDT > @@ -379,7 +380,9 @@ install-man: > gzip -f $(DESTDIR)$(MANDIR3)/$$x; \ > done > rm -f $(DESTDIR)$(MANDIR3)/free_huge_pages.3.gz > + rm -f $(DESTDIR)$(MANDIR3)/free_hugepage_region.3.gz > ln -s get_huge_pages.3.gz $(DESTDIR)$(MANDIR3)/free_huge_pages.3.gz > + ln -s get_hugepage_region.3.gz > $(DESTDIR)$(MANDIR3)/free_hugepage_region.3.gz > for x in $(INSTALL_MAN7); do \ > $(INSTALL) -m 444 man/$$x $(DESTDIR)$(MANDIR7); \ > gzip -f $(DESTDIR)$(MANDIR7)/$$x; \ > diff --git a/alloc.c b/alloc.c > index 6e026c5..74bb5a4 100644 > --- a/alloc.c > +++ b/alloc.c > @@ -35,7 +35,7 @@ static void *fallback_base_pages(size_t len, ghp_t flags) > { > int fd; > void *buf; > - DEBUG("get_huge_pages: Falling back to base pages\n"); > + DEBUG("get_hugepage_region: Falling back to base pages\n"); > > /* > * Map /dev/zero instead of MAP_ANONYMOUS avoid VMA mergings. Freeing > @@ -78,6 +78,10 @@ void *get_huge_pages(size_t len, ghp_t flags) > void *buf; > int heap_fd; > > + /* Catch an altogether-too easy typo */ > + if (flags & GHR_MASK) > + ERROR("Improper use of GHR_* in get_huge_pages()\n"); > + > /* Create a file descriptor for the new region */ > heap_fd = hugetlbfs_unlinked_fd(); > if (heap_fd < 0) { > @@ -174,3 +178,55 @@ void free_huge_pages(void *ptr) > > fclose(fd); > } > + > +/** > + * get_hugepage_region - Allocate an amount of memory backed by huge pages > + * > + * len: Size of the region to allocate > + * flags: Flags specifying the behaviour of the function > + * > + * This function allocates a region of memory backed by huge pages. Care > should > + * be taken when using this function as a drop-in replacement for malloc() as > + * memory can be wasted if the length is not hugepage-aligned. This function > + * is more relaxed than get_huge_pages() in that it allows fallback to small > + * pages when requested. > + */ > +void *get_hugepage_region(size_t len, ghr_t flags) > +{ > + size_t aligned_len, wastage; > + void *buf; > + > + /* Catch an altogether-too easy typo */ > + if (flags & GHP_MASK) > + ERROR("Improper use of GHP_* in get_hugepage_region()\n"); > Should this be GHR instead of GHP in the if check and error message?
Jon ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel