Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp102386pxb; Thu, 12 Aug 2021 11:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2eZrjIYpvBsvGDB1Z+rJH0r8G0LpdvE5rTBnTMcxZEM+Ua8R254p9/v5xv35TArGwAuEp X-Received: by 2002:a92:6f0a:: with SMTP id k10mr9217ilc.105.1628794031036; Thu, 12 Aug 2021 11:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628794031; cv=none; d=google.com; s=arc-20160816; b=N4GKteygwGeEiwwqoiqiajr0Ua8e+w+pjizA6fXYHwm5m3c195GuKoIpiN3qdvcRWo ze2dRIeO2KCO50WqatbBR3nWCDHGAw72mmM0uKNGjXN+meiB3ZKd4rnDQ9zpg87/G7Pe PNw4bEhIKWUcR0f2DB7hHKFFMVsGdNsc43pCyTxGRhHfwzx9IHYY73ZXdRvqCYN7VnQO 3iF17La6c/MXVQN9dhp5khY785IQ4yAPQKYnu0+nREQL9YQIy58klE2WUa3U7kw/TSXV 5d8Br+wFF2cmbyugG9ukZau6WNM/WCMbBy9rX97otlpWrmWgE/NVME0L06IoQLqOuv60 ctWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Uj/yo15T+Z2Zrrttajgdz0exaQDCjtR2FvJzbRpja/c=; b=OeWIqugfMug/2NXtE9wtPS5f/DSDXISH9wkA8gO457ClICBmxr5OMsjUpw9IPf6E4/ vNx55LzNMkeoxvni+laW229NZ/GZHlojCyFIniN/8wew0++PXI2JOA0na9qq60+e6e3H 0ieW91+f4d7BhQ5CRbZcBeR4ffokHZVHl4/5loDpTMibYyfgwbEyBC39ErHAGrKkYM8R j2s9uH565ruM1ivDUhMNZ6A5kl22ys2vXLxOUcDrVrK2QsKV4ZmI8NJYH8ZaHY8R/Feu Ca/TarHJuUyD7XmMHPbWC2NeRth2+Om0t1K0YMeM3vCBNtL4qNNf8FK1G8o28Dp5llzb obvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si3371935ioa.67.2021.08.12.11.46.56; Thu, 12 Aug 2021 11:47:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231449AbhHLRor (ORCPT + 99 others); Thu, 12 Aug 2021 13:44:47 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:36063 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232025AbhHLRor (ORCPT ); Thu, 12 Aug 2021 13:44:47 -0400 Received: from cwcc.thunk.org (pool-72-74-133-215.bstnma.fios.verizon.net [72.74.133.215]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 17CHiGR1016019 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 13:44:17 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id BB0D415C37C1; Thu, 12 Aug 2021 13:44:16 -0400 (EDT) Date: Thu, 12 Aug 2021 13:44:16 -0400 From: "Theodore Ts'o" To: Wang Jianchao Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, adilger.kernel@dilger.ca Subject: Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range() Message-ID: References: <20210724074124.25731-1-jianchao.wan9@gmail.com> <20210724074124.25731-3-jianchao.wan9@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210724074124.25731-3-jianchao.wan9@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sat, Jul 24, 2021 at 03:41:21PM +0800, Wang Jianchao wrote: > From: Wang Jianchao > > There is no functional change in this patch but just split the > codes, which serachs free block and does trim, into a new function > ext4_try_to_trim_range. This is preparing for the following async > backgroup discard. > > Reviewed-by: Andreas Dilger > Signed-off-by: Wang Jianchao > --- > fs/ext4/mballoc.c | 102 ++++++++++++++++++++++++++-------------------- > 1 file changed, 57 insertions(+), 45 deletions(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index 018d5d3c6eeb..e3844152a643 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -6218,6 +6218,54 @@ __acquires(bitlock) > return ret; > } > > +static int ext4_try_to_trim_range(struct super_block *sb, > + struct ext4_buddy *e4b, ext4_grpblk_t start, > + ext4_grpblk_t max, ext4_grpblk_t minblocks) > +{ > + ext4_grpblk_t next, count, free_count; > + void *bitmap; > + int ret = 0; > + > + bitmap = e4b->bd_bitmap; > + start = (e4b->bd_info->bb_first_free > start) ? > + e4b->bd_info->bb_first_free : start; > + count = 0; > + free_count = 0; > + > + while (start <= max) { > + start = mb_find_next_zero_bit(bitmap, max + 1, start); > + if (start > max) > + break; > + next = mb_find_next_bit(bitmap, max + 1, start); > + > + if ((next - start) >= minblocks) { > + ret = ext4_trim_extent(sb, start, next - start, e4b); > + if (ret && ret != -EOPNOTSUPP) > + break; > + ret = 0; > + count += next - start; > + } "ret" is only used inside the if statement, so this might be better as: > + if ((next - start) >= minblocks) { > + int ret = ext4_trim_extent(sb, start, next - start, e4b); > + > + if (ret && ret != -EOPNOTSUPP) > + break; > + count += next - start; > + } ... and then drop the "int ret = 0" above. Otherwise, looks good. - Ted