Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2011 05:43:46 GMT
From:      Zheng Liu <lz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 189849 for review
Message-ID:  <201103110543.p2B5hk97088993@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@189849?ac=10

Change 189849 by lz@freebsd-dev on 2011/03/11 05:43:43

	       Improve sweep loop like ext2_alloccg().

Affected files ...

.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#37 edit

Differences ...

==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#37 (text+ko) ====

@@ -1306,11 +1306,9 @@
         struct m_ext2fs *fs;
         struct ext2mount *ump;
         struct buf *bp;
-        int error, i, got, run;
         char *bbp;
-        daddr_t bno;
-        int bit, map;
-        unsigned char *mapp;
+        int error, i, bit, loc, end, start;
+        daddr_t bno = 0, runstart, runlen;
 
         fs = ip->i_e2fs;
         ump = ip->i_ump;
@@ -1333,51 +1331,66 @@
          * available in this cg.
          */
 
-        if (dtog(fs, bpref) != cg)
-                bpref = 0;
-        if (bpref != 0)
-                bpref = dtogd(fs, bpref);
-        mapp = &bbp[bpref / NBBY];
-        map = *mapp++;
-        bit = 1 << (bpref % NBBY);
-        for (run = 0, got = bpref; got < fs->e2fs_bpg; got++) {
-                if (!((map & bit) == 0)) {
-                        run = 0;
+        if (bpref)
+                start = dtogd(fs, bpref) / NBBY;
+        else
+                start = 0;
+        end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
+        runlen = 0;
+        runstart = 0;
+        for (loc = start; loc < end; loc++) {
+                if (bbp[loc] == (char)0xff) {
+                        runlen = 0;
+                        continue;
+                }
+
+                if (runlen == 0) {
+                        bit = fls(bbp[loc]);
+                        runlen = NBBY - bit;
+                        runstart = loc * NBBY + bit;
+                } else if (bbp[loc] == 0) {
+                        runlen += NBBY;
                 } else {
-                        run++;
-                        if (run == len)
-                                break;
+                        bit = ffs(bbp[loc]) - 1;
+                        runlen += bit;
+                        if (runlen >= len) {
+                                bno = runstart;
+                                goto gotit;
+                        }
+
+                        bit = fls(bbp[loc]);
+                        runlen = NBBY - bit;
+                        runstart = loc * NBBY + bit;
                 }
-                if ((got & (NBBY - 1)) != (NBBY - 1)) {
-                        bit <<= 1;
-                } else {
-                        map = *mapp++;
-                        bit = 1;
+
+                if (runlen >= len) {
+                        bno = runstart;
+                        goto gotit;
                 }
         }
 
-        if (got >= fs->e2fs_bpg)
+gotit:
+        if (bno == 0 || bno + len >= fs->e2fs->e2fs_fpg)
                 goto fail_lock;
 
         /*
          * Allocate the cluster that we have found.
          */
-        for (i = 1; i <= len; i++)
-                if (!isclr(bbp, got - run + i))
+        for (i = 0; i < len; i++)
+                if (!isclr(bbp, bno + i))
                         panic("ext2_clusteralloc: map mismatch");
                 
-        bno = got - run + 1;
-        if (bno >= fs->e2fs_bpg)
+        if (bno >= fs->e2fs->e2fs_fpg)
                 panic("ext2_clusteralloc: allocated out of group");
 
+        EXT2_LOCK(ump);
         for (i = 0; i < len; i += fs->e2fs_fpb) {
                 setbit(bbp, bno + i);
-                EXT2_LOCK(ump);
                 fs->e2fs->e2fs_fbcount--;
                 fs->e2fs_gd[cg].ext2bgd_nbfree--;
                 fs->e2fs_fmod = 1;
-                EXT2_UNLOCK(ump);
         }
+        EXT2_UNLOCK(ump);
 
         bdwrite(bp);
         return (phy_blk(cg, fs) + bno);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103110543.p2B5hk97088993>