Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1246663pxv; Fri, 16 Jul 2021 05:13:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS+1/kiWsWBQ2K5izeZ/RUzg8iqTAaqvnanN0YGJWTS1L0C/1/azq0sUkeh86EDBiAHFYS X-Received: by 2002:a50:ee15:: with SMTP id g21mr14116014eds.334.1626437584809; Fri, 16 Jul 2021 05:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626437584; cv=none; d=google.com; s=arc-20160816; b=T754IqrBqI7PoaGpDFticHtpO5T46u1hjKJ3HRZyzAL5AnCBO//EkdSf1u0OVaclPl iiStlVoO/LHAR0i5i6U3MI2VNyNCdf3/jEvvSI9na3BFn0D1SrKEAS+sV/SRgPrmG2rB T33NjG7/FyyMR8djAoGOHfbqO9Vh+pSE2S+y//PZIwW8DIQhgtvkP+vYZCpeT1rgIZ5P bbH4SH+L+qH15M5kko1GjNMCsSXCQ2lrr7t5AEAwk4opKU531QDqZlRNGGH3Ywn18iTn DD4CtahmQWvfraOtiUbbAVGy7ZR/0F/JzDWucA4SKa9L7Zwmf/mTwVtyFmwAJorevV32 rcZA== 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=fk1YH7qx4Sin+m3Ogyt/IBA9erZVW29jP44xdzHOtvo=; b=vPsjLH+aXTkloGgQT80ADm7Df+OjhXOyp3cec2/n+xJHyqNDNnOIbdlaDfCmEfw67H n/xz8M1xQzBR1Fva96QDj+zYLa9DlAgrcfRxjwdG4xaP2WhrFlpMqhImiz35Yhmd3fit b6bjOf23AfO0RckvbMntVAh7HtOWjlow3nFuPAHFXCZIIW8ZnBlZLB3Vs1QfnJxR0Tim Mv2xuUiaxTl4uTl+tZlE+8U0lY+7VDfl/oNec9TzqEPH/pvNjQAb4uf0ImuZSBhO3ot5 2Q66xG2G3zDU7z7c0uWS6+0gsK61SUxQ0yTJ0gxO7LqmxfrYa7DHYKY1xc6N4odiLbcO lFoQ== 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 i22si10689895ejh.547.2021.07.16.05.12.40; Fri, 16 Jul 2021 05:13:04 -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 S232024AbhGPMPN (ORCPT + 99 others); Fri, 16 Jul 2021 08:15:13 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:11434 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232146AbhGPMPM (ORCPT ); Fri, 16 Jul 2021 08:15:12 -0400 Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GR95317DWzcdsS; Fri, 16 Jul 2021 20:08:55 +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; Fri, 16 Jul 2021 20:12:13 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH v3 1/4] ext4: check and update i_disksize properly Date: Fri, 16 Jul 2021 20:20:21 +0800 Message-ID: <20210716122024.1105856-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210716122024.1105856-1-yi.zhang@huawei.com> References: <20210716122024.1105856-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 Reviewed-by: Jan Kara --- 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