| 1 | /* |
| 2 | * libhugetlbfs - Easy use of Linux hugepages |
| 3 | * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public License |
| 7 | * as published by the Free Software Foundation; either version 2.1 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * This file should only contain definitions of functions, data types, and |
| 22 | * constants which are part of the published libhugetlfs API. Functions |
| 23 | * exported here must also be listed in version.lds. |
| 24 | */ |
| 25 | |
| 26 | #ifndef _HUGETLBFS_H |
| 27 | #define _HUGETLBFS_H |
| 28 | |
| 29 | #define HUGETLBFS_MAGIC 0x958458f6 |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | long gethugepagesize(void); |
| 36 | int gethugepagesizes(long pagesizes[], int n_elem); |
| 37 | int getpagesizes(long pagesizes[], int n_elem); |
| 38 | int hugetlbfs_test_path(const char *mount); |
| 39 | const char *hugetlbfs_find_path(void); |
| 40 | const char *hugetlbfs_find_path_for_size(long page_size); |
| 41 | int hugetlbfs_unlinked_fd(void); |
| 42 | int hugetlbfs_unlinked_fd_for_size(long page_size); |
| 43 | |
| 44 | #define PF_LINUX_HUGETLB 0x100000 |
| 45 | |
| 46 | /* |
| 47 | * Direct hugepage allocation flags and types |
| 48 | * |
| 49 | * GHP_DEFAULT - Use the default hugepage size to back the region |
| 50 | */ |
| 51 | typedef unsigned long ghp_t; |
| 52 | #define GHP_DEFAULT ((ghp_t)0x01UL) |
| 53 | #define GHP_MASK (GHP_DEFAULT) |
| 54 | |
| 55 | /* Direct alloc functions for hugepages */ |
| 56 | void *get_huge_pages(size_t len, ghp_t flags); |
| 57 | void free_huge_pages(void *ptr); |
| 58 | |
| 59 | /* |
| 60 | * Region alloc flags and types |
| 61 | * |
| 62 | * GHR_DEFAULT - Use a combination of flags deemed to be a sensible default |
| 63 | * by the current implementation of the library |
| 64 | * GHR_FALLBACK - Use the default hugepage size if possible but fallback to |
| 65 | * smaller pages if necessary |
| 66 | * GHR_STRICT - Use hugepages of some size or return NULL |
| 67 | * GHP_COLOR - Use bytes wasted due to alignment to offset the buffer |
| 68 | * by a random cache line. This gives better average |
| 69 | * performance with many buffers |
| 70 | */ |
| 71 | typedef unsigned long ghr_t; |
| 72 | #define GHR_STRICT ((ghr_t)0x10000000U) |
| 73 | #define GHR_FALLBACK ((ghr_t)0x20000000U) |
| 74 | #define GHR_COLOR ((ghr_t)0x40000000U) |
| 75 | #define GHR_DEFAULT (GHR_FALLBACK|GHR_COLOR) |
| 76 | |
| 77 | #define GHR_MASK (GHR_FALLBACK|GHR_STRICT|GHR_COLOR) |
| 78 | |
| 79 | /* Allocation functions for regions backed by hugepages */ |
| 80 | void *get_hugepage_region(size_t len, ghr_t flags); |
| 81 | void free_hugepage_region(void *ptr); |
| 82 | |
| 83 | #ifdef __cplusplus |
| 84 | } |
| 85 | #endif |
| 86 | |
| 87 | #endif /* _HUGETLBFS_H */ |