… | |
… | |
4 | |
4 | |
5 | our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
5 | our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
6 | |
6 | |
7 | $^O eq "linux" or die "only linux supported right now.\n"; |
7 | $^O eq "linux" or die "only linux supported right now.\n"; |
8 | |
8 | |
9 | our $TIMER = cf::periodic 10, sub { |
9 | our $STAT_FH; |
10 | open my $fh, "</proc/self/stat" |
10 | our $TIMER; |
|
|
11 | |
|
|
12 | cf::post_init { |
|
|
13 | $STAT_FH = Coro::AIO::aio_open "/proc/self/stat", IO::AIO::O_RDONLY, 0 |
11 | or return; |
14 | or return; |
12 | |
15 | |
|
|
16 | $TIMER = cf::periodic 10, sub { |
|
|
17 | sysseek $STAT_FH, 0, 0; |
13 | sysread $fh, my $stat, 4096; # only a single line |
18 | sysread $STAT_FH, my $stat, 4096; # only a single line |
14 | my $vmsize = (split / /, $stat)[22]; |
19 | my $vmsize = (split / /, $stat)[22]; |
15 | |
20 | |
16 | cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
21 | cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
17 | if $vmsize >= $MAX_VMSIZE; |
22 | if $vmsize >= $MAX_VMSIZE; |
|
|
23 | }; |
18 | }; |
24 | }; |