From patchwork Mon Oct 15 11:03:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Dongyang X-Patchwork-Id: 1593371 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id A80C7DFB34 for ; Mon, 15 Oct 2012 11:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752134Ab2JOLB7 (ORCPT ); Mon, 15 Oct 2012 07:01:59 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:57748 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750739Ab2JOLB6 (ORCPT ); Mon, 15 Oct 2012 07:01:58 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so4821987pbb.19 for ; Mon, 15 Oct 2012 04:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer; bh=HIiQ15aA3y4NoKo9BT8vlihKaTCWnMgaFfzzBE52F44=; b=Z9EuGXfS7m8lu2SFfhrl6Kz+Lm8yjGQdEdrBWKx6sntxmIGnFrNU0qzveguDjGNAr+ /3kizRHXjsuw63NMofhVNhkwfbOjVQCIYuSoVtPkintwLBoJ8B/whubXCYMztAoEiYun eylGHgeQvM80wnbJKmSsfP4pKavS3awHEz9ffT/zTzWCauSpLc5O4eESHlak9f6EjYXi 6qGRP/mx+q1Ab2sqB+WsSqpfZmGKjYlNvKzwMZdc+sm8hBdjju0aJ3A/JcGqlqzZUovh LxkFf0WhdR9RxGc45BKVR4lEYnnTpvJLOhLS/jsTBdUwhzc2f6lQ09uTiH7Ac4lL2qfP XT2Q== Received: by 10.66.77.39 with SMTP id p7mr32059499paw.8.1350298917730; Mon, 15 Oct 2012 04:01:57 -0700 (PDT) Received: from localhost.localdomain (14-200-12-249.static.tpgi.com.au. [14.200.12.249]) by mx.google.com with ESMTPS id bv6sm8933538pab.13.2012.10.15.04.01.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 04:01:57 -0700 (PDT) From: Li Dongyang 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 Message-Id: <1350299031-2854-1-git-send-email-Jerry87905@gmail.com> X-Mailer: git-send-email 1.7.12.3 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 --- 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; }