ocfs2-devel.oss.oracle.com archive mirror
 help / color / mirror / Atom feed
From: Tao Ma <tao.ma@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 10/17] ocfs2: Grow discontig block groups in one transaction.
Date: Thu, 22 Apr 2010 14:40:24 +0800	[thread overview]
Message-ID: <1271918431-8135-10-git-send-email-tao.ma@oracle.com> (raw)
In-Reply-To: <4BCFEF22.7080607@oracle.com>

From: Joel Becker <joel.becker@oracle.com>

Rather than extending the transaction every time we add an extent to a
discontiguous block group, we grab enough credits to fill the extent
list up front.  This means we can free the bits in the same transaction
if we end up not getting enough space.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
---
 fs/ocfs2/journal.h  |   12 ++++++++++++
 fs/ocfs2/suballoc.c |   48 ++++++++++++++++++++++--------------------------
 2 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h
index 7dc5656..b5baaa8 100644
--- a/fs/ocfs2/journal.h
+++ b/fs/ocfs2/journal.h
@@ -561,6 +561,18 @@ static inline int ocfs2_calc_group_alloc_credits(struct super_block *sb,
 	return blocks;
 }
 
+/*
+ * Allocating a discontiguous block group requires the credits from
+ * ocfs2_calc_group_alloc_credits() as well as enough credits to fill
+ * the group descriptor's extent list.  The caller already has started
+ * the transaction with ocfs2_calc_group_alloc_credits().  They extend
+ * it with these credits.
+ */
+static inline int ocfs2_calc_bg_discontig_credits(struct super_block *sb)
+{
+	return ocfs2_extent_recs_per_gd(sb);
+}
+
 static inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb,
 						unsigned int clusters_to_del,
 						struct ocfs2_dinode *fe,
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index d939742..9113da9 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -527,12 +527,6 @@ static int ocfs2_block_group_grow_discontig(handle_t *handle,
 
 	while ((needed > 0) && (le16_to_cpu(el->l_next_free_rec) <
 				le16_to_cpu(el->l_count))) {
-		status = ocfs2_extend_trans(handle, OCFS2_SUBALLOC_ALLOC);
-		if (status) {
-			mlog_errno(status);
-			goto bail;
-		}
-
 		if (min_bits > needed)
 			min_bits = needed;
 		status = ocfs2_block_group_claim_bits(osb, handle, ac,
@@ -560,11 +554,12 @@ bail:
 	return status;
 }
 
-static void ocfs2_bg_alloc_cleanup(struct inode *alloc_inode,
-				   struct buffer_head *bg_bh,
-				   struct ocfs2_cached_dealloc_ctxt *dealloc)
+static void ocfs2_bg_alloc_cleanup(handle_t *handle,
+				   struct ocfs2_alloc_context *cluster_ac,
+				   struct inode *alloc_inode,
+				   struct buffer_head *bg_bh)
 {
-	int i;
+	int i, ret;
 	struct ocfs2_group_desc *bg;
 	struct ocfs2_extent_list *el;
 	struct ocfs2_extent_rec *rec;
@@ -576,9 +571,13 @@ static void ocfs2_bg_alloc_cleanup(struct inode *alloc_inode,
 	el = &bg->bg_list;
 	for (i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) {
 		rec = &el->l_recs[i];
-		ocfs2_cache_cluster_dealloc(dealloc,
-					    le64_to_cpu(rec->e_blkno),
-					    le32_to_cpu(rec->e_leaf_clusters));
+		ret = ocfs2_free_clusters(handle, cluster_ac->ac_inode,
+					  cluster_ac->ac_bh,
+					  le64_to_cpu(rec->e_blkno),
+					  le32_to_cpu(rec->e_leaf_clusters));
+		if (ret)
+			mlog_errno(ret);
+		/* Try all the clusters to free */
 	}
 
 	ocfs2_remove_from_cache(INODE_CACHE(alloc_inode), bg_bh);
@@ -589,8 +588,7 @@ static struct buffer_head *
 ocfs2_block_group_alloc_discontig(handle_t *handle,
 				  struct inode *alloc_inode,
 				  struct ocfs2_alloc_context *ac,
-				  struct ocfs2_chain_list *cl,
-				  struct ocfs2_cached_dealloc_ctxt *dealloc)
+				  struct ocfs2_chain_list *cl)
 {
 	int status;
 	u32 bit_off, num_bits;
@@ -605,6 +603,13 @@ ocfs2_block_group_alloc_discontig(handle_t *handle,
 		goto bail;
 	}
 
+	status = ocfs2_extend_trans(handle,
+				    ocfs2_calc_bg_discontig_credits(osb->sb));
+	if (status) {
+		mlog_errno(status);
+		goto bail;
+	}
+
 	/* Claim the first region */
 	status = ocfs2_block_group_claim_bits(osb, handle, ac, min_bits,
 					      &bit_off, &num_bits);
@@ -642,7 +647,7 @@ ocfs2_block_group_alloc_discontig(handle_t *handle,
 
 bail:
 	if (status)
-		ocfs2_bg_alloc_cleanup(alloc_inode, bg_bh, dealloc);
+		ocfs2_bg_alloc_cleanup(handle, ac, alloc_inode, bg_bh);
 	return status ? ERR_PTR(status) : bg_bh;
 }
 
@@ -664,14 +669,11 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
 	u64 bg_blkno;
 	struct buffer_head *bg_bh = NULL;
 	struct ocfs2_group_desc *bg;
-	struct ocfs2_cached_dealloc_ctxt dealloc;
 
 	BUG_ON(ocfs2_is_cluster_bitmap(alloc_inode));
 
 	mlog_entry_void();
 
-	ocfs2_init_dealloc_ctxt(&dealloc);
-
 	cl = &fe->id2.i_chain;
 	status = ocfs2_reserve_clusters_with_limit(osb,
 						   le16_to_cpu(cl->cl_cpg),
@@ -703,8 +705,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
 	if (IS_ERR(bg_bh) && (PTR_ERR(bg_bh) == -ENOSPC))
 		bg_bh = ocfs2_block_group_alloc_discontig(handle,
 							  alloc_inode,
-							  ac, cl,
-							  &dealloc);
+							  ac, cl);
 	if (IS_ERR(bg_bh)) {
 		status = PTR_ERR(bg_bh);
 		bg_bh = NULL;
@@ -754,11 +755,6 @@ bail:
 	if (handle)
 		ocfs2_commit_trans(osb, handle);
 
-	if (ocfs2_dealloc_has_cluster(&dealloc)) {
-		ocfs2_schedule_truncate_log_flush(osb, 1);
-		ocfs2_run_deallocs(osb, &dealloc);
-	}
-
 	if (ac)
 		ocfs2_free_alloc_context(ac);
 
-- 
1.5.5

  parent reply	other threads:[~2010-04-22  6:40 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22  6:39 [Ocfs2-devel] [PATCH 00/17 V2] ocfs2: Support for discontiguous block group Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 01/17] ocfs2: Define data structures for discontiguous block groups Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 02/17] ocfs2: Allocate " Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 03/17] ocfs2: Pass suballocation results back via a structure Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 04/17] ocfs2: Add suballoc_loc to metadata blocks Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 05/17] ocfs2: ocfs2_claim_suballoc_bits() doesn't need an osb argument Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 06/17] ocfs2: Trim suballocations if they cross discontiguous regions Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 07/17] ocfs2: ocfs2_claim_*() don't need an ocfs2_super argument Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 08/17] ocfs2: Return allocated metadata blknos on the ocfs2_suballoc_result Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 09/17] ocfs2: Set suballoc_loc on allocated metadata Tao Ma
2010-04-22  6:40 ` Tao Ma [this message]
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 11/17] ocfs2: Don't relink cluster groups when allocating discontig block groups Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 12/17] ocfs2: Some tiny bug fixes for discontiguous block allocation Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 13/17] ocfs2: ocfs2_group_bitmap_size has to handle old volume Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 14/17] ocfs2: Add ocfs2_gd_is_discontig Tao Ma
2010-04-26 21:49   ` Joel Becker
2010-04-27  0:47     ` Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 15/17] ocfs2: Free block to the right block group Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 16/17] ocfs2: Set ac_last_group properly with discontig group Tao Ma
2010-04-22  6:40 ` [Ocfs2-devel] [PATCH 17/17] ocfs2: enable discontig block group support Tao Ma
2010-05-06  1:36 ` [Ocfs2-devel] [PATCH 00/17 V2] ocfs2: Support for discontiguous block group Joel Becker
2010-05-06  6:20   ` Tao Ma
2010-05-17 19:21 ` Joel Becker
2010-05-17 23:54   ` Tao Ma
2010-05-18 22:45     ` Joel Becker
2010-05-18 22:49       ` Joel Becker
2010-05-18 23:10         ` Tao Ma
2010-05-18 23:00       ` Tao Ma
2010-05-18 23:53         ` Joel Becker
2010-05-18 21:44   ` Mark Fasheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1271918431-8135-10-git-send-email-tao.ma@oracle.com \
    --to=tao.ma@oracle.com \
    --cc=ocfs2-devel@oss.oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).