Skip to contentSkip to conversation

ocfs2: Clear undo bits when local alloc is freed

PATCH New Mark Fasheh 2 participants 3 messages Mar 12, 2010 – Mar 19, 2010 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: Clear undo bits when local alloc is freed

When the local alloc file changes windows, unused bits are freed back to the global bitmap. By defnition, those bits can not be in use by any file. Also, the local alloc will never have been able to allocate those bits if they were part of a previous truncate. Therefore it makes sense that we should clear unused local alloc bits in the undo buffer so that they can be used immediatly.

---
 fs/ocfs2/alloc.c        |    4 ++--
 fs/ocfs2/dir.c          |    2 +-
 fs/ocfs2/localalloc.c   |    2 +-
 fs/ocfs2/refcounttree.c |    2 +-
 fs/ocfs2/suballoc.c     |   44 ++++++++++++++++++++++++++++----------------
 fs/ocfs2/suballoc.h     |    5 +++--
 fs/ocfs2/xattr.c        |    2 +-
 7 files changed, 37 insertions(+), 24 deletions(-)
fs/ocfs2/alloc.c +2 -2
index d17bdc7..c9608a5 100644
@@ -5921,7 +5921,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
 
 			status = ocfs2_free_clusters(handle, data_alloc_inode,
 						     data_alloc_bh, start_blk,
-						     num_clusters);
+						     num_clusters, 0);
 			if (status < 0) {
 				mlog_errno(status);
 				goto bail;
@@ -6349,7 +6349,7 @@ static int ocfs2_free_cached_blocks(struct ocfs2_super *osb,
 		     head->free_bit, (unsigned long long)head->free_blk);
 
 		ret = ocfs2_free_suballoc_bits(handle, inode, di_bh,
-					       head->free_bit, bg_blkno, 1);
+					       head->free_bit, bg_blkno, 1, 0);
 		if (ret) {
 			mlog_errno(ret);
 			goto out_journal;
fs/ocfs2/dir.c +1 -1
index 28c3ec2..54f711a 100644
@@ -4497,7 +4497,7 @@ static int ocfs2_dx_dir_remove_index(struct inode *dir,
 	bit = le16_to_cpu(dx_root->dr_suballoc_bit);
 	bg_blkno = ocfs2_which_suballoc_group(blk, bit);
 	ret = ocfs2_free_suballoc_bits(handle, dx_alloc_inode, dx_alloc_bh,
-				       bit, bg_blkno, 1);
+				       bit, bg_blkno, 1, 0);
 	if (ret)
 		mlog_errno(ret);
 
fs/ocfs2/localalloc.c +1 -1
index 955a60b..0347544 100644
@@ -874,7 +874,7 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
 			     ocfs2_blocks_to_clusters(osb->sb, blkno), count);
 
 			status = ocfs2_free_clusters(handle, main_bm_inode,
-						     main_bm_bh, blkno, count);
+						     main_bm_bh, blkno, count, 1);
 			if (status < 0) {
 				mlog_errno(status);
 				goto bail;
fs/ocfs2/refcounttree.c +1 -1
index 8ae65c9..4507207 100644
@@ -847,7 +847,7 @@ int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh)
 		delete_tree = 1;
 		ocfs2_erase_refcount_tree_from_list(osb, ref_tree);
 		ret = ocfs2_free_suballoc_bits(handle, alloc_inode,
-					       alloc_bh, bit, bg_blkno, 1);
+					       alloc_bh, bit, bg_blkno, 1, 0);
 		if (ret)
 			mlog_errno(ret);
 	}
fs/ocfs2/suballoc.c +28 -16

107 lines not on this page · raw message

fs/ocfs2/suballoc.h +3 -2
index a614a44..b910642 100644
@@ -118,7 +118,7 @@ int ocfs2_free_suballoc_bits(handle_t *handle,
 			     struct buffer_head *alloc_bh,
 			     unsigned int start_bit,
 			     u64 bg_blkno,
-			     unsigned int count);
+			     unsigned int count, int la_data);
 int ocfs2_free_dinode(handle_t *handle,
 		      struct inode *inode_alloc_inode,
 		      struct buffer_head *inode_alloc_bh,
@@ -127,7 +127,8 @@ int ocfs2_free_clusters(handle_t *handle,
 			struct inode *bitmap_inode,
 			struct buffer_head *bitmap_bh,
 			u64 start_blk,
-			unsigned int num_clusters);
+			unsigned int num_clusters,
+			int la_data);
 
 static inline u64 ocfs2_which_suballoc_group(u64 block, unsigned int bit)
 {
fs/ocfs2/xattr.c +1 -1
index 8fc6fb0..0d00ce3 100644
@@ -1971,7 +1971,7 @@ static int ocfs2_xattr_free_block(struct inode *inode,
 	}
 
 	ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh,
-				       bit, bg_blkno, 1);
+				       bit, bg_blkno, 1, 0);
 	if (ret < 0)
 		mlog_errno(ret);
 
Signature · 1 line
1.6.4.2
#1 lore raw

PATCH 1/1 ocfs2: Clear undo bits when local alloc is freed

Quoted 23 lines · Mark Fasheh

When the local alloc file changes windows, unused bits are freed back to the global bitmap. By defnition, those bits can not be in use by any file. Also, the local alloc will never have been able to allocate those bits if they were part of a previous truncate. Therefore it makes sense that we should clear unused local alloc bits in the undo buffer so that they can be used immediatly.

---
 fs/ocfs2/alloc.c        |    4 ++--
 fs/ocfs2/dir.c          |    2 +-
 fs/ocfs2/localalloc.c   |    2 +-
 fs/ocfs2/refcounttree.c |    2 +-
 fs/ocfs2/suballoc.c     |   44 ++++++++++++++++++++++++++++----------------
 fs/ocfs2/suballoc.h     |    5 +++--
 fs/ocfs2/xattr.c        |    2 +-
 7 files changed, 37 insertions(+), 24 deletions(-)
fs/ocfs2/alloc.c +0 -0
index d17bdc7..c9608a5 100644

fs/ocfs2/alloc.c static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, · line 5924

Quoted 5 lines
fs/ocfs2/alloc.c +1 -1
@@ -5921,7 +5921,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
 
 			status = ocfs2_free_clusters(handle, data_alloc_inode,
 						     data_alloc_bh, start_blk,
-						     num_clusters);
+						     num_clusters, 0);

Seeing all these ', 0' arguments appear, I was confused until I
saw the actual ocfs2_free_clusters change later in the patch. That made me worry I would be re-confused coming back to this code six months from now.
Here's my shot at leaving ocfs2_free_clusters() and
ocfs2_free_suballoc_bits() intact while providing the same functionality.

Joel

fs/ocfs2/localalloc.c +4 -2
index 171c691..c983715 100644
@@ -872,8 +872,10 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
 			     (unsigned long long)la_start_blk,
 			     (unsigned long long)blkno);
 
-			status = ocfs2_free_clusters(handle, main_bm_inode,
-						     main_bm_bh, blkno, count);
+			status = ocfs2_release_clusters(handle,
+							main_bm_inode,
+							main_bm_bh, blkno,
+							count);
 			if (status < 0) {
 				mlog_errno(status);
 				goto bail;
fs/ocfs2/ocfs2.h +12 -2
index 1238b49..adf5e2e 100644
@@ -763,8 +763,18 @@ static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb,
 	return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits);
 }
 
-#define ocfs2_set_bit ext2_set_bit
-#define ocfs2_clear_bit ext2_clear_bit
+static inline void _ocfs2_set_bit(unsigned int bit, unsigned long *bitmap)
+{
+	ext2_set_bit(bit, bitmap);
+}
+#define ocfs2_set_bit(bit, addr) _ocfs2_set_bit((bit), (unsigned long *)(addr))
+
+static inline void _ocfs2_clear_bit(unsigned int bit, unsigned long *bitmap)
+{
+	ext2_clear_bit(bit, bitmap);
+}
+#define ocfs2_clear_bit(bit, addr) _ocfs2_clear_bit((bit), (unsigned long *)(addr))
+
 #define ocfs2_test_bit ext2_test_bit
 #define ocfs2_find_next_zero_bit ext2_find_next_zero_bit
 #define ocfs2_find_next_bit ext2_find_next_bit
fs/ocfs2/suballoc.c +75 -42

190 lines not on this page · raw message

fs/ocfs2/suballoc.h +5 -0
index fa60723..e0f46df 100644
@@ -127,6 +127,11 @@ int ocfs2_free_clusters(handle_t *handle,
 			struct buffer_head *bitmap_bh,
 			u64 start_blk,
 			unsigned int num_clusters);
+int ocfs2_release_clusters(handle_t *handle,
+			   struct inode *bitmap_inode,
+			   struct buffer_head *bitmap_bh,
+			   u64 start_blk,
+			   unsigned int num_clusters);
 
 static inline u64 ocfs2_which_suballoc_group(u64 block, unsigned int bit)
 {
Signature · 9 lines
"If you took all of the grains of sand in the world, and lined
 them up end to end in a row, you'd be working for the government!"
	- Mr. Interesting

Joel Becker
Principal Software Developer
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
#2 lore raw

PATCH 1/1 ocfs2: Clear undo bits when local alloc is freed

Quoted 25 lines · Joel Becker
Quoted 24 lines · Mark Fasheh

When the local alloc file changes windows, unused bits are freed back to the global bitmap. By defnition, those bits can not be in use by any file. Also, the local alloc will never have been able to allocate those bits if they were part of a previous truncate. Therefore it makes sense that we should clear unused local alloc bits in the undo buffer so that they can be used immediatly.

---
 fs/ocfs2/alloc.c        |    4 ++--
 fs/ocfs2/dir.c          |    2 +-
 fs/ocfs2/localalloc.c   |    2 +-
 fs/ocfs2/refcounttree.c |    2 +-
 fs/ocfs2/suballoc.c     |   44 ++++++++++++++++++++++++++++----------------
 fs/ocfs2/suballoc.h     |    5 +++--
 fs/ocfs2/xattr.c        |    2 +-
 7 files changed, 37 insertions(+), 24 deletions(-)
fs/ocfs2/alloc.c +0 -0
index d17bdc7..c9608a5 100644
@@ -5921,7 +5921,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
 
Quoted 12 lines

fs/ocfs2/alloc.c static int ocfs2_replay_truncate_records(struct ocfs2_super *osb, · line 5924

Quoted 4 lines
fs/ocfs2/alloc.c +1 -1
 			status = ocfs2_free_clusters(handle, data_alloc_inode,
 						     data_alloc_bh, start_blk,
-						     num_clusters);
+						     num_clusters, 0);

Seeing all these ', 0' arguments appear, I was confused until I
saw the actual ocfs2_free_clusters change later in the patch. That made me worry I would be re-confused coming back to this code six months from now.
Here's my shot at leaving ocfs2_free_clusters() and
ocfs2_free_suballoc_bits() intact while providing the same functionality.

Yeah, that patch looks better. Thanks for the cleanup.

--
Mark Fasheh