Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp45532rdb; Fri, 26 Jan 2024 18:11:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFO8Gy5iHXfuDFZnkjAWIUgrUyK02Wq++HbBYc1+kzy8vVw/0j00sWOt7ZMaosw31U8ydVS X-Received: by 2002:ac8:5a55:0:b0:42a:8004:888f with SMTP id o21-20020ac85a55000000b0042a8004888fmr1013249qta.61.1706321503115; Fri, 26 Jan 2024 18:11:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706321503; cv=pass; d=google.com; s=arc-20160816; b=W8QrH7oJymGYyfsAV0EB86fREMbvwz1DMtZ1CB3GMjG6mpvZC/8213ywZjqQ/RqeQB oQQkDUa4VpOztsgtJzCHCLaewDUbmAlCT01jSDNrg+sZxnvz3b+xv2/1CB+GgPThEj/b PezrSQ390Za30bG+VuKH+y4r1sr2R4AQqLCobYOb0jqlzNGylWSVw77TW/LuNgdHNgOi 5XvqW/jcfyIZ7jeCB54JOPnvF1XSYBUrzntW+ke2cGEWlYGUz+T9DBWC4T5Q5lg88UVF 9XG7YnUUC1x7b5uG/NbFuVK8ud/InYoEQai+dcNWUhYvN2otpiTMPchnI0Ho9s1gE93e mpUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5hFbF0KxnHt4vEEsH7/8Qchlvjc2GO7GkzsMdnMu9kI=; fh=UhGiR19HeAIu8tzXykjZgtAKLLMPZj8YX6gPScUOsdE=; b=QL8cMzaJRWBv3DHKmwDP3MNwdHlW6d7jOxgE/qmEkBKMp+JIJKkQ+v8QT+or4uIPWi z4aswfBMhf1KJQFOswkBRR9Kq6EqwarY2bEyiNxnW1JXnH/AHJA37LHnh+za1DRXxSF6 7Hfqx1jQ/F1cFuEYLe0vxQ45Byv2NsPDSydxbRyb4rkkVLjXyUq6bAPwfoX4n4j4pGz7 fyDfQHXGeKArsktOJZz4Hezv4ywbJDeJRVGpUb0wn7Vih8KyboQ4fnWY7Ck+lSZNxOp/ grYc9qvoNZFKIm+mYULh85D5SEmwxhsPGsWr8wWNT3QYgLm+FaLBMgVH9hiGUQ5aLG/D kp5A== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-973-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x10-20020ac87eca000000b0042a81457e69si1928589qtj.394.2024.01.26.18.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 18:11:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-973-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BD4901C21577 for ; Sat, 27 Jan 2024 02:11:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B49E32193; Sat, 27 Jan 2024 02:03:00 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0EB62D054; Sat, 27 Jan 2024 02:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706320980; cv=none; b=G7tk6tHIKzBuEAlOInl/hkrTKqOa7TepqvCd5KwOQMOu94JC/ydNulykozsfGop6AE1QcJidfX2zVutG90sCTm5v15o2asu7jrz3W09g9Ns+iOfpSUvk9dMOH4mInA/fIFqrMusbQSEYMHwvQryQWee1bfkByTyoDdfQDcDb3g4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706320980; c=relaxed/simple; bh=P5Kc9FtgEZ5BDpINem6S/h/J6MaE0rbkxN50rLHq4vM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bsFrYR3/tVGY9CY2yzw+fsJ1ZvUrlyg0bzJ63u5lqCtcsH4G6xUD2NI+i29l7FUoh9d/sKIl3A69wupFcaIFMkLKcbsh+Q4934ZNJvELgFOgDDoTjdTfs8Gg4g7+TUnsyMsIzMjWZPX1K2liqCT0zACVzX86FE/aXtQvGeaQ5JU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrr68bhz4f3k6S; Sat, 27 Jan 2024 10:02:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 48EA01A01E9; Sat, 27 Jan 2024 10:02:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S28; Sat, 27 Jan 2024 10:02:55 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v3 24/26] ext4: partially enable iomap for regular file's buffered IO path Date: Sat, 27 Jan 2024 09:58:23 +0800 Message-Id: <20240127015825.1608160-25-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX5g40ZLRlGJtmCA--.7377S28 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyxGFy5GF1xXFy8XFyrWFg_yoWrXw18pF ZIkr1rJr48u3s7ur4ftF48Zr1ava1xK3yUGrWSgwn5JFyrJ3WSqF1FyF1YyF15JrZ5u3WS qF48CF15uw47urDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbCe HDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Partially enable iomap for regular file's buffered IO path on default mount option and default filesystem features. Set inode state flag EXT4_STATE_BUFFERED_IOMAP when creating one inode to indicate that this inode choice the iomap path. Now it still have many limitations, it doesn't support inline data, fs_verity, fs_crypt, defrag, bigalloc, dax and data=journal mode yet, so we have to fallback to buffered_head path if these options/features were enabled. I hope these would be supported gradually in the future. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index eaf29bade606..16dce8701c5e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2972,6 +2972,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +bool ext4_should_use_buffered_iomap(struct inode *inode); int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index e9bbb1da2d0a..956b9d69c559 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,6 +1336,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; ei->i_datasync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f8e9f566ef6a..30067775e828 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -774,6 +774,8 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, if (ext4_has_inline_data(inode)) return -ERANGE; + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; map.m_lblk = iblock; map.m_len = bh->b_size >> inode->i_blkbits; @@ -2552,6 +2554,9 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) trace_ext4_writepages(inode, wbc); + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; + /* * No pages to write? This is mainly a kludge to avoid starting * a transaction for special inodes like journal inode on last iput() @@ -5089,6 +5094,32 @@ static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) return NULL; } +bool ext4_should_use_buffered_iomap(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + if (ext4_has_feature_inline_data(sb)) + return false; + if (ext4_has_feature_verity(sb)) + return false; + if (ext4_has_feature_bigalloc(sb)) + return false; + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (IS_DAX(inode)) + return false; + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE)) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) + return false; + + return true; +} + struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ext4_iget_flags flags, const char *function, unsigned int line) @@ -5353,6 +5384,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations; -- 2.39.2