From patchwork Sat Jan 27 01:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533903 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 E4DF2C47422 for ; Sat, 27 Jan 2024 02:03:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EE6D6B0099; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79BDD6B009A; Fri, 26 Jan 2024 21:02:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EF716B009B; Fri, 26 Jan 2024 21:02:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 488F46B0099 for ; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 27B74803E3 for ; Sat, 27 Jan 2024 02:02:54 +0000 (UTC) X-FDA: 81723442668.16.DC2C91E Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id AC50C40005 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320972; a=rsa-sha256; cv=none; b=trK2S379F4xbvY9M4S6etgqQPRz3yxsbd8+CZ6BnJDZj92t4tFicnYoU05iscVuN4fTRIj /rx7RYaE9osPK8hRNYhw0PUPEfV0OFwjYVxhPbK4PAvoHm0zB/KODe5IlLV/kETZ2SYQKm szwOmf496mHBWRstdp5YpznVkXh6voU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320972; 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=dyRM1jf5CeAp9qbUfvlJ8CU8r3Drv8/gQ2NAo01PoDQ=; b=v2e/IGNsM0U8taxPIGLM3zqeJkY4ntCauVSdKHY3oetreNTaxnkiwQNaKTuH+qXxLQJlEQ m2Hb42AXB9ybFh7cLlWSN+rDfNWYLn8j7Mhe+OVxt+C+bpG3FxCx+Ss1Td25Eid03Qo+RT Tzsvgh+MuQWc0ix/PHdjCbYd6TglfhU= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrj3f3Hz4f3k68 for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E765B1A0172 for ; Sat, 27 Jan 2024 10:02:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S17; Sat, 27 Jan 2024 10:02:47 +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 13/26] ext4: use reserved metadata blocks when splitting extent in endio Date: Sat, 27 Jan 2024 09:58:12 +0800 Message-Id: <20240127015825.1608160-14-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> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S17 X-Coremail-Antispam: 1UD129KBjvJXoW7CF4rtw18JFykGr1kKw1xXwb_yoW8CrWUpr 93Ar18Gr409a409aykZ3WUG34rua43WF47GrZ0q3y29FWUCFyFgr47tFyrZFyrtrWxX3Wj vF40v348AwnxAa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AC50C40005 X-Stat-Signature: 7wz5cdbt8teooq563ri5aityq8m1rmuf X-HE-Tag: 1706320971-233560 X-HE-Meta: U2FsdGVkX1/JfpeCGTTliLyC/BzFaZ+X593huD1ZUBTS3V0LZgcOgK47ukPQeR2g0GJL/4zZcxpelVdlPtEFQp4lD2AEJh3qCP5G3VxyYFl7IbwZsM1QP7bMLfBMofR7DFaxmu7IIRbg3tqbKpDUyt3m3Iwhc/iQrTQ9MoQ7OZNqjhYWh2cpqa4EU9TS336SNXW1Pd9ka+VRt83Brr/HnC8wonTAjZuFgO9JZGNuK2BX4pQBSK3NZwqEd/K7K1hf1NNKcfFpEV9h6sP1aa1xGKPILl/GdLB0s9A9g+/WxuA+tbGuvR7uEbz4ygiuG0Y71OZxK3BbU04Qu0/HAGvRLnKkZWXwswPxuU3m5V+DUei/wWZ7N7MKFrMD1E8hSFrOroKycO+/0mCw6i4JEuOdUvz3K7fC5XzRynTmH7CX6fQMBgJoGlOFQEAaRQC7ymi7RmNcbJqATeKQkIZLycK9lAc8bnM7r0DF6SHtJMIgIPvhvtiw2n3KCISRius8jKhP/tOUS3lMUYqv/HMHTEonABD7zv79XHX9MN4pv7IfenXKnFXf3YTMYcRIf2U8S7GWuq3A+MZ+FdYpACO87Xsn5Bu0X7qHSnbzOac0YZsVNDkr62YEP9Eq1UgVZlzKYoHfFwMPx9xkGOvLDZYbCz3kAmkef/gDm+KAVxKfGzMu7coUVJd0oTJyzINmxXLwKQju4Y/i3rVHd8mjn+O2McrlWw939y2CPTPVZad8f7gF92af2qOXl79+fnmE6+xkKy/6dW23X7Fh1vOP67qpB/p98B9t1BHL19QScy+So6M+PbETJySVXq9/fRjuE8AIOdRkhVfUP3tJ8k78/6WdeCs4TVBsii9ZQJ2MO371Oz72rAzHwbwX2CL19HCBn8iqBIoa9YqOKxdxATXhyoOVEQKJypmnAetDN31gNIo3Nqg9AHKx5VPTZn93rTL2TLxCVUwRNBLPDbncZ3l0Nmy95Jm R4Zj1QPx HCSWxnR8j7ADTMs1lyqWLFEpjot+s9m2/dzErOnKVJn5erCxiXOQGHOdDS1j1/JfMc7Z69igd2WcxzqWd94DVrhG55swEiThqF6zs/vy/5DKh97YT/H550aNz82oUU1KXY7ymtHDG9FYaCd81WLrZvWPxYA9+V/qyyE83PSECE7AGLQjccLU4qqoYraZ6j0TfeBp1POBAEywUtPUwmEJkEU+MJc4V+gJfZ78CoHFHZj54aO711Ty6Qckck/kxLA6hopS+xbsHz/NTt9fsq74/+I8u0QL6Z9vWKNpj 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 Now ext4 only reserved space for delalloc for data blocks in ext4_da_reserve_space(), not reserve space for meta blocks when allocating data blocks. Besides, if we enable dioread_nolock mount option, it also not reserve meta blocks for the unwritten extents to written extents conversion. In order to prevent data loss due to failed to allocate meta blocks when writing data back, we reserve 2% space or 4096 blocks for meta data, and use EXT4_GET_BLOCKS_PRE_IO to do the potential split in advance. But all these two methods are just best efforts, if it's really running out of sapce, there is no difference between splitting extent when writing data back and when I/Os are completed, both will result in data loss. The best way is to reserve enough space for metadata. Before that, we can at least make sure that things will not get worse if we postpone splitting extent in endio. Plus, after converting regular file's buffered write path from buffer_head to iomap, splitting extents in endio becomes mandatory. Now, in preparation for the future conversion, let's use reserved sapce in endio too. Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 6b64319a7df8..48d6d125ec37 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3722,7 +3722,8 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle, (unsigned long long)map->m_lblk, map->m_len); #endif err = ext4_split_convert_extents(handle, inode, map, ppath, - EXT4_GET_BLOCKS_CONVERT); + EXT4_GET_BLOCKS_CONVERT | + EXT4_GET_BLOCKS_METADATA_NOFAIL); if (err < 0) return err; path = ext4_find_extent(inode, map->m_lblk, ppath, 0);