Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp188325lqj; Wed, 10 Apr 2024 07:47:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXtJMrfDBzcqhcaRFmWf3oH0j/IGwpoyeflxQgIuw1kqETyI7d4hPqW7de4Fyfc99z0rlsiAP7YFQH/QVZSs60pwBYt9ZbWDiYDM5ZGiA== X-Google-Smtp-Source: AGHT+IH8Ya35F+86RiKoFeSFdDNXBTkdkhpAwkZQ0aFXf3eodEn4RIAgZTkJJnYu5yqhCuAL+bj4 X-Received: by 2002:a17:906:2998:b0:a51:e2a0:98ed with SMTP id x24-20020a170906299800b00a51e2a098edmr1877297eje.4.1712760453601; Wed, 10 Apr 2024 07:47:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760453; cv=pass; d=google.com; s=arc-20160816; b=bf/XDSp1OUYHUtQ61A6CV/bKcUxcSg33RwkdKF2jYXIEaSAgbW5lvQhF/aiNOkuaFl +gv7LJP71crOp86Y/wrDQ5mwIwqZLhxJ5asfZFT6dulqaHxjrTvL4ApsMnUdq66gputF LzTN4shkJK0v1RQ0+ldXnK1GB6nYvoKtgvXuPyMTUVUW7s/SgOddeDpNQzLByd3C7GqQ qj3KkyG8EIqP0mcuAGhbTHhAaobW+Lvh1WZ1t47c0geyIP8CS8kxxlEOha+Y0Ap7gIUe W0Yr21yhO7oRJBkkfPa1Na17lkj8SGlYVUDqf7NPOZxQUIjlt82DLBErbJRKq1Vz3Cwx AABA== 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=37SfuM5G3Dj7+7QLVyT1la8ndDsI8tsv6jHJ3LlC8EU=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=S71XtSc4dqf8Btm6uAfmXdFGsw1COQ++Ywgq8T1ffNcEp2CPIOUApEXkJ6AcdCmooT QAS//KQ8jECWnQl5DISi2hRsgIt8Qmj47rHCfqYvD8gx0XACcXuoH9nQxWBiimaIjabT FRBm5/gKhRPx9L3wZ7NwsUa57TNAZidzdP9BjbRKaP/LBXFWCXm675I9xGYwAZw2Povs zrwNZvWbB//C2BRd4cLqXeFBLqH2A4LbvdVwZxOV3Y8zcjnpxWY0lklIxVwplhtKmu4A pu/AI1vinTxw5v1zOX65stEyn65DqisPkrW0tdJBIFBinmV6JUVGMwOl+Bk9rJClRebZ ZroQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-138788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138788-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m4-20020a1709066d0400b00a519055c375si5941084ejr.152.2024.04.10.07.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-138788-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138788-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 522D11F24D24 for ; Wed, 10 Apr 2024 14:47:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E433B180A7E; Wed, 10 Apr 2024 14:38:45 +0000 (UTC) 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 BEBBA179657; Wed, 10 Apr 2024 14:38:42 +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=1712759925; cv=none; b=JZCzM3p19RLo11vs4Id8ieRmxqt9lKX3IgWkWZZWI/BrIrgVmwQUnBzoU4aAjShkjgjmH1TURIJ48OT60iGHIFnk1GTvmQIuU7ih7c1t+s2TsJZkNjbtHlewqrxdyyC6lXetCM/tBuKhCo2t0NjLnWTUaKKflHWbjhpLX2kIhwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759925; c=relaxed/simple; bh=aX2gfX0qKYkUHf7H0T+1mAzhQZIXwn9a3KNHcyddJUU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KXrsprj4gzyaslnJXw54rR8gdE8gDDxPlxa5BwKNqR2SC+W9E2CqdtgIFrLmKVgsIFSw0VPHXUlZmc7aRpHIsUISSmO69apAM67DrqueO0LIlVZzBw6Y1gKm0aC7tQObU6gJevW/9SVt58c3nYKHUO3O6mJ7YqrZvXLW0eOCBqg= 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 4VF56f2K67z4f3k6m; Wed, 10 Apr 2024 22:38:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B75FD1A0DA9; Wed, 10 Apr 2024 22:38:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S24; Wed, 10 Apr 2024 22:38:38 +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 20/34] ext4: use reserved metadata blocks when splitting extent on endio Date: Wed, 10 Apr 2024 22:29:34 +0800 Message-Id: <20240410142948.2817554-21-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RFSpBZmcwR8Jg--.63000S24 X-Coremail-Antispam: 1UD129KBjvJXoW7tr1UXw4xWrW5ZFy8Ary5Jwb_yoW8Wryfpr 9rAF1xWr40v3Wj9FW8u3WUJryrC3WUWF47GrZ8t3y29ay7Jr1ruF47K3WrZFyFqrZ7Xw4j vr40qa48Zwn5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Yi ext4 only reserved space for delalloc for data blocks, doesn't reserve space for metadata blocks in ext4_da_reserve_space(). Besides, if we enable dioread_nolock mount option, it also doesn't reserve metadata blocks for the extent status conversion. In order to prevent data loss caused by fail to allocate metadata blocks on writeback, 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 were just best efforts, if it's really running out of sapce, there is no difference between splitting extent on writeback and on IO completed, both will lead to data loss. The best way is to reserve enough space for metadata. Before that, we can at least make sure that things won't get worse if we postpone splitting extent to endio. So 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 8bc8a519f745..fcb1916a7c29 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); -- 2.39.2