linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Dong <hao.bigrat@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: Robin Dong <sanbai@taobao.com>
Subject: [PATCH 8/8 bigalloc] ext4: make cluster works for mmap
Date: Tue,  1 Nov 2011 18:53:37 +0800	[thread overview]
Message-ID: <1320144817-16397-9-git-send-email-hao.bigrat@gmail.com> (raw)
In-Reply-To: <1320144817-16397-1-git-send-email-hao.bigrat@gmail.com>

From: Robin Dong <sanbai@taobao.com>

When users write a page in mmap regioin, it need to zero out other
pages around it.

Signed-off-by: Robin Dong <sanbai@taobao.com>
---
 fs/ext4/inode.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 2b70377..56a5401 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4545,13 +4545,17 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 	struct page *page = vmf->page;
 	loff_t size;
 	unsigned long len;
-	int ret;
+	int ret, i, uninit = 0;
 	struct file *file = vma->vm_file;
 	struct inode *inode = file->f_path.dentry->d_inode;
+	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
 	struct address_space *mapping = inode->i_mapping;
+	struct ext4_write_cluster_ctxt *ewcc = NULL;
 	handle_t *handle;
 	get_block_t *get_block;
 	int retries = 0;
+	unsigned int flags = AOP_FLAG_NOFS;
+	unsigned long from, to;
 
 	/*
 	 * This check is racy but catches the common case. We rely on
@@ -4608,7 +4612,47 @@ retry_alloc:
 		ret = VM_FAULT_SIGBUS;
 		goto out;
 	}
+
+	ewcc = ext4_alloc_write_cluster_ctxt();
+	if (!ewcc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	if (sbi->s_cluster_ratio > 1) {
+		/* We need to know whether the block is allocated already
+		 */
+		struct ext4_map_blocks map;
+		map.m_lblk = page->index;
+		map.m_len = 1;
+		ret = ext4_map_blocks(handle, inode, &map, 0);
+		uninit = map.m_flags & EXT4_MAP_UNWRITTEN;
+		if (ret <= 0 || uninit) {
+			ret = ext4_prepare_cluster_left_pages(inode,
+					page->index, ewcc, flags);
+			if (ret)
+				goto err_out;
+		}
+	}
+
 	ret = __block_page_mkwrite(vma, vmf, get_block);
+	if (ret)
+		goto err_out;
+
+	if (sbi->s_cluster_ratio > 1 && uninit) {
+		ret = ext4_prepare_cluster_right_pages(inode, page->index,
+				ewcc, flags);
+		if (ret)
+			goto err_out;
+		for (i = 0; i < ewcc->w_num_pages; i++) {
+			if (!ewcc->w_pages[i] ||
+					!page_buffers(ewcc->w_pages[i]))
+				break;
+			block_commit_write(ewcc->w_pages[i],
+					0, PAGE_CACHE_SIZE);
+		}
+	}
+
 	if (!ret && ext4_should_journal_data(inode)) {
 		if (walk_page_buffers(handle, page_buffers(page), 0,
 			  PAGE_CACHE_SIZE, NULL, do_journal_get_write_access)) {
@@ -4616,13 +4660,36 @@ retry_alloc:
 			ret = VM_FAULT_SIGBUS;
 			goto out;
 		}
+
+		for (i = 0; i < ewcc->w_num_pages; i++) {
+			page = ewcc->w_pages[i];
+			if (!page || !page_buffers(page))
+				continue;
+			from = page->index << PAGE_CACHE_SHIFT;
+			to = from + PAGE_CACHE_SIZE;
+			ret = walk_page_buffers(handle, page_buffers(page),
+				from, to, NULL, do_journal_get_write_access);
+			if (ret) {
+				ret = VM_FAULT_SIGBUS;
+				goto out;
+			}
+		}
 		ext4_set_inode_state(inode, EXT4_STATE_JDATA);
 	}
+
+err_out:
+	if (ewcc) {
+		ext4_free_write_cluster_ctxt(ewcc);
+		ewcc = NULL;
+	}
 	ext4_journal_stop(handle);
 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
 		goto retry_alloc;
 out_ret:
 	ret = block_page_mkwrite_return(ret);
+
 out:
+	if (ewcc)
+		ext4_free_write_cluster_ctxt(ewcc);
 	return ret;
 }
-- 
1.7.3.2


      parent reply	other threads:[~2011-11-01 10:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-01 10:53 [PATCH 0/8 bigalloc] ext4: change unit of extent's ee_len from block to cluster Robin Dong
2011-11-01 10:53 ` [PATCH 1/8 bigalloc] ext4: get blocks from ext4_ext_get_actual_len Robin Dong
2011-11-02 18:29   ` Andreas Dilger
2011-11-03  8:50     ` Yongqiang Yang
2011-11-03 17:57       ` Andreas Dilger
2011-11-01 10:53 ` [PATCH 2/8 bigalloc] ext4: change ext4_ext_map_blocks to allocate clusters instead of blocks Robin Dong
2011-11-01 10:53 ` [PATCH 3/8 bigalloc] ext4: remove unused functions and tags Robin Dong
2011-11-01 10:53 ` [PATCH 4/8 bigalloc] ext4: zeroout extra pages when users write one page Robin Dong
2011-11-01 10:53 ` [PATCH 5/8 bigalloc] ext4: zero out extra pages when truncate file Robin Dong
2011-11-01 10:53 ` [PATCH 6/8 bigalloc] ext4: directories allocate a cluster when it need spaces Robin Dong
2011-11-01 10:53 ` [PATCH 7/8 bigalloc] ext4: align fallocate size to a whole cluster Robin Dong
2011-11-01 10:53 ` Robin Dong [this message]

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=1320144817-16397-9-git-send-email-hao.bigrat@gmail.com \
    --to=hao.bigrat@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sanbai@taobao.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).