From: Nate Diller <nate.diller@gmail.com>
To: Andrew Morton <akpm@osdl.org>, Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/2] fs: use simple_prepare_write to zero page data
Date: Mon, 09 Apr 2007 21:31:37 -0700 [thread overview]
Message-ID: <20070410043137.19370.15007.patchbomb.py@localhost> (raw)
In-Reply-To: <20070410043137.19370.2295.patchbomb.py@localhost>
It's common for file systems to need to zero data on either side of a write,
if a page is not Uptodate during prepare_write. It just so happens that
simple_prepare_write() in libfs.c does exactly that, so we can avoid
duplication and just call that function to zero page data.
Compile tested on x86_64.
signed-off-by: Nate Diller <nate.diller@gmail.com>
---
cifs/file.c | 9 +--------
ext4/writeback.c | 17 +----------------
reiser4/plugin/item/extent_file_ops.c | 13 +++----------
3 files changed, 5 insertions(+), 34 deletions(-)
---
diff -urpN -X dontdiff linux-2.6.21-rc6-mm1/fs/cifs/file.c linux-2.6.21-rc6-mm1-test/fs/cifs/file.c
--- linux-2.6.21-rc6-mm1/fs/cifs/file.c 2007-04-09 18:25:37.000000000 -0700
+++ linux-2.6.21-rc6-mm1-test/fs/cifs/file.c 2007-04-09 18:23:16.000000000 -0700
@@ -1955,14 +1955,7 @@ static int cifs_prepare_write(struct fil
* We don't need to read data beyond the end of the file.
* zero it, and set the page uptodate
*/
- void *kaddr = kmap_atomic(page, KM_USER0);
-
- if (from)
- memset(kaddr, 0, from);
- if (to < PAGE_CACHE_SIZE)
- memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
- flush_dcache_page(page);
- kunmap_atomic(kaddr, KM_USER0);
+ simple_prepare_write(file, page, from, to);
SetPageUptodate(page);
} else if ((file->f_flags & O_ACCMODE) != O_WRONLY) {
/* might as well read a page, it is fast enough */
diff -urpN -X dontdiff linux-2.6.21-rc6-mm1/fs/ext4/writeback.c linux-2.6.21-rc6-mm1-test/fs/ext4/writeback.c
--- linux-2.6.21-rc6-mm1/fs/ext4/writeback.c 2007-04-09 18:32:52.000000000 -0700
+++ linux-2.6.21-rc6-mm1-test/fs/ext4/writeback.c 2007-04-09 18:23:16.000000000 -0700
@@ -819,21 +819,6 @@ int ext4_wb_writepages(struct address_sp
return 0;
}
-static void ext4_wb_clear_page(struct page *page, int from, int to)
-{
- void *kaddr;
-
- if (to < PAGE_CACHE_SIZE || from > 0) {
- kaddr = kmap_atomic(page, KM_USER0);
- if (PAGE_CACHE_SIZE > to)
- memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
- if (0 < from)
- memset(kaddr, 0, from);
- flush_dcache_page(page);
- kunmap_atomic(kaddr, KM_USER0);
- }
-}
-
int ext4_wb_prepare_write(struct file *file, struct page *page,
unsigned from, unsigned to)
{
@@ -863,7 +848,7 @@ int ext4_wb_prepare_write(struct file *f
/* this block isn't allocated yet, reserve space */
wb_debug("reserve space for new block\n");
page->private = 1;
- ext4_wb_clear_page(page, from, to);
+ simple_prepare_write(file, page, from, to);
ClearPageMappedToDisk(page);
} else {
/* block is already mapped, so no need to reserve */
diff -urpN -X dontdiff linux-2.6.21-rc6-mm1/fs/reiser4/plugin/item/extent_file_ops.c linux-2.6.21-rc6-mm1-test/fs/reiser4/plugin/item/extent_file_ops.c
--- linux-2.6.21-rc6-mm1/fs/reiser4/plugin/item/extent_file_ops.c 2007-04-09 18:32:52.000000000 -0700
+++ linux-2.6.21-rc6-mm1-test/fs/reiser4/plugin/item/extent_file_ops.c 2007-04-09 18:31:34.000000000 -0700
@@ -1040,16 +1040,9 @@ ssize_t reiser4_write_extent(struct file
BUG_ON(get_current_context()->trans->atom != NULL);
lock_page(page);
- if (!PageUptodate(page) && to_page != PAGE_CACHE_SIZE) {
- void *kaddr;
-
- kaddr = kmap_atomic(page, KM_USER0);
- memset(kaddr, 0, page_off);
- memset(kaddr + page_off + to_page, 0,
- PAGE_CACHE_SIZE - (page_off + to_page));
- flush_dcache_page(page);
- kunmap_atomic(kaddr, KM_USER0);
- }
+ if (!PageUptodate(page) && to_page != PAGE_CACHE_SIZE)
+ simple_prepare_write(file, page, page_off,
+ page_off + to_page);
written = filemap_copy_from_user(page, page_off, buf, to_page);
flush_dcache_page(page);
next prev parent reply other threads:[~2007-04-10 4:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-10 4:31 [PATCH 1/2] fs: use memclear_highpage_flush to zero page data Nate Diller
2007-04-10 4:31 ` Nate Diller [this message]
2007-04-10 6:10 ` Andrew Morton
2007-04-10 9:37 ` Anton Altaparmakov
2007-04-10 21:22 ` Nate Diller
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=20070410043137.19370.15007.patchbomb.py@localhost \
--to=nate.diller@gmail.com \
--cc=akpm@osdl.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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.