From patchwork Wed Mar 11 03:50:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 448793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id C8A50140187; Wed, 11 Mar 2015 14:50:40 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YVXfD-0007i2-Hd; Wed, 11 Mar 2015 03:50:31 +0000 Received: from mail-pd0-f181.google.com ([209.85.192.181]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YVXf8-0007gR-4i for kernel-team@lists.ubuntu.com; Wed, 11 Mar 2015 03:50:26 +0000 Received: by pdjz10 with SMTP id z10so7572939pdj.11 for ; Tue, 10 Mar 2015 20:50:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:subject:date:message-id; bh=n+uxT5ziqeNJhQPTJTPJPlpEiF/8nLzH6FRQx73XWOk=; b=PHlOnbsgETi9kmrebn+/B7SGfKxay6lX7Mn1lK1kIwLC1bdzjnPLQCspZtYI0XAm/C yJLqaFGjjPlZR0OV9PX0sRP2Y5eHrJ03qz2wy489esQCSQJyJRlWDagXzoGBgYuhn3G3 3VSWkOIcedcjyJc59XUBlzaBn9z8n3k3QfEVxtujnTXJ8StZiktZnksNkRApI1jm9XsJ MaPq65Vlp4NKYbRP7Mdd2d1Fc4l1+n0E1UxukTAJS8/eqknMQ1prkizhacmBPFNi0s0j VnqMGvx1VW0udTrwIkP4lS+zAFNv7nZo284CWOjDUPI9w8iDsZzlD5z7vSYymPWhch4C EPjg== X-Received: by 10.66.178.139 with SMTP id cy11mr72501952pac.146.1426045825177; Tue, 10 Mar 2015 20:50:25 -0700 (PDT) Received: from localhost (li398-122.members.linode.com. [106.187.48.122]) by mx.google.com with ESMTPSA id lf13sm3503615pab.2.2015.03.10.20.50.23 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 10 Mar 2015 20:50:24 -0700 (PDT) From: Ming Lei To: kernel-team@lists.ubuntu.com Subject: [PATCH] ext4: merge uninitialized extents Date: Wed, 11 Mar 2015 11:50:19 +0800 Message-Id: <1426045819-24485-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: "Darrick J. Wong" Buglink: https://bugs.launchpad.net/bugs/1430184 Upstream commit: a9b8241 ext4: merge uninitialized extents Allow for merging uninitialized extents. Signed-off-by: Darrick J. Wong Signed-off-by: "Theodore Ts'o" Signed-off-by: Ming Lei --- fs/ext4/extents.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 9875fd0..ef4b535 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1691,7 +1691,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, * the extent that was written properly split out and conversion to * initialized is trivial. */ - if (ext4_ext_is_uninitialized(ex1) || ext4_ext_is_uninitialized(ex2)) + if (ext4_ext_is_uninitialized(ex1) != ext4_ext_is_uninitialized(ex2)) return 0; ext1_ee_len = ext4_ext_get_actual_len(ex1); @@ -1708,6 +1708,11 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, */ if (ext1_ee_len + ext2_ee_len > EXT_INIT_MAX_LEN) return 0; + if (ext4_ext_is_uninitialized(ex1) && + (ext4_test_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN) || + atomic_read(&EXT4_I(inode)->i_unwritten) || + (ext1_ee_len + ext2_ee_len > EXT_UNINIT_MAX_LEN))) + return 0; #ifdef AGGRESSIVE_TEST if (ext1_ee_len >= 4) return 0; @@ -1731,7 +1736,7 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, { struct ext4_extent_header *eh; unsigned int depth, len; - int merge_done = 0; + int merge_done = 0, uninit; depth = ext_depth(inode); BUG_ON(path[depth].p_hdr == NULL); @@ -1741,8 +1746,11 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, if (!ext4_can_extents_be_merged(inode, ex, ex + 1)) break; /* merge with next extent! */ + uninit = ext4_ext_is_uninitialized(ex); ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) + ext4_ext_get_actual_len(ex + 1)); + if (uninit) + ext4_ext_mark_uninitialized(ex); if (ex + 1 < EXT_LAST_EXTENT(eh)) { len = (EXT_LAST_EXTENT(eh) - ex - 1) @@ -1896,7 +1904,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, struct ext4_ext_path *npath = NULL; int depth, len, err; ext4_lblk_t next; - int mb_flags = 0; + int mb_flags = 0, uninit; if (unlikely(ext4_ext_get_actual_len(newext) == 0)) { EXT4_ERROR_INODE(inode, "ext4_ext_get_actual_len(newext) == 0"); @@ -1946,9 +1954,11 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, path + depth); if (err) return err; - + uninit = ext4_ext_is_uninitialized(ex); ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) + ext4_ext_get_actual_len(newext)); + if (uninit) + ext4_ext_mark_uninitialized(ex); eh = path[depth].p_hdr; nearex = ex; goto merge; @@ -1971,10 +1981,13 @@ prepend: if (err) return err; + uninit = ext4_ext_is_uninitialized(ex); ex->ee_block = newext->ee_block; ext4_ext_store_pblock(ex, ext4_ext_pblock(newext)); ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) + ext4_ext_get_actual_len(newext)); + if (uninit) + ext4_ext_mark_uninitialized(ex); eh = path[depth].p_hdr; nearex = ex; goto merge;