Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp144465lqj; Wed, 10 Apr 2024 06:41:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZYHC39ZIYU2EioDDHA8umnIsLLY1NYQXjKJyhN2jvkxv5SDyQZfi3a5YdFX8K+Sx8s7oYP28htPJlBaGjhXSZvbdHAMJKVfbXLD1eLg== X-Google-Smtp-Source: AGHT+IHeO18QibPSjYD5vbk6AC9xDpQF/vwmXx+8kuPbtLhYf/bAGcRcgSDLUA3G75UNqiUYiB5M X-Received: by 2002:ac8:748c:0:b0:434:da41:2e4b with SMTP id v12-20020ac8748c000000b00434da412e4bmr6048453qtq.12.1712756466247; Wed, 10 Apr 2024 06:41:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712756466; cv=pass; d=google.com; s=arc-20160816; b=pZZNmfc5jRQU21AKqV1rkoJuZ+t9IwbNdde1rSrqphS6SHeAr2jdaXrq5Kee0hSMP/ QcVB1RD3yag4NWRTGt6JveF3P3X3u1O1y+x1ylzFJ+IPC/xdywI3bie9bddxDVqxOKEo adsN1GlEtq2U62lroQM+PAqyZp/EsDSTzZii0ohgn+Fcn5V4n+6Pt5yZSs+F/nu+IAh/ DZeX97+6S5C1n1xh45h21b3B187bcKPb6HAXWev/24FrtUgraIqZ0Q4xJ8EWc9jIbDdT 9ku+ml9f8ihTeMZY32LyQZTUCgA+7GzAeuBvQT9nx8qeKYKdBspFXYBqf3SMtNePSSik I57g== 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=UhGiR19HeAIu8tzXykjZgtAKLLMPZj8YX6gPScUOsdE=; b=0CdSewkAgulPsOwtF1dw8iiYbYLZTTpqRrLaAm9Rrww6HUPtqfItWUinn/AmlauGdm hX8v/rgnyF3mQTlx5if4s4C0idY/K7Bq00rUt47oPhDgwWZY56OO51/62Fla2YyBUx+B SjgX+t2EyZ+oLyaIjsRaEfic/zB1aJGBsJ1YUkFX+FQIK0qS44NBc1P82pL1GvZAsOVW 3TSp1wlt8j+eIGkDcx6Qxn3oDsaPpWF8vbJLh5RPlgRBSo+kznHZRI88slTZcNtha2wj CWwhrba8HMM9wcgQITeXwAw4MddkZTrfllZmVQqxrjRKbwj5pVlQM4yY7jI+D55vR0XZ 3PCw==; 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-1955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1955-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f40-20020a05622a1a2800b00434aef8f709si5654064qtb.78.2024.04.10.06.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1955-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 DB1281C21EAD for ; Wed, 10 Apr 2024 13:41:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8A12174ED7; Wed, 10 Apr 2024 13:37:05 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 C7A3816F0C8; Wed, 10 Apr 2024 13:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712756225; cv=none; b=sfZfbPk/h3DBF1dD5YPK92M1R4F3WEeVi9QUYBZ1aa4hEsUoaCDXL/dhDBAB8ue7OaQJa6Tpp0Yq4rlbco/K5JNjoxvASIZiTcwPn6lzKrdO/0F2iitrfCrUpTXDdSqseW0tw1DWnBV+FJq8YCHaAbV6BKDSX9IxsYh0D4BAJ8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712756225; c=relaxed/simple; bh=aHOAXjEHlVp/8KJOctpi+of6Qtv9ufx9i8fFt5zvFYQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fBH7eigaxV+M9DdojTw2x3JrS26bMAUWTIbIia/+s9cKY2N9zOKfFQgvczLFhbM3rdGw6NPJ98BPc4tngHE09aLEImFPRW10Pa13ZQg+HEDJB6PzyUcJ/383efc9ml9QFneJSEBm/dlgR6fNHVFmwg0Teb/5pTMKXeImA+6aag4= 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.56 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 dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lQ3BMsz4f3jJ9; Wed, 10 Apr 2024 21:36:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 471E71A0572; Wed, 10 Apr 2024 21:36:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S19; Wed, 10 Apr 2024 21:36:57 +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 v4 15/34] ext4: update delalloc data reserve spcae in ext4_es_insert_extent() Date: Wed, 10 Apr 2024 21:27:59 +0800 Message-Id: <20240410132818.2812377-16-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-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:cCh0CgAn+RHolRZmeCl4Jg--.8806S19 X-Coremail-Antispam: 1UD129KBjvJXoW3JryxCFy7GFy8tr1kWF13CFg_yoW7ZF47pr ZxCr1fJw1rXw1q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ofrz/ 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