[CRIU] [PATCH RFC 2/2] mount: lookup mountinfo in hash instead of list search

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Thu Mar 17 05:54:08 PDT 2016


This search is much faster.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 criu/mount.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/criu/mount.c b/criu/mount.c
index ac784a2..cac1abc 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -57,6 +57,19 @@ void mountinfo_hash_add(struct mount_info *mi)
 	hlist_add_head(&mi->hash, &mountinfo_hash[mi->mnt_id % MOUNTINFO_HASH_SIZE]);
 }
 
+struct mount_info *lookup_mnt_id(unsigned int id)
+{
+	struct mount_info *mi;
+	struct hlist_head *chain;
+
+	chain = &mountinfo_hash[id % MOUNTINFO_HASH_SIZE];
+	hlist_for_each_entry(mi, chain, hash)
+		if (mi->mnt_id == id)
+			return mi;
+
+	return NULL;
+}
+
 int ext_mount_add(char *key, char *val)
 {
 	struct ext_mount *em;
@@ -227,11 +240,6 @@ static struct mount_info *__lookup_mnt_id(struct mount_info *list, int id)
 	return NULL;
 }
 
-struct mount_info *lookup_mnt_id(unsigned int id)
-{
-	return __lookup_mnt_id(mntinfo, id);
-}
-
 struct mount_info *lookup_mnt_sdev(unsigned int s_dev)
 {
 	struct mount_info *m;



More information about the CRIU mailing list