Skip to content

Commit

Permalink
US1644 configurable memory consumption limit (#56)
Browse files Browse the repository at this point in the history
The memory limit is configurable be means of setting cgroup mem limit
when starting a container (-m docker run option)

Signed-off-by: Jan Kryl <jan.kryl@cloudbyte.com>
  • Loading branch information
Jan Kryl committed Jun 26, 2018
1 parent 48a2090 commit 6e279e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/libzpool/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,12 +1509,25 @@ void
kernel_init(int mode)
{
extern uint_t rrw_tsd_key;
uint64_t cgroupmem;
FILE *f;

umem_nofail_callback(umem_out_of_memory);

physmem = sysconf(_SC_PHYS_PAGES);

dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
/* If we run inside a container get the cgroup mem limit */
f = fopen("/sys/fs/cgroup/memory/memory.limit_in_bytes", "r");
if (f != NULL) {
if (fscanf(f, "%lu", &cgroupmem) == 1) {
cgroupmem /= sysconf(_SC_PAGE_SIZE);
if (physmem > cgroupmem)
physmem = cgroupmem;
}
fclose(f);
}

printf("physmem = %lu pages (%.2f GB)\n", physmem,
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));

(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
Expand Down

0 comments on commit 6e279e4

Please sign in to comment.