All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - dev-cache: replace inefficient looking for dev
Date: Tue,  2 Mar 2021 21:58:30 +0000 (GMT)	[thread overview]
Message-ID: <20210302215830.351443851C35@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9dd759c6b1c0e25e785485f823b09c59ef5b2583
Commit:        9dd759c6b1c0e25e785485f823b09c59ef5b2583
Parent:        081e47912e6c80f233fec5d472e32e1ac4f19a78
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Fri Feb 26 00:21:41 2021 +0100
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Tue Mar 2 22:54:40 2021 +0100

dev-cache: replace inefficient looking for dev

Use btree loopkup to find dev structure by major:minor.
This could have slow down lvm2 commands significantly with
higher amount of LVs.
---
 lib/device/dev-cache.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 8dd069c79..21c9ef0ea 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1549,29 +1549,12 @@ struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct d
 	return dev;
 }
 
-static struct device *_dev_cache_seek_devt(dev_t dev)
-{
-	struct device *d = NULL;
-	struct dm_hash_node *n = dm_hash_get_first(_cache.names);
-	while (n) {
-		d = dm_hash_get_data(_cache.names, n);
-		if (d->dev == dev)
-			return d;
-		n = dm_hash_get_next(_cache.names, n);
-	}
-	return NULL;
-}
-
-/*
- * TODO This is very inefficient. We probably want a hash table indexed by
- * major:minor for keys to speed up these lookups.
- */
 struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t dev, struct dev_filter *f, int *filtered)
 {
 	char path[PATH_MAX];
 	const char *sysfs_dir;
 	struct stat info;
-	struct device *d = _dev_cache_seek_devt(dev);
+	struct device *d = (struct device *) btree_lookup(_cache.devices, (uint32_t) dev);
 	int ret;
 
 	if (filtered)
@@ -1600,7 +1583,7 @@ struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t dev, struct
 		log_debug_devs("Device num not found in dev_cache repeat dev_cache_scan for %d:%d",
 				(int)MAJOR(dev), (int)MINOR(dev));
 		dev_cache_scan();
-		d = _dev_cache_seek_devt(dev);
+		d = (struct device *) btree_lookup(_cache.devices, (uint32_t) dev);
 	}
 
 	if (!d)



                 reply	other threads:[~2021-03-02 21:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210302215830.351443851C35@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.