20 #include <sys/types.h> 32 fd = open (file_name, O_WRONLY);
41 if (write (fd, s,
vec_len (s)) < 0)
58 fd = open (file_name, O_RDONLY);
97 r = readlink (link, buffer,
sizeof (buffer) - 1);
103 p = strrchr (buffer,
'/');
124 if (log2_page_size == 0)
127 page_size = 1ULL << (log2_page_size - 10);
129 p =
format (p,
"/sys/devices/system/node/node%u%c", numa_node, 0);
131 if (stat ((
char *) p, &sb) == 0)
133 if (S_ISDIR (sb.st_mode) == 0)
139 else if (numa_node == 0)
142 p =
format (p,
"/sys/kernel/mm%c", 0);
143 if (stat ((
char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
157 p =
format (p,
"/hugepages/hugepages-%ukB/nr_hugepages%c", page_size, 0);
168 int log2_page_size,
int *val)
176 if (log2_page_size == 0)
179 page_size = 1ULL << (log2_page_size - 10);
182 p =
format (p,
"/sys/devices/system/node/node%u%c", numa_node, 0);
184 if (stat ((
char *) p, &sb) == 0)
186 if (S_ISDIR (sb.st_mode) == 0)
192 else if (numa_node == 0)
195 p =
format (p,
"/sys/kernel/mm%c", 0);
196 if (stat ((
char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
210 p =
format (p,
"/hugepages/hugepages-%ukB/%s_hugepages%c", page_size,
245 if (log2_page_size == 0)
248 page_size = 1ULL << (log2_page_size - 10);
260 clib_warning (
"pre-allocating %u additional %uK hugepages on numa node %u",
261 needed, page_size, numa_node);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
clib_error_t * clib_sysfs_prealloc_hugepages(int numa_node, int log2_page_size, int nr)
__clib_export u8 * clib_sysfs_link_to_name(char *link)
static uword min_log2(uword x)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
__clib_export clib_error_t * clib_sysfs_write(char *file_name, char *fmt,...)
description fragment has unexpected format
#define clib_error_return(e, args...)
vl_api_fib_path_type_t type
#define clib_error_return_unix(e, args...)
clib_error_t * clib_sysfs_get_nr_hugepages(int numa_node, int log2_page_size, int *v)
clib_error_t * clib_sysfs_get_free_hugepages(int numa_node, int log2_page_size, int *v)
clib_error_t * clib_sysfs_get_surplus_hugepages(int numa_node, int log2_page_size, int *v)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
__clib_export uword clib_mem_get_default_hugepage_size(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
__clib_export clib_error_t * clib_sysfs_read(char *file_name, char *fmt,...)
clib_error_t * clib_sysfs_set_nr_hugepages(int numa_node, int log2_page_size, int nr)
static clib_error_t * clib_sysfs_get_xxx_hugepages(char *type, int numa_node, int log2_page_size, int *val)