Skip to content

Commit c6a9182

Browse files
mjkravetztorvalds
authored andcommitted
hugetlbfs: add minimum size tracking fields to subpool structure
hugetlbfs allocates huge pages from the global pool as needed. Even if the global pool contains a sufficient number pages for the filesystem size at mount time, those global pages could be grabbed for some other use. As a result, filesystem huge page allocations may fail due to lack of pages. Applications such as a database want to use huge pages for performance reasons. hugetlbfs filesystem semantics with ownership and modes work well to manage access to a pool of huge pages. However, the application would like some reasonable assurance that allocations will not fail due to a lack of huge pages. At application startup time, the application would like to configure itself to use a specific number of huge pages. Before starting, the application can check to make sure that enough huge pages exist in the system global pools. However, there are no guarantees that those pages will be available when needed by the application. What the application wants is exclusive use of a subset of huge pages. Add a new hugetlbfs mount option 'min_size=<value>' to indicate that the specified number of pages will be available for use by the filesystem. At mount time, this number of huge pages will be reserved for exclusive use of the filesystem. If there is not a sufficient number of free pages, the mount will fail. As pages are allocated to and freeed from the filesystem, the number of reserved pages is adjusted so that the specified minimum is maintained. This patch (of 4): Add a field to the subpool structure to indicate the minimimum number of huge pages to always be used by this subpool. This minimum count includes allocated pages as well as reserved pages. If the minimum number of pages for the subpool have not been allocated, pages are reserved up to this minimum. An additional field (rsv_hpages) is used to track the number of pages reserved to meet this minimum size. The hstate pointer in the subpool is convenient to have when reserving and unreserving the pages. Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Aneesh Kumar <aneesh.kumar@linux.vnet.ibm.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 195b0c6 commit c6a9182

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/linux/hugetlb.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ struct mmu_gather;
2222
struct hugepage_subpool {
2323
spinlock_t lock;
2424
long count;
25-
long max_hpages, used_hpages;
25+
long max_hpages; /* Maximum huge pages or -1 if no maximum. */
26+
long used_hpages; /* Used count against maximum, includes */
27+
/* both alloced and reserved pages. */
28+
struct hstate *hstate;
29+
long min_hpages; /* Minimum huge pages or -1 if no minimum. */
30+
long rsv_hpages; /* Pages reserved against global pool to */
31+
/* sasitfy minimum size. */
2632
};
2733

2834
struct resv_map {

mm/hugetlb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ struct hugepage_subpool *hugepage_new_subpool(long nr_blocks)
7777
{
7878
struct hugepage_subpool *spool;
7979

80-
spool = kmalloc(sizeof(*spool), GFP_KERNEL);
80+
spool = kzalloc(sizeof(*spool), GFP_KERNEL);
8181
if (!spool)
8282
return NULL;
8383

8484
spin_lock_init(&spool->lock);
8585
spool->count = 1;
8686
spool->max_hpages = nr_blocks;
87-
spool->used_hpages = 0;
8887

8988
return spool;
9089
}

0 commit comments

Comments
 (0)