From patchwork Wed Apr 10 15:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD0D3CD11C2 for ; Wed, 10 Apr 2024 15:11:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FE0F6B00BF; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45E396B00C2; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107296B00C0; Wed, 10 Apr 2024 11:11:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E12C86B00BF for ; Wed, 10 Apr 2024 11:11:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A57101A07D6 for ; Wed, 10 Apr 2024 15:11:56 +0000 (UTC) X-FDA: 81993962232.10.8A37B5C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 40D024000A for ; Wed, 10 Apr 2024 15:11:52 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712761914; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G63A/1vzHT8HBZ1GnRpYOGjnssd8Ud0KFI6wZDe0IEA=; b=pvPHcI0qKWBFAhGn6zlJ/zk/aixTKDHeIT6cfwLL7zJSh68AR4v3Rfm3DMig2YQx7n6so8 6/UPToyJEDa/FOLm/h7lV6tUSFa1LQ9pVV47wJqWSeqE62QH557UOmWx6BIr+rChduZp9q K0LhCg3t0B4y/HMOBvlkhim8OPmyhfc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf11.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712761914; a=rsa-sha256; cv=none; b=pE9NNhpaZXogMHBasXSbb/RJ1/6nyUM08Lkyfcwqml42Wdyao8sJiBxwGfreoPenAVjn1+ ADqaWCAS0BDs7cCvd1dZgdrJ/BoahFCOXp+GCGrhwnV0JBD/a6iZt3HKOgzAyuvrdOjpRX VMYjP/SE+q/sjxQmfF2+6PCYHoyD49E= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF5rw0bS5z4f3kKj for ; Wed, 10 Apr 2024 23:11:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7F0E11A0D0E for ; Wed, 10 Apr 2024 23:11:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S4; Wed, 10 Apr 2024 23:11:48 +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, david@fromorbit.com, 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 v4 29/34] ext4: fall back to buffer_head path for defrag Date: Wed, 10 Apr 2024 23:03:08 +0800 Message-Id: <20240410150313.2820364-1-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn9g4orBZmFSt+Jg--.51485S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45KryfZr4UWr15ZF1xuFg_yoW8Kry5pr 9Ikr15Kr4DXas29Fn3ta4UZr1rKa10g3y7urWfW3WxJFWDA34IgFyjkF1UAFW5trZ7JrWa qF40kr17W347G3DanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG 64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r 4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjcxG6xCI17CEII8v rVW3JVW8Jr1lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04v7Mx kF7I0En4kS14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4U MxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI 0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE 14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20x vaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r4UJVWxJr1lIxAIcVC2z280aVCY1x0267AK xVW0oVCq3bIYCTnIWIevJa73UjIFyTuYvjxU0dgAUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 40D024000A X-Stat-Signature: hfsaooduzmsguem4biszopeo3xet8eio X-HE-Tag: 1712761912-480857 X-HE-Meta: U2FsdGVkX1/6GabdYecMtJgyBgMDKHedJ62PGr9YD11gad3J9bRr7MvWaVhY/7yCDv36sak9Abew4V7PeOnmatzzku6JCHX9HIKKBphGcftmDqQt+lz/X40I93J9YeBEdEDOkby4d1F6oDWA/dC5WLy9K0DKBdlY+TkbwlVEfzxGA6xMb3J/wiM9bP8pSMpYadcWCMfr10N1HWPt8esVT4URicGY/kHGGmxkLe/juqzkv8Q0fzwsSqEZm2NA+2V1lvMx0uhNFQL58clYWOrPvaXzRsrHn1F8K+Yawhjrw7o8hfaIe2oI/wi9U0jKFDWyhtoGiZJ1KDFlHe9Qq8Lqh5/FH5nkoAe3959eOnh1XDfWICOcpgFR0y765Skzoacf7t2GGyCheROSUmS0YZhjPRR2RskwsSMJJIJhnKNb2pwBlV2kIVyv5BsUtxGDgW0+XjYc4RxjfDyG6SN5Hs1nxBDOCQDRNz4903a6P25lZ5OosrZ2vVwHoT2Ddud7UDDj6cHa3yyS2b9BVYb3QZjTVdFA1/nJ66cUBatnte85myzN2wBZ28UUZv1OKffnQAQEqXqZj8O0D+s9eWMIj5rHDapbUaQ5H/fXlZEG5VczAY8nsdZDPGkrqa5WtauW9keKM60SL6+7xt65o++F4Fzf3qevWEZBwoKyxR1u23vfI3U5IFb4jRSIA4nNYzmHKRrYNWgWsU6F19FnFa+OdNOS7jBe/qLfHvzEovQftNFy/anUq8pwpKRttpBMQlw091H+P1ClY1scX8+WOdLgGMSrl3jYTkrNzhLvaGTJIvtJORh+Kq+0AzMtVaSjyLry4MsQCVrlAvMSRWWZ7ahtO6QVwBMXExxr5AOJfEoUJ3StnZlDsdLcow654u9Uo0oL28jvRxUAPP5XyXSEG74sg0OUYp4n8zwDvhMDScV7xy9RWmH05rV4rcVZ+Aj2qN81PeI1icnvw7H7WR4nCt+aB83 9XQ1jtSS CY1FofKpVHbq8HvcHrNA0sbRcs20anRj3wPuQI9KHrZpgWNWhE3F+8xey/24QUA54nUFMUpvWFrDXaibw4aD5vyUo931zm+ABPl9rwpNp5Hcfx7MIfpi0IMIYoILbGtj/ssJROqEbcyWLyAk6ye4CAzpJx5ixQl0YS5/PdOxOuGZymsAEhZAgRmki+HhxIvm4kxVSpHYqqqmoMobm5uapab0rDjC6DSD6KSCCGqLXkArrYqw44XxsjHepmVGWk00++jYktf787uys/Xy04Ctf+WoWPC3HDnUhcwx/WCd/lwdiCbptfpkzN7pwXPyW2U4UtFA1+zIqzlVeTqI71lgSwGTevQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Online defrag doesn't support iomap path yet, we have to fall back to buffer_head path for the inode which has been using iomap. Changing active inode is dangerous, before we start, we must hold the inode lock and the mapping->invalidate_lock, and writeback all dirty folios and drop the inode's pagecache. Signed-off-by: Zhang Yi --- fs/ext4/move_extent.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 7cd4afa4de1d..3db255385367 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -538,6 +538,34 @@ mext_check_arguments(struct inode *orig_inode, return 0; } +/* + * Disable buffered iomap path for the inode that requiring move extents, + * fallback to buffer_head path. + */ +static int ext4_disable_buffered_iomap_aops(struct inode *inode) +{ + int err; + + /* + * The buffered_head aops don't know how to handle folios + * dirtied by iomap, so before falling back, flush all dirty + * folios the inode has. + */ + filemap_invalidate_lock(inode->i_mapping); + err = filemap_write_and_wait(inode->i_mapping); + if (err < 0) { + filemap_invalidate_unlock(inode->i_mapping); + return err; + } + truncate_inode_pages(inode->i_mapping, 0); + + ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + ext4_set_aops(inode); + filemap_invalidate_unlock(inode->i_mapping); + + return 0; +} + /** * ext4_move_extents - Exchange the specified range of a file * @@ -609,6 +637,12 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, inode_dio_wait(orig_inode); inode_dio_wait(donor_inode); + /* Fallback to buffer_head aops for inodes with buffered iomap aops */ + if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(orig_inode); + if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(donor_inode); + /* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem(orig_inode, donor_inode); /* Check the filesystem environment whether move_extent can be done */