All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Becker <Joel.Becker@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 17/41] ocfs2: Add CoW support.
Date: Thu, 20 Aug 2009 20:55:48 -0700	[thread overview]
Message-ID: <20090821035547.GA20755@mail.oracle.com> (raw)
In-Reply-To: <20090821025136.GK10558@mail.oracle.com>

On Thu, Aug 20, 2009 at 07:51:36PM -0700, Joel Becker wrote:
> 	I'm halfway through a modification of this code that splits out
> MAX_COW_BYTES from write_len.  Let me finish it tomorrow.

	I just did it.  What do you think?

Joel

diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index d59860d..7790e1d 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -2499,7 +2499,7 @@ out:
 	return ret;
 }
 
-#define	MAX_COW_BYTES	1048576
+#define	MAX_CONTIG_BYTES	1048576
 /*
  * Calculate out the start and number of virtual clusters we need to to CoW.
  *
@@ -2508,9 +2508,8 @@ out:
  * max_cpos is the place where we want to stop CoW intentionally.
  *
  * Normal we will start CoW from the beginning of extent record cotaining cpos.
- * And We will try to Cow as much clusters as we can until we reach
- * MAX_COW_BYTES. If the write_len is larger than MAX_COW_BYTES, we will
- * use that value as the maximum clusters.
+ * We try to break up extents on boundaries of MAX_CONTIG_BYTES so that we
+ * get good I/O from the resulting extent tree.
  */
 static int ocfs2_refcount_cal_cow_clusters(struct inode *inode,
 					   struct ocfs2_extent_list *el,
@@ -2525,10 +2524,11 @@ static int ocfs2_refcount_cal_cow_clusters(struct inode *inode,
 	struct buffer_head *eb_bh = NULL;
 	struct ocfs2_extent_block *eb = NULL;
 	struct ocfs2_extent_rec *rec;
-	int max_clusters = ocfs2_clusters_for_bytes(inode->i_sb, MAX_COW_BYTES);
+	int want_clusters;
+	int contig_clusters =
+		ocfs2_clusters_for_bytes(inode->i_sb, MAX_CONTIG_BYTES);
 	int leaf_clusters, rec_end = 0;
 
-	max_clusters = max_clusters < write_len ? write_len : max_clusters;
 	if (tree_height > 0) {
 		ret = ocfs2_find_leaf(INODE_CACHE(inode), el, cpos, &eb_bh);
 		if (ret) {
@@ -2587,53 +2587,84 @@ static int ocfs2_refcount_cal_cow_clusters(struct inode *inode,
 			leaf_clusters = rec_end - le32_to_cpu(rec->e_cpos);
 		}
 
-		if (*cow_len + leaf_clusters >= max_clusters) {
-			if (*cow_len == 0) {
-				/*
-				 * cpos is in a very large extent record.
-				 * So just split max_clusters from the
-				 * extent record.
-				 */
-				if ((rec_end - cpos) <= max_clusters) {
-					/*
-					 * We can take max_clusters off
-					 * the end and cover all of our
-					 * write.
-					 */
-					*cow_start = rec_end - max_clusters;
-				} else if ((*cow_start + max_clusters) >
-					   (cpos + write_len)) {
-					/*
-					 * We can take max_clusters off
-					 * the front and cover all of
-					 * our write.
-					 */
-					/* NOOP, *cow_start is already set */
-				} else {
-					/*
-					 * We're CoWing more data than
-					 * write_len for contiguousness,
-					 * but it doesn't fit at the
-					 * front or end of this extent.
-					 * Let's try to slice the extent
-					 * up nicely.  Optimally, our
-					 * CoW region starts at a
-					 * multiple of max_clusters.  If
-					 * that doesn't fit, we give up
-					 * and just CoW at cpos.
-					 */
-					*cow_start +=
-						(cpos - *cow_start) &
-							~(max_clusters - 1);
-					if ((*cow_start + max_clusters) <
-					    (cpos + write_len))
-						*cow_start = cpos;
-				}
-			}
-			*cow_len = max_clusters;
-			break;
-		} else
+		/*
+		 * How many clusters do we actually need from
+		 * this extent?  First we see how many we actually
+		 * need to complete the write.  If that's smaller
+		 * than contig_clusters, we try for
+		 * contig_clustes.
+		 */
+		if (!*cow_len)
+			want_clusters = write_len;
+		else
+			want_clusters = (cpos + write_len) -
+				(*cow_start + *cow_len);
+		if (want_clusters < contig_clusters)
+			want_clusters = contig_clusters;
+
+		/*
+		 * If the write does not cover the whole extent, we
+		 * need to calculate how we're going to split the extent.
+		 * We try to do it on contig_clusters boundaries.
+		 *
+		 * Any extent smaller than contig_clusters will be
+		 * CoWed in its entirety.
+		 */
+		if (leaf_clusters < contig_clusters)
 			*cow_len += leaf_clusters;
+		else if (*cow_len || (*cow_start == cpos)) {
+			/*
+			 * This extent needs to be CoW'd from its
+			 * beginning, so all we have to do is compute
+			 * how many clusters to grab.
+			 */
+			if (leaf_clusters < want_clusters)
+				*cow_len += leaf_clusters;
+			else
+				*cow_len += want_clusters;
+		} else if ((*cow_start + contig_clusters) >
+			   (cpos + write_len)) {
+			/*
+			 * Breaking off contig_clusters at the front
+			 * of the extent will cover our write.  That's
+			 * easy.
+			 */
+			*cow_len = contig_clusters;
+		} else if ((rec_end - cpos) <= contig_clusters) {
+			/*
+			 * Breaking off contig_clusters at the tail of
+			 * this extent will cover cpos.
+			 */
+			*cow_start = rec_end - cpos;
+			*cow_len = contig_clusters;
+		} else if ((rec_end - cpos) <= want_clusters) {
+			/*
+			 * While we can't fit the entire write in this
+			 * extent, we know that the write goes from cpos
+			 * to the end of the extent.  Break that off.
+			 */
+			*cow_start = cpos;
+			*cow_len = rec_end - cpos;
+		} else {
+			/*
+			 * Ok, the entire write lives in the middle of
+			 * this extent.
+			 * Let's try to slice the extentup nicely.
+			 * Optimally, our CoW region starts at a
+			 * multiple of contig_clusters.  If that doesn't
+			 * fit, we give up and just CoW@cpos.
+			 */
+			*cow_start += (cpos - *cow_start) &
+				~(contig_clusters - 1);
+			if ((*cow_start + want_clusters) <
+			    (cpos + write_len))
+				*cow_start = cpos;
+			*cow_len = want_clusters;
+		}
+
+		/* Have we covered our entire write yet? */
+		if ((*cow_start + *cow_len) >= (cpos + write_len))
+			break;
 
 		/*
 		 * If we reach the end of the extent block and don't get enough


-- 

Life's Little Instruction Book #450

	"Don't be afraid to say, 'I need help.'"

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127

  parent reply	other threads:[~2009-08-21  3:55 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-18  6:19 [Ocfs2-devel] [PATCH 00/41] ocfs2: Add reflink file support. V4 Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 01/41] ocfs2: Define refcount tree structure Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 02/41] ocfs2: Add metaecc for ocfs2_refcount_block Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 03/41] ocfs2: Add ocfs2_read_refcount_block Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 04/41] ocfs2: Abstract caching info checkpoint Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 05/41] ocfs2: Add new refcount tree lock resource in dlmglue Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 06/41] ocfs2: Add caching info for refcount tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 07/41] ocfs2: Add refcount tree lock mechanism Tao Ma
2009-08-19 23:25   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 08/41] ocfs2: Basic tree root operation Tao Ma
2009-08-19 23:30   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 09/41] ocfs2: Wrap ocfs2_extent_contig in ocfs2_extent_tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 10/41] ocfs2: Abstract extent split process Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 11/41] ocfs2: Add refcount b-tree as a new extent tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 12/41] ocfs2: move tree path functions to alloc.h Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 13/41] ocfs2: Add support for incrementing refcount in the tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 14/41] ocfs2: Add support of decrementing refcount for delete Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 15/41] ocfs2: Add functions for extents refcounted Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 16/41] ocfs2: Decrement refcount when truncating refcounted extents Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 17/41] ocfs2: Add CoW support Tao Ma
2009-08-21  0:59   ` Joel Becker
2009-08-21  2:04     ` Tao Ma
2009-08-21  2:51       ` Joel Becker
2009-08-21  3:04         ` Tao Ma
2009-08-21  7:10           ` Joel Becker
2009-08-21  3:55         ` Joel Becker [this message]
2009-08-21  6:25           ` Tao Ma
2009-08-21  7:07             ` Joel Becker
2009-08-21  8:24               ` Tao Ma
2009-08-21 18:39                 ` Joel Becker
2009-08-21 20:58                   ` Joel Becker
2009-08-24 15:04                     ` Tao Ma
2009-08-24 18:20                       ` Joel Becker
2009-08-25 19:30                       ` Joel Becker
2009-08-26  8:17                         ` TaoMa
2009-08-21 23:07                   ` Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 18/41] ocfs2: CoW refcount tree improvement Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 19/41] ocfs2: Integrate CoW in file write Tao Ma
2009-08-21  1:04   ` Joel Becker
2009-08-21  2:12     ` Tao Ma
2009-08-21 14:55       ` Tao Ma
2009-08-21 20:43         ` Joel Becker
2009-08-21 21:12   ` Joel Becker
2009-08-21 23:17     ` Tao Ma
2009-08-21 23:42       ` Joel Becker
2009-08-22  0:31         ` Tao Ma
2009-08-24 15:06         ` Tao Ma
2009-08-24 18:32           ` Joel Becker
2009-08-25  0:12             ` [Ocfs2-devel] [PATCH 19/41] ocfs2: Integrate CoW in file write(add refcount check) Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 20/41] ocfs2: CoW a reflinked cluster when it is truncated Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 21/41] ocfs2: Add normal functions for reflink a normal file's extents Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 22/41] ocfs2: handle file attributes issue for reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 23/41] ocfs2: Return extent flags for xattr value tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 24/41] ocfs2: Abstract duplicate clusters process in CoW Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 25/41] ocfs2: Add CoW support for xattr Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 26/41] ocfs2: Remove inode from ocfs2_xattr_bucket_get_name_value Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 27/41] ocfs2: Abstract the creation of xattr block Tao Ma
2009-08-21  1:22   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 28/41] ocfs2: Abstract ocfs2 xattr tree extend rec iteration process Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 29/41] ocfs2: Attach xattr clusters to refcount tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 30/41] ocfs2: Call refcount tree remove process properly Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 31/41] ocfs2: Create an xattr indexed block if needed Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 32/41] ocfs2: Add reflink support for xattr Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 33/41] ocfs2: Modify removing xattr process for refcount Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 34/41] ocfs2: Don't merge in 1st refcount ops of reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 35/41] ocfs2: Make transaction extend more efficient Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 36/41] ocfs2: Use proper parameter for some inode operation Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 37/41] ocfs2: Create reflinked file in orphan dir Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 38/41] ocfs2: Add preserve to reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 39/41] ocfs2: Implement ocfs2_reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 40/41] ocfs2: Enable refcount tree support Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 41/41] ocfs2: Add ioctl for reflink Tao Ma
2009-08-21  1:24 ` [Ocfs2-devel] [PATCH 00/41] ocfs2: Add reflink file support. V4 Joel Becker
2009-08-21  1:39   ` Tao Ma
2009-08-24 23:11   ` TaoMa

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=20090821035547.GA20755@mail.oracle.com \
    --to=joel.becker@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.