Commit 95c2a4d6 authored by Pavel Emelyanov's avatar Pavel Emelyanov

proc_parse: Set bigger buffer for smaps FILE

We spend a lot of time reading the /proc/$pid/smaps file. The time
is spent in two places:

1 kernel puts too many info into it
2 fgets pulls info in 1024-bytes chunks, info about one vma is
  typically bigger (up to 3k bytes) thus we call read() ~3 times
  per one vma, which increases the amount of time spent in kernel
  to re-fill this info

Setting the internal buffer to PAGE_SIZE size reduces the amount of
read()-s on ~60% during basic container dump. Setting bigger buffer
doesn't work, as kernel's seq file engine feeds at most one page of
data per read syscall regardless of the buffer size.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
parent c6a3b1de
......@@ -246,6 +246,8 @@ int parse_self_maps_lite(struct vm_area_list *vms)
return 0;
}
static char smaps_buf[PAGE_SIZE];
int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files)
{
struct vma_area *vma_area = NULL;
......@@ -268,6 +270,8 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
if (!smaps)
goto err;
setvbuf(smaps, smaps_buf, _IOFBF, sizeof(smaps_buf));
if (use_map_files) {
map_files_dir = opendir_proc(pid, "map_files");
if (!map_files_dir) /* old kernel? */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment