public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH 2/6] delalloc ENOSPC: estimate metadata blocks needed to reserve
@ 2008-06-01 23:35 Mingming Cao
  0 siblings, 0 replies; only message in thread
From: Mingming Cao @ 2008-06-01 23:35 UTC (permalink / raw)
  To: linux-ext4

ext4: delalloc --estimate need metadata blocks to reserve

From: Mingming cao <cmm@us.ibm.com>

Calculate the number of metadata blocks needed to allocate blocks
Worse case is one block per extent

Signed-off-by: Mingming cao <cmm@us.ibm.com>

---
 fs/ext4/ext4_extents.h |    1 +
 fs/ext4/extents.c      |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

Index: linux-2.6.26-rc4/fs/ext4/ext4_extents.h
===================================================================
--- linux-2.6.26-rc4.orig/fs/ext4/ext4_extents.h	2008-06-01 14:22:03.000000000 -0700
+++ linux-2.6.26-rc4/fs/ext4/ext4_extents.h	2008-06-01 14:57:57.000000000 -0700
@@ -212,6 +212,7 @@ static inline int ext4_ext_get_actual_le
 		(le16_to_cpu(ext->ee_len) - EXT_INIT_MAX_LEN));
 }
 
+extern int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks);
 extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *);
 extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t);
 extern int ext4_extent_tree_init(handle_t *, struct inode *);
Index: linux-2.6.26-rc4/fs/ext4/extents.c
===================================================================
--- linux-2.6.26-rc4.orig/fs/ext4/extents.c	2008-06-01 14:22:03.000000000 -0700
+++ linux-2.6.26-rc4/fs/ext4/extents.c	2008-06-01 14:57:57.000000000 -0700
@@ -246,6 +246,36 @@ static int ext4_ext_space_root_idx(struc
 	return size;
 }
 
+/*
+ * Calculate the number of metadata blocks needed
+ * to allocate @blocks
+ * Worse case is one block per extent
+ */
+int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks)
+{
+	int lcap, icap, rcap, leafs, idxs, num;
+	int newextents = blocks;
+
+	rcap = ext4_ext_space_root_idx(inode);
+	lcap = ext4_ext_space_block(inode);
+	icap = ext4_ext_space_block_idx(inode);
+
+	/* number of new leaf blocks needed */
+	num = leafs = (newextents + lcap - 1) / lcap;
+
+	/*
+	 * Worse case, we need separate index block(s)
+	 * to link all new leaf blocks
+	 */
+	idxs = (leafs + icap - 1) / icap;
+	do {
+	        num += idxs;
+	        idxs = (idxs + icap - 1) / icap;
+	} while (idxs > rcap);
+
+	return num;
+}
+
 static int
 ext4_ext_max_entries(struct inode *inode, int depth)
 {



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-01 23:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-01 23:35 [RFC][PATCH 2/6] delalloc ENOSPC: estimate metadata blocks needed to reserve Mingming Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox