Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp50632pxv; Wed, 14 Jul 2021 18:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz0x5fTU0Zw7LF/FXDX0D0aXBtLyoAB6JvkQKkojVyQbqt0/wD2rd2cuHTKNsLoqSSlCtU X-Received: by 2002:a17:906:5f99:: with SMTP id a25mr1685140eju.101.1626314361035; Wed, 14 Jul 2021 18:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626314361; cv=none; d=google.com; s=arc-20160816; b=qdsjc3vhIGD5S6BvMCg2/eWHx4HTekg+kqJIc2gM3wmOMdihPgO357Ryfx1DCp1MWF 3Lnf+A5SbZYc6bGg8DHua1x0/HbnaNAT55AlIrb1FTX1cpBaRZpfDGYv9irLTVE0Uq3K mey15BG9xr4BK/+ix+4INXvIgfTHwBGL1TCc41CkoIY8Wix4auLmTTChUs2Iv9chuv8K 51LT+k/W3FoHiISav/XIYkdwUmVzCG/jbFheO54v3vgktAjTafKtmc4ek/J7hTko0KkN VSZ7+NH+ttnLK+cocVkUD6qRl+jylew86UPFPzsgNwhXSnPpMTbmF15ClojZJGZ9AH3t XGTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=o+g0VtJYckkyZ7psHiT5i4p1EcnQXd5h8rE1JMpkxNo=; b=Xzun9kJ+5z7nZVOWiCJvgYhLiNJYINoCZEGGYYWtt/s9RnJXULoMtZYgZRTKIe05WU Duy73T4QDbSXad8F9d5mnQcl4wWzROGcvWtpnpiSSPkj6vn6n3jFVRXGWSat1TmMauZg 5uvTubSUQdtHI1YP1si/dqghnKLGrZtHbk8MXnYX2qf79Vh4n1ikQGm3qP64vjt43YZn sKr3G7dKatiWbjp2t5BTo2Rt8TjStgIlggd1l2aUx4/PfjKb5cDwXNvIiLRiG0dVQoRe 9HDGy1sVklK3wZLuHS+5Z2WaS/8FpyJcgp/b1sEdEeGuBOXniVJTf1KUSC3jXacaESnG kKzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 25si4772485ejd.711.2021.07.14.18.58.54; Wed, 14 Jul 2021 18:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231786AbhGOBtb (ORCPT + 99 others); Wed, 14 Jul 2021 21:49:31 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:11305 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231660AbhGOBta (ORCPT ); Wed, 14 Jul 2021 21:49:30 -0400 Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GQHDH0yHKz7tZ3; Thu, 15 Jul 2021 09:42:07 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme752-chm.china.huawei.com (10.3.19.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 15 Jul 2021 09:46:36 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH v2 1/4] ext4: check and update i_disksize properly Date: Thu, 15 Jul 2021 09:54:49 +0800 Message-ID: <20210715015452.2542505-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715015452.2542505-1-yi.zhang@huawei.com> References: <20210715015452.2542505-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme752-chm.china.huawei.com (10.3.19.98) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org After commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize"), i_disksize could always be updated to i_size in ext4_setattr(), and we could sure that i_disksize <= i_size since holding inode lock and if i_disksize < i_size there are delalloc writes pending in the range upto i_size. If the end of the current write is <= i_size, there's no need to touch i_disksize since writeback will push i_disksize upto i_size eventually. So we can switch to check i_size instead of i_disksize in ext4_da_write_end() when write to the end of the file. we also could remove ext4_mark_inode_dirty() together because we defer inode dirtying to generic_write_end() or ext4_da_write_inline_data_end(). Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d8de607849df..dca8e3810443 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3084,35 +3084,37 @@ static int ext4_da_write_end(struct file *file, end = start + copied - 1; /* - * generic_write_end() will run mark_inode_dirty() if i_size - * changes. So let's piggyback the i_disksize mark_inode_dirty - * into that. + * Since we are holding inode lock, we are sure i_disksize <= + * i_size. We also know that if i_disksize < i_size, there are + * delalloc writes pending in the range upto i_size. If the end of + * the current write is <= i_size, there's no need to touch + * i_disksize since writeback will push i_disksize upto i_size + * eventually. If the end of the current write is > i_size and + * inside an allocated block (ext4_da_should_update_i_disksize() + * check), we need to update i_disksize here as neither + * ext4_writepage() nor certain ext4_writepages() paths not + * allocating blocks update i_disksize. + * + * Note that we defer inode dirtying to generic_write_end() / + * ext4_da_write_inline_data_end(). */ new_i_size = pos + copied; - if (copied && new_i_size > EXT4_I(inode)->i_disksize) { + if (copied && new_i_size > inode->i_size) { if (ext4_has_inline_data(inode) || - ext4_da_should_update_i_disksize(page, end)) { + ext4_da_should_update_i_disksize(page, end)) ext4_update_i_disksize(inode, new_i_size); - /* We need to mark inode dirty even if - * new_i_size is less that inode->i_size - * bu greater than i_disksize.(hint delalloc) - */ - ret = ext4_mark_inode_dirty(handle, inode); - } } if (write_mode != CONVERT_INLINE_DATA && ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) && ext4_has_inline_data(inode)) - ret2 = ext4_da_write_inline_data_end(inode, pos, len, copied, + ret = ext4_da_write_inline_data_end(inode, pos, len, copied, page); else - ret2 = generic_write_end(file, mapping, pos, len, copied, + ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); - copied = ret2; - if (ret2 < 0) - ret = ret2; + copied = ret; ret2 = ext4_journal_stop(handle); if (unlikely(ret2 && !ret)) ret = ret2; -- 2.31.1