public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blkid: optimize dm_device_is_leaf() usage
@ 2008-08-25 20:48 Karel Zak
  2008-08-26 12:24 ` Theodore Tso
  0 siblings, 1 reply; 15+ messages in thread
From: Karel Zak @ 2008-08-25 20:48 UTC (permalink / raw)
  To: Theodore Tso; +Cc: linux-ext4, Eric Sandeen, Karel Zak

 * devname.c: probe_one(): call dm_device_is_leaf() with *constant*
   devno argument in the list_for_each_safe loop does not make sense at
   all.

 * devname.c: probe_one(): call dm_device_is_leaf() for already
   checked DM devices is unnecessary. DM devices are already checked
   in dm_probe_all(). The dm_probe_all() function never returns slave
   devices.

 * devname.c: dm_device_is_leaf(): stop checking for dependences when
   a first dependence is detected.

Performance test:

  # for i in $(seq 1 100); do dmsetup create $i --table "0 1 zero"; done

 new version:

  # blkid &> /dev/null

  real    0m0.267s
  user    0m0.047s
  sys     0m0.212s

 old version:

  # blkid &> /dev/null

  real    0m2.149s
  user    0m0.291s
  sys     0m1.820s

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 lib/blkid/devname.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 86fd44c..4967b96 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -133,25 +133,27 @@ static void probe_one(blkid_cache cache, const char *ptname,
 	const char **dir;
 	char *devname = NULL;
 
-	/* See if we already have this device number in the cache. */
-	list_for_each_safe(p, pnext, &cache->bic_devs) {
-		blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
-					   bid_devs);
 #ifdef HAVE_DEVMAPPER
-		if (!dm_device_is_leaf(devno))
-			continue;
+	/* call dm_device_is_leaf() for non-DM device only */
+	if (pri == BLKID_PRI_DM || dm_device_is_leaf(devno))
 #endif
-		if (tmp->bid_devno == devno) {
-			if (only_if_new && !access(tmp->bid_name, F_OK))
-				return;
-			dev = blkid_verify(cache, tmp);
-			if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED))
-				break;
-			dev = 0;
+	{
+		/* See if we already have this device number in the cache. */
+		list_for_each_safe(p, pnext, &cache->bic_devs) {
+			blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
+						   bid_devs);
+			if (tmp->bid_devno == devno) {
+				if (only_if_new && !access(tmp->bid_name, F_OK))
+					return;
+				dev = blkid_verify(cache, tmp);
+				if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED))
+					break;
+				dev = 0;
+			}
 		}
+		if (dev && dev->bid_devno == devno)
+			goto set_pri;
 	}
-	if (dev && dev->bid_devno == devno)
-		goto set_pri;
 
 	/*
 	 * Take a quick look at /dev/ptname for the device number.  We check
@@ -271,9 +273,10 @@ static int dm_device_is_leaf(const dev_t dev)
 	do {
 		names = (struct dm_names *) ((char *)names + next);
 
-		if (dm_device_has_dep(dev, names->name))
+		if (dm_device_has_dep(dev, names->name)) {
 			ret = 0;

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-08-27  8:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-25 20:48 [PATCH] blkid: optimize dm_device_is_leaf() usage Karel Zak
2008-08-26 12:24 ` Theodore Tso
2008-08-26 13:51   ` Karel Zak
2008-08-26 14:47     ` Theodore Tso
2008-08-26 18:04       ` Theodore Tso
2008-08-26 19:44       ` Andreas Dilger
2008-08-26 20:00         ` Theodore Tso
2008-08-26 20:47       ` Karel Zak
2008-08-26 23:32         ` Theodore Tso
2008-08-27  0:19           ` Karel Zak
2008-08-27  1:21             ` Theodore Tso
2008-08-27  4:40               ` Theodore Tso
2008-08-27  8:32                 ` Karel Zak
2008-08-27  7:26             ` Andreas Dilger
2008-08-27  8:10               ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox