Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp188108lqj; Wed, 10 Apr 2024 07:47:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU7GNNT9s1LK2YvM/54Tw0+Mk+Hr6tEGZ1DEgh+yVRRAS/l5YJVq9MwINM0swTHdKUlO7HE88pQPef5XeGaI4Vey2+JzfPj3QWJIhkWlg== X-Google-Smtp-Source: AGHT+IFQeGsr5qZN/b98I6mH+H6W5sxGDHA9ZL7dphmI68Lhxno5cjKODFMBEQQyCFIchfrnDoUt X-Received: by 2002:a05:6a20:3214:b0:1a7:55f2:c92c with SMTP id hl20-20020a056a20321400b001a755f2c92cmr3088301pzc.45.1712760432191; Wed, 10 Apr 2024 07:47:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760432; cv=pass; d=google.com; s=arc-20160816; b=muUUUu/qVa5bqjbTSgM5iV5+NBJM6/euTqIriVU0RIXiW6M2olrK9+VCQS2q0Ip2Do ktnrozyemCbMSG2bYA337jQ7b5qQYUdEN78H0uajxfNNFa2XnRMOvg+WbHJqFyhA+S24 +5A4mjOfJ/GEvDVflrlbZ8f8jfaUl/BVc7TPDZZEbYh2KsWt5Urbrb1dVuA6mnEvTjPI XEhxfJWQ70HM9FQ4VWQdOER7eWILOP27/y2LOpYZQTsrpVVvY5Kl79K7YzG0gdAt7gfd wWYT1Ibj7ddPw+sW8IQNlrX5RT1YUeV0dSSHlloVq5XG8mxL67KN3fMHVkd73LYv8qGM Xn4w== 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=upAYWM8WgHqo23GX2mAxJ5/S2qs3yjrM0C+UPUpJNSw=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=yD/tMdziz9V4LqQpPUDxyn/FMk82PG3TaUu/s+sTF3kwYR7mGF+28TG+9ilx+hmcqw burQBYxvomhxeV0/2jhaSEMVIXYBKXkqlAwLcs9oMUcv29tM210Spl1nsXejT0FS364a k6r+mEDxPJm/P8VO9ix1GISY2g+fiWl2RcpGDcJyaknJlHq7M7zeEVJVPCu0ICy6dH34 8oe18+yc/juooA2CtSAPH4Bzi7Dr17iAQo3Y6iG8iKQ1bq/1riqAKbxCjYW9riTZRSso tKOKQW1TVwbAtUGOPRLsBCJH8MsZldsl2rrCYLxQozLkd1cMBvV4wt75SD+5tZ7RaNeE HOMA==; 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-ext4+bounces-1988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1988-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p14-20020a056a000b4e00b006e6f6dd1735si11241818pfo.371.2024.04.10.07.47.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:47:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1988-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6B42528503E for ; Wed, 10 Apr 2024 14:46:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6557917F361; Wed, 10 Apr 2024 14:38:43 +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 C069D179664; Wed, 10 Apr 2024 14:38:38 +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=1712759922; cv=none; b=u9UMc0euaAYHQOFBcqzAg+GYMcOK0iLl0xaGo2uOickKoMmf8TM3LGmSD8GbT3WuKWnQGgtJVdus1c1Dc4Vb0rSugd8YkTMv4p+ByoX3D2RHrPirRMWAv3QR6ZSep6DatFtiKgLUnVZOCLZYbLKNMYXnPeR0cUnJ2PdrJmP6UBg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759922; c=relaxed/simple; bh=aHOAXjEHlVp/8KJOctpi+of6Qtv9ufx9i8fFt5zvFYQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ePDKY8SXm74n6Irsvf9b/TTf7jFYIg4LI6fNRHQUIUvyU0FwexWeHJknu4Bhy5DqdaMUBO9HEkj0xvNNxuUR9NOqH6oMwOlkEzO1zyCI3s2kybXGtS8mWsG/mFeSt0b1DIsWiOW7zBCV9XAXLmlnfJJEJ4OG0o82XFYcm6Jc1+Y= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56b0cWKz4f3kJv; Wed, 10 Apr 2024 22:38:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7BF841A0568; Wed, 10 Apr 2024 22:38:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S19; Wed, 10 Apr 2024 22:38:35 +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 15/34] ext4: update delalloc data reserve spcae in ext4_es_insert_extent() Date: Wed, 10 Apr 2024 22:29:29 +0800 Message-Id: <20240410142948.2817554-16-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-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RFSpBZmcwR8Jg--.63000S19 X-Coremail-Antispam: 1UD129KBjvJXoW3JryxCFy7GFy8tr1kWF13CFg_yoW7ZF47pr ZxCr1fJw1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VCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Now we update data reserved space for delalloc after allocating new blocks in ext4_{ind|ext}_map_blocks(). If bigalloc feature is enabled, we also need to query the extents_status tree and calculate the exact reserved clusters. This is complicated and it appears ext4_es_insert_extent() is a better place to do this job, it could make things simple because __es_remove_extent() could count delalloc blocks and __revise_pending() and return newly added pending count. One special case needs to concern is the quota claiming, when bigalloc is enabled, if the delayed cluster allocation has been raced by another no-delayed allocation which doesn't overlap the delayed blocks (from fallocate, filemap, DIO...) , we cannot claim quota as usual because the racer have already done it, so we also need to check the counted reserved blocks. | one cluster | ------------------------------------------- | | delayed es | ------------------------------------------- ^ ^ | fallocate | <- don't claim quota Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 37 ------------------------------------- fs/ext4/extents_status.c | 22 +++++++++++++++++++++- fs/ext4/indirect.c | 7 ------- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index e57054bdc5fd..8bc8a519f745 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4355,43 +4355,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, goto out; } - /* - * Reduce the reserved cluster count to reflect successful deferred - * allocation of delayed allocated clusters or direct allocation of - * clusters discovered to be delayed allocated. Once allocated, a - * cluster is not included in the reserved count. - */ - if (test_opt(inode->i_sb, DELALLOC) && allocated_clusters) { - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) { - /* - * When allocating delayed allocated clusters, simply - * reduce the reserved cluster count and claim quota - */ - ext4_da_update_reserve_space(inode, allocated_clusters, - 1); - } else { - ext4_lblk_t lblk, len; - unsigned int n; - - /* - * When allocating non-delayed allocated clusters - * (from fallocate, filemap, DIO, or clusters - * allocated when delalloc has been disabled by - * ext4_nonda_switch), reduce the reserved cluster - * count by the number of allocated clusters that - * have previously been delayed allocated. Quota - * has been claimed by ext4_mb_new_blocks() above, - * so release the quota reservations made for any - * previously delayed allocated clusters. - */ - lblk = EXT4_LBLK_CMASK(sbi, map->m_lblk); - len = allocated_clusters << sbi->s_cluster_bits; - n = ext4_es_delayed_clu(inode, lblk, len); - if (n > 0) - ext4_da_update_reserve_space(inode, (int) n, 0); - } - } - /* * Cache the extent and update transaction to commit on fdatasync only * when it is _not_ an unwritten extent. diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 38ec2cc5ae3b..75227f151b8f 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -856,6 +856,8 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, struct extent_status newes; ext4_lblk_t end = lblk + len - 1; int err1 = 0, err2 = 0, err3 = 0; + struct rsvd_info rinfo; + int resv_used, pending = 0; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct extent_status *es1 = NULL; struct extent_status *es2 = NULL; @@ -894,7 +896,7 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, pr = __alloc_pending(true); write_lock(&EXT4_I(inode)->i_es_lock); - err1 = __es_remove_extent(inode, lblk, end, NULL, es1); + err1 = __es_remove_extent(inode, lblk, end, &rinfo, es1); if (err1 != 0) goto error; /* Free preallocated extent if it didn't get used. */ @@ -924,9 +926,27 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, __free_pending(pr); pr = NULL; } + pending = err3; } error: write_unlock(&EXT4_I(inode)->i_es_lock); + /* + * Reduce the reserved cluster count to reflect successful deferred + * allocation of delayed allocated clusters or direct allocation of + * clusters discovered to be delayed allocated. Once allocated, a + * cluster is not included in the reserved count. + * + * When bigalloc is enabled, allocating non-delayed allocated blocks + * which belong to delayed allocated clusters (from fallocate, filemap, + * DIO, or clusters allocated when delalloc has been disabled by + * ext4_nonda_switch()). Quota has been claimed by ext4_mb_new_blocks(), + * so release the quota reservations made for any previously delayed + * allocated clusters. + */ + resv_used = rinfo.delonly_cluster + pending; + if (resv_used) + ext4_da_update_reserve_space(inode, resv_used, + rinfo.delonly_block); if (err1 || err2 || err3 < 0) goto retry; diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index d8ca7f64f952..7404f0935c90 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -652,13 +652,6 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, ext4_update_inode_fsync_trans(handle, inode, 1); count = ar.len; - /* - * Update reserved blocks/metadata blocks after successful block - * allocation which had been deferred till now. - */ - if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) - ext4_da_update_reserve_space(inode, count, 1); - got_it: map->m_flags |= EXT4_MAP_MAPPED; map->m_pblk = le32_to_cpu(chain[depth-1].key); -- 2.39.2