[PATCH] blkid: optimize dm_device_is_leaf() usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 * 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@xxxxxxxxxx>
---
 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;
-
+			goto out;
+		}
 		next = names->next;
 	} while (next);
 
-- 
1.5.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux