]> git.neil.brown.name Git - LaFS.git/commitdiff
split out set_youth.
authorNeilBrown <neilb@suse.de>
Sun, 19 Sep 2010 04:16:00 +0000 (14:16 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 19 Sep 2010 04:16:00 +0000 (14:16 +1000)
Setting of the youth value is now a separate function.

Signed-off-by: NeilBrown <neilb@suse.de>
segments.c

index 8b3acb385f32fd940c9652f0897553d05c6dc11b..92c616ab9c60e6408ab14758433288c6822b4c2d 100644 (file)
@@ -400,6 +400,36 @@ void lafs_seg_move(struct fs *fs, u64 oldaddr, u64 newaddr,
        }
 }
 
+static void set_youth(struct fs *fs, struct segsum *ss)
+{
+       u16 y;
+       u16 *youthp;
+
+       /* HACK youth_next should always be at least 0x8000 so that
+        * cleanable score differentiates well for new segments.
+        * old code would sometimes set youth_next very low, so
+        * over-ride that
+        */
+       if (fs->youth_next < 0x8000)
+               fs->youth_next = 0x8000;
+       y = fs->youth_next;
+       if (fs->scan.do_decay &&
+           (fs->scan.free_dev < ss->devnum
+            || (fs->scan.free_dev == ss->devnum
+                && fs->scan.free_block < (ss->segnum
+                                          / (fs->blocksize / 2)))
+                   ))
+               /* Haven't decayed this block yet - revert decay */
+               y = decay_undo(y);
+       youthp = map_dblock(ss->youthblk);
+       youthp[ss->segnum & ((1 << (fs->blocksize_bits
+                                   - 1)) - 1)]
+               = cpu_to_le16(y);
+       fs->youth_next++;
+       unmap_dblock(ss->youthblk, youthp);
+       lafs_dirty_dblock(ss->youthblk);
+}
+
 static void seg_apply(struct fs *fs, struct segsum *ss)
 {
        int err;
@@ -1117,7 +1147,6 @@ void lafs_free_get(struct fs *fs, unsigned int *dev, u32 *seg,
         * The youth value must have been zero, and we set it to the
         * current youth number.
         */
-       u16 *youthp;
        struct segstat *ss;
        struct segsum *ssum = NULL;
        int ssnum;
@@ -1173,33 +1202,8 @@ again:
                ssum = NULL;
        }
 
-       if (ssum) {
-               u16 y;
-               /* HACK youth_next should always be at least 0x8000 so that
-                * cleanable score differentiates well for new segments.
-                * old code would sometimes set youth_next very low, so
-                * over-ride that
-                */
-
-               if (fs->youth_next < 0x8000)
-                       fs->youth_next = 0x8000;
-               y = fs->youth_next;
-               if (fs->scan.do_decay &&
-                   (fs->scan.free_dev < ss->dev
-                    || (fs->scan.free_dev == ss->dev 
-                        && fs->scan.free_block < (ss->segment
-                                                  / (fs->blocksize / 2)))
-                           ))
-                       /* Haven't decayed this block yet - revert decay */
-                       y = decay_undo(y);
-               youthp = map_dblock(ssum->youthblk);
-               youthp[(*seg) & ((1 << (fs->blocksize_bits
-                                       - 1)) - 1)]
-                       = cpu_to_le16(y);
-               fs->youth_next++;
-               unmap_dblock(ssum->youthblk, youthp);
-               lafs_dirty_dblock(ssum->youthblk);
-       }
+       if (ssum)
+               set_youth(fs, ssum);
 
        spin_unlock(&fs->lock);