mirror of
https://gitlab.labs.nic.cz/labs/bird.git
synced 2024-05-11 16:54:54 +00:00
Multipage allocation
We can also quite simply allocate bigger blocks. Anyway, we need these blocks to be aligned to their size which needs one mmap() two times bigger and then two munmap()s returning the unaligned parts. The user can specify -B <N> on startup when <N> is the exponent of 2, setting the block size to 2^N. On most systems, N is 12, anyway if you know that your configuration is going to eat gigabytes of RAM, you are almost forced to raise your block size as you may easily get into memory fragmentation issues or you have to raise your maximum mapping count, e.g. "sysctl vm.max_map_count=(number)".
This commit is contained in:
@@ -682,7 +682,7 @@ signal_init(void)
|
||||
* Parsing of command-line arguments
|
||||
*/
|
||||
|
||||
static char *opt_list = "bc:dD:ps:P:u:g:flRh";
|
||||
static char *opt_list = "B:c:dD:ps:P:u:g:flRh";
|
||||
int parse_and_exit;
|
||||
char *bird_name;
|
||||
static char *use_user;
|
||||
@@ -703,6 +703,7 @@ display_help(void)
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
"Options: \n"
|
||||
" -B <block-size> Use 2^this number as memory allocation block size (default: 12)\n"
|
||||
" -c <config-file> Use given configuration file instead of\n"
|
||||
" " PATH_CONFIG_FILE "\n"
|
||||
" -d Enable debug messages and run bird in foreground\n"
|
||||
@@ -789,12 +790,15 @@ get_gid(const char *s)
|
||||
return gr->gr_gid;
|
||||
}
|
||||
|
||||
extern _Bool alloc_multipage;
|
||||
|
||||
static void
|
||||
parse_args(int argc, char **argv)
|
||||
{
|
||||
int config_changed = 0;
|
||||
int socket_changed = 0;
|
||||
int c;
|
||||
int bp;
|
||||
|
||||
bird_name = get_bird_name(argv[0], "bird");
|
||||
if (argc == 2)
|
||||
@@ -807,6 +811,29 @@ parse_args(int argc, char **argv)
|
||||
while ((c = getopt(argc, argv, opt_list)) >= 0)
|
||||
switch (c)
|
||||
{
|
||||
case 'B':
|
||||
bp = atoi(optarg);
|
||||
if (bp < 1)
|
||||
{
|
||||
fprintf(stderr, "Strange block size power %d\n\n", bp);
|
||||
display_usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((1 << bp) < page_size)
|
||||
{
|
||||
fprintf(stderr, "Requested block size %ld is lesser than page size %ld\n\n", (1L<<bp), page_size);
|
||||
display_usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((1L << bp) > page_size)
|
||||
{
|
||||
alloc_multipage = 1;
|
||||
page_size = (1L << bp);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'c':
|
||||
config_name = optarg;
|
||||
config_changed = 1;
|
||||
@@ -861,6 +888,8 @@ parse_args(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
void resource_sys_init(void);
|
||||
|
||||
/*
|
||||
* Hic Est main()
|
||||
*/
|
||||
@@ -873,6 +902,7 @@ main(int argc, char **argv)
|
||||
dmalloc_debug(0x2f03d00);
|
||||
#endif
|
||||
|
||||
resource_sys_init();
|
||||
parse_args(argc, argv);
|
||||
log_switch(1, NULL, NULL);
|
||||
|
||||
|
Reference in New Issue
Block a user