[CRIU] [PATCH] vdso: Speed up /proc/pid/maps parse

Pavel Emelyanov xemul at virtuozzo.com
Thu Apr 13 08:30:16 PDT 2017


This file is parsed on each start, it's nicer to make it
use bfd engine and save several syscalls and #PFs.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/vdso.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/criu/vdso.c b/criu/vdso.c
index 7708535..bbaba3f 100644
--- a/criu/vdso.c
+++ b/criu/vdso.c
@@ -229,19 +229,28 @@ err:
 static int vdso_parse_maps(pid_t pid, struct vdso_symtable *s)
 {
 	int exit_code = -1;
-	char buf[512];
-	FILE *maps;
+	char *buf;
+	struct bfd f;
 
 	*s = (struct vdso_symtable)VDSO_SYMTABLE_INIT;
 
-	maps = fopen_proc(pid, "maps");
-	if (!maps)
+	f.fd = open_proc(pid, "maps");
+	if (f.fd < 0)
 		return -1;
 
-	while (fgets(buf, sizeof(buf), maps)) {
+	if (bfdopenr(&f))
+		goto err;
+
+	while (1) {
 		unsigned long start, end;
 		char *has_vdso, *has_vvar;
 
+		buf = breadline(&f);
+		if (buf == NULL)
+			break;
+		if (IS_ERR(buf))
+			goto err;
+
 		has_vdso = strstr(buf, "[vdso]");
 		if (!has_vdso)
 			has_vvar = strstr(buf, "[vvar]");
@@ -275,7 +284,7 @@ static int vdso_parse_maps(pid_t pid, struct vdso_symtable *s)
 
 	exit_code = 0;
 err:
-	fclose(maps);
+	bclose(&f);
 	return exit_code;
 }
 
-- 
2.5.5


More information about the CRIU mailing list