mirror of
https://github.com/systemd/systemd.git
synced 2025-03-13 00:58:27 +03:00
fileio: start with 4k buffer for procfs
There's a very gradual increase of anonymous memory in systemd-journald that blames to 2ac67221bb6270f0fbe7cbd0076653832cd49de2. systemd-journald makes many calls to read /proc/PID/cmdline and /proc/PID/status, both of which tend to be well under 4K. However the combination of allocating 4M read buffers, then using `realloc()` to shrink the buffer in `read_virtual_file()` appears to be creating fragmentation in the heap (when combined with the other allocations systemd-journald is doing). To help mitigate this, try reading /proc with a 4K buffer as `read_virtual_file()` did before 2ac67221bb6270f0fbe7cbd0076653832cd49de2. If it isn't big enough then try again with the larger buffers.
This commit is contained in:
parent
1dcd91ad11
commit
5aaa55d841
@ -433,6 +433,11 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents
|
|||||||
}
|
}
|
||||||
|
|
||||||
n_retries--;
|
n_retries--;
|
||||||
|
} else if (n_retries > 1) {
|
||||||
|
/* Files in /proc are generally smaller than the page size so let's start with a page size
|
||||||
|
* buffer from malloc and only use the max buffer on the final try. */
|
||||||
|
size = MIN3(page_size() - 1, READ_VIRTUAL_BYTES_MAX, max_size);
|
||||||
|
n_retries = 1;
|
||||||
} else {
|
} else {
|
||||||
size = MIN(READ_VIRTUAL_BYTES_MAX, max_size);
|
size = MIN(READ_VIRTUAL_BYTES_MAX, max_size);
|
||||||
n_retries = 0;
|
n_retries = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user