Skip to main content

Module init

Module init 

Source
Expand description

The setup of the server process before it serves: umask, OOM score, open files limit, malloc and transparent huge pages, the standard streams and the descriptors it inherited, its working directory and the subreaper flag, and giving the runtime calls the OOM score, huge pages setting and open files limits the server started with.

ConstantsΒ§

MALLOC_ARENAS πŸ”’
The most malloc arenas of the server. glibc gives every thread an arena of its own, up to eight per CPU, and on AArch64 it backs them with 2 MiB transparent huge pages by default, so each costs up to 2 MiB resident. The runtime, which also runs the RPC LocalSet, runs on one thread, the others only serve short blocking work, so one arena is enough, the per thread caches of the allocator absorb most of the contention.
MALLOC_THRESHOLD πŸ”’
The size from which on glibc maps every allocation on its own, which goes back to the kernel once freed, and the free memory at the top of the heap from which on glibc returns it. Both are the defaults of glibc, which raises them to the size of every mapped allocation that gets freed, up to 32 and 64 MiB. After an exec_sync with a large output, up to 16 MiB per pipe which get copied into the response, the allocations of that size would stay in the heap then and keep it resident. Setting them turns that off.
OOM_SCORE_ADJ πŸ”’
The OOM score adjustment of the server.

StaticsΒ§

INHERITED_NOFILE πŸ”’
The soft and hard limit of open files the server started with, if it raised the soft one, see raise_nofile_limit.
INHERITED_OOM_SCORE πŸ”’
The OOM score adjustment the server started with, see reset_inherited.
THP_DISABLED πŸ”’
Whether the server turned transparent huge pages off for itself, which the processes it runs must not inherit, see disable_thp.

FunctionsΒ§

close_inherited_fds πŸ”’
Close file descriptors inherited from whatever started us.
configure_malloc πŸ”’
Limit the malloc arenas of the server, see MALLOC_ARENAS, and fix the thresholds of glibc, see MALLOC_THRESHOLD. Runs before the fork, while the process has a single thread. The runtimes and containers keep the defaults, an exec starts their allocator anew.
disable_thp πŸ”’
Turn transparent huge pages off for the process, as early as possible. On AArch64 glibc asks for them for its heap by default, so the first growth of the heap beyond a 2 MiB boundary costs 2 MiB resident, which a server per pod does not need. mallopt cannot turn that off, and the tunable which can takes effect only from the start of the process. Huge pages which were already allocated stay.
inherited_fds πŸ”’
Every open descriptor above stderr. Split out from close_inherited_fds so it can be tested without closing the test runner’s own descriptors.
raise_nofile_limit πŸ”’
Raise the soft limit of open files to the hard one. The server holds the pipes, log files, pidfds and sockets of every container of a pod and the sessions of the streaming server, while Go programs like CRI-O start it with the soft limit they started with, often 1024. The runtimes get the limits the server started with, see reset_inherited.
redirect_stdio πŸ”’
Like a daemon, do not keep the standard streams of the caller, like the file the Go client reads the launch errors from, see startServer in pkg/client. The processes the server starts, like the runtimes, would write into it otherwise. Only the stdout log driver writes to them.
reset_inherited πŸ”’
Give a child the OOM score adjustment, the transparent huge pages setting and the open files limits the server started with instead of its own, see save_oom_score, disable_thp and raise_nofile_limit. The runtimes pass them on to the container processes, an exec would be the last process the kernel picks otherwise. conmon resets the OOM score of its runtime the same way. Add it after the other pre_exec hooks, those run in order and may need the raised limit.
restore_nofile πŸ”’
Set the open files limits of the process, if any, async signal safe for a pre_exec hook. A failure keeps the ones of the server.
save_oom_score πŸ”’
Remember the OOM score adjustment the server started with, before it protects itself with set_oom_score.
set_default_umask πŸ”’
Set the default umask.
set_oom_score πŸ”’
Adjust the OOM score of the server, best effort without the privileges to lower it.
set_oom_score_at πŸ”’
set_up_process πŸ”’
Set up the process before it forks: remember the OOM score and raise the open files limit for the runtimes, configure malloc and protect the server from the OOM killer. The server keeps the C locale, unlike conmon, so that the errors it returns to CRI-O do not depend on the environment. The umask is set before the configuration prepares the runtime directories, see crate::run.
set_up_serving πŸ”’
Set up the process to serve, once the logging is: do not keep the working directory of the caller busy, like a mount which then cannot be unmounted (the paths of the configuration are absolute, see Config::make_absolute, and so are the ones of the requests), and make the container processes get reparented to the server once their runtime exits.