[CRIU] [PATCH] proc_parse: Set bigger buffer for smaps FILE
Pavel Emelyanov
xemul at parallels.com
Thu Feb 13 11:45:59 PST 2014
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 feeds at most one vma per read() syscall
regardless of the buffer size.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
diff --git a/proc_parse.c b/proc_parse.c
index 365688a..714a2cb 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -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? */
More information about the CRIU
mailing list