[CRIU] [PATCH 16/27] seccomp: Speedup entry cleaning

Cyrill Gorcunov gorcunov at openvz.org
Thu Mar 1 15:41:38 MSK 2018


From: Cyrill Gorcunov <gorcunov at virtuozzo.com>

Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
 criu/include/seccomp.h |  1 +
 criu/seccomp.c         | 14 +++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/criu/include/seccomp.h b/criu/include/seccomp.h
index ff0465b8266f..c1c1bf4c3be4 100644
--- a/criu/include/seccomp.h
+++ b/criu/include/seccomp.h
@@ -53,6 +53,7 @@ struct seccomp_filter_chain {
 
 struct seccomp_entry {
 	struct rb_node			node;
+	struct seccomp_entry		*next;
 	pid_t				tid_real;
 	size_t				last_filter;
 	unsigned int			mode;
diff --git a/criu/seccomp.c b/criu/seccomp.c
index 0f0866e0c4a5..f73bcfbaaa1a 100644
--- a/criu/seccomp.c
+++ b/criu/seccomp.c
@@ -22,6 +22,7 @@
 #define LOG_PREFIX "seccomp: "
 
 static struct rb_root seccomp_tid_rb_root = RB_ROOT;
+static struct seccomp_entry *seccomp_tid_entry_root;
 
 struct seccomp_entry *seccomp_lookup(pid_t tid_real, bool create, bool mandatory)
 {
@@ -50,6 +51,7 @@ struct seccomp_entry *seccomp_lookup(pid_t tid_real, bool create, bool mandatory
 		rb_init_node(&entry->node);
 		entry->tid_real	= tid_real;
 
+		entry->next = seccomp_tid_entry_root, seccomp_tid_entry_root = entry;
 		rb_link_and_balance(&seccomp_tid_rb_root, &entry->node, parent, new);
 	} else {
 		if (mandatory)
@@ -92,14 +94,16 @@ static void seccomp_free_chain(struct seccomp_entry *entry)
 
 void seccomp_free_entries(void)
 {
-	struct seccomp_entry *entry;
-	struct rb_node *node;
+	struct seccomp_entry *entry, *next;
 
-	while ((node = rb_first(&seccomp_tid_rb_root))) {
-		rb_erase(node, &seccomp_tid_rb_root);
-		entry = rb_entry(node, struct seccomp_entry, node);
+	for (entry = seccomp_tid_entry_root; entry; entry = next) {
+		next = entry->next;
+		seccomp_free_chain(entry);
 		xfree(entry);
 	}
+
+	seccomp_tid_rb_root = RB_ROOT;
+	seccomp_tid_entry_root = NULL;
 }
 
 int seccomp_dump_thread(pid_t tid_real, ThreadCoreEntry *thread_core)
-- 
2.14.3



More information about the CRIU mailing list