PERFORCE change 177890 for review

Zheng Liu lz at FreeBSD.org
Fri May 7 08:19:50 UTC 2010


http://p4web.freebsd.org/@@177890?ac=10

Change 177890 by lz at gnehzuil-freebsd on 2010/05/07 08:19:31

	Add initialize and finalize code.
	
	 * add ext2_init_rsv_win_info, ext2_discard_rsv_win, ext2_rsv_win_remove funcs.
	 * add initialize and finalize code.

Affected files ...

.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#2 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_balloc.c#2 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_inode.c#2 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#2 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_vfsops.c#3 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_vnops.c#2 edit

Differences ...

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

@@ -50,6 +50,7 @@
 #include <fs/ext2fs/ext2fs.h>
 #include <fs/ext2fs/fs.h>
 #include <fs/ext2fs/ext2_extern.h>
+#include <fs/ext2fs/ext2_rsv_win.h>
 
 static daddr_t	ext2_alloccg(struct inode *, int, daddr_t, int);
 static u_long	ext2_dirpref(struct inode *);
@@ -59,6 +60,81 @@
 						int));
 static daddr_t	ext2_nodealloccg(struct inode *, int, daddr_t, int);
 static daddr_t  ext2_mapsearch(struct m_ext2fs *, char *, daddr_t);
+
+static void ext2_rsv_win_remove(struct m_ext2fs *, struct ext2_rsv_win *);
+
+RB_GENERATE(ext2_rsv_win_tree, ext2_rsv_win, rw_link, ext2_rsv_win_cmp);
+
+/*
+ * Lazily initialize reservation window per inode.
+ *
+ * When file need to allocate blocks first, reservation window
+ * info structure will be initialized.
+ */
+void
+ext2_init_rsv_win_info(struct inode *ip)
+{
+	struct ext2_rsv_win *rwp;
+	struct ext2_rsv_win_info *rwip;
+
+	rwip = malloc(sizeof(struct ext2_rsv_win_info),
+			M_EXT2NODE, M_NOWAIT | M_ZERO);
+	if (rwip == NULL)
+		/* If malloc failed, we just do not use
+		 * reservation window mechnism
+		 */
+		return;
+
+	rwp = &rwip->rwi_entry;
+	rwp->rw_start = EXT2_RWI_NOT_ALLOCATED;
+	rwp->rw_end = EXT2_RWI_NOT_ALLOCATED;
+
+	rwp->rw_goal_size = EXT2_RWI_DEFAULT_RESERVE_BLKS;
+	rwp->rw_alloc_hit = 0;
+
+	ip->i_rsv_winp = rwip;
+} 
+
+/*
+ * Discard reservation window.
+ *
+ * It is called at following locations:
+ * 1. free an inode
+ * 2. sync inode
+ */
+void
+ext2_discard_rsv_win(struct inode *ip)
+{
+	struct ext2_rsv_win *rwp;
+
+	/* do not use reservation window */
+	if (ip->i_rsv_winp == NULL)
+		return;
+
+
+	rwp = &ip->i_rsv_winp->rwi_entry;
+	if (rwp->rw_end == EXT2_RWI_NOT_ALLOCATED)
+		/* reservation window is empty */
+		return;
+
+	mtx_lock_spin(&ip->i_e2fs->e2fs_rsv_win_lock);
+	if (rwp->rw_end != EXT2_RWI_NOT_ALLOCATED)
+		ext2_rsv_win_remove(ip->i_e2fs, rwp);
+	mtx_unlock_spin(&ip->i_e2fs->e2fs_rsv_win_lock);
+}
+
+/*
+ * Remove a ext2_rsv_win structure from RB tree.
+ */
+void
+ext2_rsv_win_remove(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp)
+{
+	rwp->rw_start = EXT2_RWI_NOT_ALLOCATED;
+	rwp->rw_end = EXT2_RWI_NOT_ALLOCATED;
+	rwp->rw_alloc_hit = 0;
+	RB_REMOVE(ext2_rsv_win_tree, &sbp->e2fs_tree, rwp);
+}
+
 /*
  * Allocate a block in the file system.
  *
@@ -866,6 +942,10 @@
 		panic("ext2_vfree: range: devvp = %p, ino = %d, fs = %s",
 		    pip->i_devvp, ino, fs->e2fs_fsmnt);
 
+	ext2_discard_rsv_win(pip);
+	free(pip->i_rsv_winp, M_EXT2NODE);
+	pip->i_rsv_winp = NULL;
+
 	cg = ino_to_cg(fs, ino);
 	error = bread(pip->i_devvp,
 		fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap),

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

@@ -49,6 +49,7 @@
 #include <fs/ext2fs/fs.h>
 #include <fs/ext2fs/ext2_extern.h>
 #include <fs/ext2fs/ext2_mount.h>
+#include <fs/ext2fs/ext2_rsv_win.h>
 /*
  * Balloc defines the structure of file system storage
  * by allocating the physical blocks on a device given
@@ -79,6 +80,12 @@
 	ump = ip->i_ump;
 
 	/*
+	 * lazily initialize the reservation window info in inode
+	 */
+	if (ip->i_rsv_winp == NULL)
+		ext2_init_rsv_win_info(ip);
+
+	/*
 	 * check if this is a sequential block allocation. 
 	 * If so, increment next_alloc fields to allow ext2_blkpref 
 	 * to make a good guess

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

@@ -153,6 +153,7 @@
 	}
 	fs = oip->i_e2fs;
 	osize = oip->i_size;
+	ext2_discard_rsv_win(oip);
 	/*
 	 * Lengthen the size of the file. We must ensure that the
 	 * last byte of the file is allocated. Since the smallest
@@ -525,6 +526,13 @@
 	if (prtactive && vrefcnt(vp) != 0)
 		vprint("ufs_reclaim: pushing active", vp);
 	ip = VTOI(vp);
+
+	ext2_discard_rsv_win(ip);
+	if (ip->i_rsv_winp != NULL) {
+		free(ip->i_rsv_winp, M_EXT2NODE);
+		ip->i_rsv_winp = NULL;
+	}
+
 	if (ip->i_flag & IN_LAZYMOD) {
 		ip->i_flag |= IN_MODIFIED;
 		ext2_update(vp, 0);

==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#2 (text+ko) ====

@@ -40,6 +40,9 @@
 
 #include <sys/tree.h>
 
+#define EXT2_RWI_DEFAULT_RESERVE_BLKS 8
+#define EXT2_RWI_NOT_ALLOCATED 0
+
 /*
  * reservation window entry
  */
@@ -73,9 +76,15 @@
  */
 struct ext2_rsv_win_info {
 	struct ext2_rsv_win rwi_entry;
-
+#if 0
 	u_int32_t rwi_last_logical_blk;  /* Last allocated logical block */
 	u_int32_t rwi_last_physical_blk; /* Last allocated physical block */
+#endif
 };
 
-#endif /* _EXT2_RSV_WIN_H_ */
+/* ext2_allo.c */
+struct inode;
+void ext2_init_rsv_win_info(struct inode *ip);
+void ext2_discard_rsv_win(struct inode *ip);
+
+#endif /* !_EXT2_RSV_WIN_H_ */

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

@@ -891,6 +891,8 @@
 	ip->i_e2fs = fs = ump->um_e2fs;
 	ip->i_ump  = ump;
 	ip->i_number = ino;
+	/* lazily initialize reservation window */
+	ip->i_rsv_winp = NULL;
 
 	lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
 	error = insmntque(vp, mp);

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



More information about the p4-projects mailing list