From: Li Dongyang <jerry87905@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] Btrfs: do not zero the page if it's in a hole
Date: Mon, 15 Oct 2012 22:03:50 +1100 [thread overview]
Message-ID: <1350299031-2854-1-git-send-email-Jerry87905@gmail.com> (raw)
Don't bother zeroing the page if it's already a hole under there.
We can save one allocation from this.
Signed-off-by: Li Dongyang <Jerry87905@gmail.com>
---
fs/btrfs/inode.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 85a1e50..017052e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3481,6 +3481,7 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
struct btrfs_ordered_extent *ordered;
struct extent_state *cached_state = NULL;
+ struct extent_map *em = NULL;
char *kaddr;
u32 blocksize = root->sectorsize;
pgoff_t index = from >> PAGE_CACHE_SHIFT;
@@ -3538,6 +3539,20 @@ again:
goto again;
}
+ em = btrfs_get_extent_fiemap(inode, NULL, 0, page_start,
+ PAGE_CACHE_SIZE, 0);
+ if (!IS_ERR_OR_NULL(em) && em->block_start == EXTENT_MAP_HOLE) {
+ u64 em_end = extent_map_end(em);
+ if (em->start <= page_start &&
+ em_end >= page_start + PAGE_CACHE_SIZE) {
+ btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE);
+ unlock_extent_cached(io_tree, page_start, page_end,
+ &cached_state, GFP_NOFS);
+ ret = 0;
+ goto out_unlock;
+ }
+ }
+
clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end,
EXTENT_DIRTY | EXTENT_DELALLOC |
EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG,
@@ -3574,6 +3589,8 @@ out_unlock:
unlock_page(page);
page_cache_release(page);
out:
+ if (em)
+ free_extent_map(em);
return ret;
}
--
1.7.12.3
next reply other threads:[~2012-10-15 11:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-15 11:03 Li Dongyang [this message]
2012-10-15 11:03 ` [PATCH] Btrfs: try harder when we merge holes Li Dongyang
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=1350299031-2854-1-git-send-email-Jerry87905@gmail.com \
--to=jerry87905@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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).