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,
'/');
123 p =
format (p,
"/sys/devices/system/node/node%u%c", numa_node, 0);
125 if (stat ((
char *) p, &sb) == 0)
127 if (S_ISDIR (sb.st_mode) == 0)
133 else if (numa_node == 0)
136 p =
format (p,
"/sys/kernel/mm%c", 0);
137 if (stat ((
char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
151 p =
format (p,
"/hugepages/hugepages-%ukB/nr_hugepages%c", page_size, 0);
162 int page_size,
int *val)
168 p =
format (p,
"/sys/devices/system/node/node%u%c", numa_node, 0);
170 if (stat ((
char *) p, &sb) == 0)
172 if (S_ISDIR (sb.st_mode) == 0)
178 else if (numa_node == 0)
181 p =
format (p,
"/sys/kernel/mm%c", 0);
182 if (stat ((
char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
196 p =
format (p,
"/hugepages/hugepages-%ukB/%s_hugepages%c", page_size,
238 clib_warning (
"pre-allocating %u additional %uK hugepages on numa node %u",
239 needed, page_size, numa_node);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static clib_error_t * clib_sysfs_get_xxx_hugepages(char *type, int numa_node, int page_size, int *val)
clib_error_t * clib_sysfs_get_surplus_hugepages(int numa_node, int page_size, int *v)
clib_error_t * clib_sysfs_write(char *file_name, char *fmt,...)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define clib_error_return(e, args...)
#define clib_error_return_unix(e, args...)
clib_error_t * clib_sysfs_get_free_hugepages(int numa_node, int page_size, int *v)
clib_error_t * clib_sysfs_read(char *file_name, char *fmt,...)
#define vec_free(V)
Free vector's memory (no header).
clib_error_t * clib_sysfs_set_nr_hugepages(int numa_node, int page_size, int nr)
#define clib_warning(format, args...)
clib_error_t * clib_sysfs_get_nr_hugepages(int numa_node, int page_size, int *v)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
clib_error_t * clib_sysfs_prealloc_hugepages(int numa_node, int page_size, int nr)
u8 * clib_sysfs_link_to_name(char *link)