mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
increase number of reserved huge pages automatically if required
This commit is contained in:
parent
90e973ce37
commit
4bb0aa76c9
9 changed files with 73 additions and 2 deletions
4
config.h
4
config.h
|
@ -24,6 +24,10 @@
|
|||
#define DEFAULT_VALUES 64
|
||||
#define DEFAULT_QUEUELEN 1024
|
||||
|
||||
/** Number of hugepages which are requested from the the kernel.
|
||||
* @see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt */
|
||||
#define DEFAULT_NR_HUGEPAGES 25
|
||||
|
||||
/** Width of log output in characters */
|
||||
#define LOG_WIDTH 132
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
//#include <sys/capability.h>
|
||||
|
||||
/** Check if current process has capability \p cap.
|
||||
|
@ -19,7 +21,13 @@
|
|||
* @retval 0 If capabilty is present.
|
||||
* @retval <0 If capability is not present.
|
||||
*/
|
||||
//int kernel_check_cap(cap_value_t cap):
|
||||
//int kernel_check_cap(cap_value_t cap);
|
||||
|
||||
/** Get number of reserved hugepages. */
|
||||
int kernel_get_nr_hugepages();
|
||||
|
||||
/** Set number of reserved hugepages. */
|
||||
int kernel_set_nr_hugepages(int nr);
|
||||
|
||||
/** Checks for realtime (PREEMPT_RT) patched kernel.
|
||||
*
|
||||
|
|
|
@ -44,6 +44,9 @@ struct memzone {
|
|||
size_t len;
|
||||
};
|
||||
|
||||
/** Initilialize memory subsystem */
|
||||
int memory_init();
|
||||
|
||||
/** Allocate \p len bytes memory of type \p m.
|
||||
*
|
||||
* @retval NULL If allocation failed.
|
||||
|
|
|
@ -152,6 +152,38 @@ int kernel_get_cacheline_size()
|
|||
return sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
|
||||
}
|
||||
|
||||
int kernel_get_nr_hugepages()
|
||||
{
|
||||
FILE *f;
|
||||
int nr, ret;
|
||||
|
||||
f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "r");
|
||||
if (!f)
|
||||
serror("Failed to open %s", PROCFS_PATH "/sys/vm/nr_hugepages");
|
||||
|
||||
ret = fscanf(f, "%d", &nr);
|
||||
if (ret != 1)
|
||||
nr = -1;
|
||||
|
||||
fclose(f);
|
||||
|
||||
return nr;
|
||||
}
|
||||
|
||||
int kernel_set_nr_hugepages(int nr)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "w");
|
||||
if (!f)
|
||||
serror("Failed to open %s", PROCFS_PATH "/sys/vm/nr_hugepages");
|
||||
|
||||
fprintf(f, "%d\n", nr);
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int kernel_check_cap(cap_value_t cap)
|
||||
{
|
||||
|
|
15
lib/memory.c
15
lib/memory.c
|
@ -12,11 +12,26 @@
|
|||
/* Required to allocate hugepages on Apple OS X */
|
||||
#ifdef __MACH__
|
||||
#include <mach/vm_statistics.h>
|
||||
#elif defined(__linux__)
|
||||
#include "kernel/kernel.h"
|
||||
#endif
|
||||
|
||||
#include "log.h"
|
||||
#include "memory.h"
|
||||
|
||||
int memory_init()
|
||||
{
|
||||
#ifdef __linux__
|
||||
int nr = kernel_get_nr_hugepages();
|
||||
|
||||
debug(DBG_MEM | 2, "System has %d reserved hugepages", nr);
|
||||
|
||||
if (nr < DEFAULT_NR_HUGEPAGES)
|
||||
kernel_set_nr_hugepages(DEFAULT_NR_HUGEPAGES);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * memory_alloc(const struct memtype *m, size_t len)
|
||||
{
|
||||
debug(DBG_MEM | 2, "Allocating %#zx bytes of %s memory", len, m->name);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <villas/utils.h>
|
||||
#include <villas/cfg.h>
|
||||
#include <villas/path.h>
|
||||
#include <villas/memory.h>
|
||||
#include <villas/node.h>
|
||||
#include <villas/kernel/kernel.h>
|
||||
#include <villas/kernel/rt.h>
|
||||
|
@ -124,6 +125,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
info("Initialize real-time system");
|
||||
rt_init(settings.affinity, settings.priority);
|
||||
|
||||
info("Initialize memory system");
|
||||
memory_init();
|
||||
|
||||
info("Initialize signals");
|
||||
signals_init();
|
||||
|
|
|
@ -225,6 +225,9 @@ int main(int argc, char *argv[])
|
|||
info("Initialize real-time system");
|
||||
rt_init(settings.affinity, settings.priority);
|
||||
|
||||
info("Initialize memory system");
|
||||
memory_init();
|
||||
|
||||
/* Initialize node */
|
||||
node = list_lookup(&nodes, argv[2]);
|
||||
if (!node)
|
||||
|
|
|
@ -87,6 +87,9 @@ int main(int argc, char *argv[])
|
|||
log_init();
|
||||
cfg_parse(argv[1], &config, &settings, &nodes, NULL);
|
||||
|
||||
info("Initialize memory system");
|
||||
memory_init();
|
||||
|
||||
node = list_lookup(&nodes, argv[3]);
|
||||
if (!node)
|
||||
error("There's no node with the name '%s'", argv[3]);
|
||||
|
|
|
@ -8,7 +8,6 @@ TEST_LDLIBS = $(LDLIBS) -lcriterion -lvillas -pthread
|
|||
tests: $(BUILDDIR)/testsuite
|
||||
|
||||
run-tests: tests
|
||||
echo 25 > /proc/sys/vm/nr_hugepages
|
||||
$(BUILDDIR)/testsuite
|
||||
|
||||
# Compile
|
||||
|
|
Loading…
Add table
Reference in a new issue