* Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
[not found] <202107251600.qcLierqr-lkp@intel.com>
@ 2021-07-26 3:42 ` kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-07-26 3:42 UTC (permalink / raw)
To: Wang Jianchao, linux-ext4, LKML; +Cc: kbuild-all, tytso, adilger.kernel
[-- Attachment #1: Type: text/plain, Size: 17042 bytes --]
Hi Wang,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on ext4/dev]
[also build test WARNING on linux/master linus/master v5.14-rc2
next-20210723]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url:
https://github.com/0day-ci/linux/commits/Wang-Jianchao/ext4-get-discard-out-of-jbd2-commit-context/20210724-154426
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 25 hours ago
:::::: commit date: 25 hours ago
config: x86_64-randconfig-c001-20210725 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project
c63dbd850182797bc4b76124d08e1c320ab2365d)
reproduce (this is a W=1 build):
wget
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross
-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
#
https://github.com/0day-ci/linux/commit/55a3430685e83709742c1fe2e0d4b347781bcc80
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review
Wang-Jianchao/ext4-get-discard-out-of-jbd2-commit-context/20210724-154426
git checkout 55a3430685e83709742c1fe2e0d4b347781bcc80
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
clang-analyzer ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
clang-analyzer warnings: (new ones prefixed by >>)
fs/ext4/mballoc.c:1909:2: note: Taking true branch
if (ex->fe_start + ex->fe_len >
EXT4_CLUSTERS_PER_GROUP(e4b->bd_sb)) {
^
fs/ext4/mballoc.c:1911:3: note: Taking true branch
WARN_ON(1);
^
include/asm-generic/bug.h:120:2: note: expanded from macro 'WARN_ON'
if (unlikely(__ret_warn_on))
\
^
fs/ext4/mballoc.c:1911:3: note: Loop condition is false. Exiting loop
WARN_ON(1);
^
include/asm-generic/bug.h:121:3: note: expanded from macro 'WARN_ON'
__WARN();
\
^
include/asm-generic/bug.h:94:19: note: expanded from macro '__WARN'
#define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
^
arch/x86/include/asm/bug.h:78:2: note: expanded from macro
'__WARN_FLAGS'
instrumentation_begin(); \
^
include/linux/instrumentation.h:53:34: note: expanded from macro
'instrumentation_begin'
# define instrumentation_begin() do { } while(0)
^
fs/ext4/mballoc.c:1911:3: note: Loop condition is false. Exiting loop
WARN_ON(1);
^
include/asm-generic/bug.h:121:3: note: expanded from macro 'WARN_ON'
__WARN();
\
^
include/asm-generic/bug.h:94:19: note: expanded from macro '__WARN'
#define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
^
arch/x86/include/asm/bug.h:79:2: note: expanded from macro
'__WARN_FLAGS'
_BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
^
arch/x86/include/asm/bug.h:25:37: note: expanded from macro '_BUG_FLAGS'
#define _BUG_FLAGS(ins, flags)
\
^
fs/ext4/mballoc.c:1911:3: note: Loop condition is false. Exiting loop
WARN_ON(1);
^
include/asm-generic/bug.h:121:3: note: expanded from macro 'WARN_ON'
__WARN();
\
^
include/asm-generic/bug.h:94:19: note: expanded from macro '__WARN'
#define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
^
arch/x86/include/asm/bug.h:81:2: note: expanded from macro
'__WARN_FLAGS'
instrumentation_end(); \
^
include/linux/instrumentation.h:54:33: note: expanded from macro
'instrumentation_end'
# define instrumentation_end() do { } while(0)
^
fs/ext4/mballoc.c:1911:3: note: Loop condition is false. Exiting loop
WARN_ON(1);
^
include/asm-generic/bug.h:121:3: note: expanded from macro 'WARN_ON'
__WARN();
\
^
include/asm-generic/bug.h:94:19: note: expanded from macro '__WARN'
#define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN))
^
arch/x86/include/asm/bug.h:76:33: note: expanded from macro
'__WARN_FLAGS'
#define __WARN_FLAGS(flags) \
^
fs/ext4/mballoc.c:1912:3: note: 14th function call argument is an
uninitialized value
ext4_grp_locked_error(e4b->bd_sb, e4b->bd_group, 0, 0,
^
fs/ext4/ext4.h:3126:2: note: expanded from macro 'ext4_grp_locked_error'
__ext4_grp_locked_error(__func__, __LINE__, sb, grp, ino,
block, \
^
fs/ext4/mballoc.c:2597:27: warning: Value stored to 'grp' during its
initialization is never read [clang-analyzer-deadcode.DeadStores]
struct ext4_group_info *grp =
ext4_get_group_info(sb, group);
^~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/mballoc.c:2597:27: note: Value stored to 'grp' during its
initialization is never read
struct ext4_group_info *grp =
ext4_get_group_info(sb, group);
^~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/mballoc.c:3839:3: warning: Value stored to 'err' is never
read [clang-analyzer-deadcode.DeadStores]
err = PTR_ERR(bitmap_bh);
^ ~~~~~~~~~~~~~~~~~~
fs/ext4/mballoc.c:3839:3: note: Value stored to 'err' is never read
err = PTR_ERR(bitmap_bh);
^ ~~~~~~~~~~~~~~~~~~
fs/ext4/mballoc.c:3844:2: warning: Value stored to 'err' is never
read [clang-analyzer-deadcode.DeadStores]
err = -EIO;
^ ~~~~
fs/ext4/mballoc.c:3844:2: note: Value stored to 'err' is never read
err = -EIO;
^ ~~~~
fs/ext4/mballoc.c:3889:2: warning: Value stored to 'err' is never
read [clang-analyzer-deadcode.DeadStores]
err = ext4_handle_dirty_metadata(NULL, NULL, gdp_bh);
^
fs/ext4/mballoc.c:3889:2: note: Value stored to 'err' is never read
fs/ext4/mballoc.c:5746:3: warning: Value stored to 'err' is never
read [clang-analyzer-deadcode.DeadStores]
err = PTR_ERR(bitmap_bh);
^ ~~~~~~~~~~~~~~~~~~
fs/ext4/mballoc.c:5746:3: note: Value stored to 'err' is never read
err = PTR_ERR(bitmap_bh);
^ ~~~~~~~~~~~~~~~~~~
>> fs/ext4/mballoc.c:6245:4: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
ret = 0;
^ ~
fs/ext4/mballoc.c:6245:4: note: Value stored to 'ret' is never read
ret = 0;
^ ~
Suppressed 6 warnings (6 in non-user code).
Use -header-filter=.* to display errors from all non-system headers.
Use -system-headers to display errors from system headers as well.
4 warnings generated.
Suppressed 4 warnings (4 in non-user code).
Use -header-filter=.* to display errors from all non-system headers.
Use -system-headers to display errors from system headers as well.
12 warnings generated.
arch/x86/include/asm/paravirt.h:585:2: warning: Assigned value is
garbage or undefined [clang-analyzer-core.uninitialized.Assign]
PVOP_VCALL2(lock.queued_spin_lock_slowpath, lock, val);
^
arch/x86/include/asm/paravirt_types.h:547:2: note: expanded from
macro 'PVOP_VCALL2'
__PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2))
^
arch/x86/include/asm/paravirt_types.h:491:8: note: expanded from
macro '__PVOP_VCALL'
(void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS,
\
^
arch/x86/include/asm/paravirt_types.h:446:3: note: expanded from
macro '____PVOP_CALL'
PVOP_CALL_ARGS;
\
^
arch/x86/include/asm/paravirt_types.h:404:16: note: expanded from
macro 'PVOP_CALL_ARGS'
unsigned long __edi = __edi, __esi = __esi, \
^
kernel/trace/trace.c:5779:2: note: Calling 'queued_spin_lock'
arch_spin_lock(&trace_cmdline_lock);
^
include/asm-generic/qspinlock.h:117:28: note: expanded from macro
'arch_spin_lock'
#define arch_spin_lock(l) queued_spin_lock(l)
^~~~~~~~~~~~~~~~~~~
include/asm-generic/qspinlock.h:82:6: note: Assuming the condition
is false
if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val,
_Q_LOCKED_VAL)))
^
include/linux/compiler.h:77:20: note: expanded from macro 'likely'
# define likely(x) __builtin_expect(!!(x), 1)
^~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/qspinlock.h:82:2: note: Taking false branch
if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val,
_Q_LOCKED_VAL)))
^
include/asm-generic/qspinlock.h:85:2: note: Calling
'queued_spin_lock_slowpath'
queued_spin_lock_slowpath(lock, val);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/qspinlock.h:51:2: note: Calling
'pv_queued_spin_lock_slowpath'
pv_queued_spin_lock_slowpath(lock, val);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/paravirt.h:585:2: note: Assigned value is
garbage or undefined
PVOP_VCALL2(lock.queued_spin_lock_slowpath, lock, val);
^
arch/x86/include/asm/paravirt_types.h:547:2: note: expanded from
macro 'PVOP_VCALL2'
__PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/paravirt_types.h:491:8: note: expanded from
macro '__PVOP_VCALL'
(void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS,
\
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/paravirt_types.h:446:3: note: expanded from
macro '____PVOP_CALL'
PVOP_CALL_ARGS;
\
^~~~~~~~~~~~~~
arch/x86/include/asm/paravirt_types.h:404:16: note: expanded from
macro 'PVOP_CALL_ARGS'
unsigned long __edi = __edi, __esi = __esi, \
^ ~~~~~
arch/x86/include/asm/paravirt.h:590:2: warning: Assigned value is
garbage or undefined [clang-analyzer-core.uninitialized.Assign]
PVOP_ALT_VCALLEE1(lock.queued_spin_unlock, lock,
^
arch/x86/include/asm/paravirt_types.h:541:2: note: expanded from
macro 'PVOP_ALT_VCALLEE1'
__PVOP_ALT_VCALLEESAVE(op, alt, cond, PVOP_CALL_ARG1(arg1))
^
arch/x86/include/asm/paravirt_types.h:504:8: note: expanded from
macro '__PVOP_ALT_VCALLEESAVE'
(void)____PVOP_ALT_CALL(, op.func, alt, cond, CLBR_RET_REG,
\
^
arch/x86/include/asm/paravirt_types.h:460:3: note: expanded from
macro '____PVOP_ALT_CALL'
PVOP_CALL_ARGS;
\
^
arch/x86/include/asm/paravirt_types.h:404:16: note: expanded from
macro 'PVOP_CALL_ARGS'
unsigned long __edi = __edi, __esi = __esi, \
^
kernel/trace/trace.c:9948:6: note: Assuming 'tracepoint_printk' is 0
if (tracepoint_printk) {
^~~~~~~~~~~~~~~~~
kernel/trace/trace.c:9948:2: note: Taking false branch
if (tracepoint_printk) {
^
kernel/trace/trace.c:9957:2: note: Calling 'tracer_alloc_buffers'
tracer_alloc_buffers();
^~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace.c:9821:6: note: Assuming the condition is false
if (security_locked_down(LOCKDOWN_TRACEFS)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace.c:9821:2: note: Taking false branch
if (security_locked_down(LOCKDOWN_TRACEFS)) {
^
kernel/trace/trace.c:9830:15: note: TRACE_ITER_LAST_BIT is <= 32
BUILD_BUG_ON(TRACE_ITER_LAST_BIT > TRACE_FLAGS_MAX_SIZE);
^
include/linux/build_bug.h:50:19: note: expanded from macro
'BUILD_BUG_ON'
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^~~~~~~~~
include/linux/build_bug.h:39:58: note: expanded from macro
'BUILD_BUG_ON_MSG'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
vim +/ret +6245 fs/ext4/mballoc.c
7360d1731e5dc7 Lukas Czerner 2010-10-27 6220 55a3430685e837 Wang
Jianchao 2021-07-24 6221 static int ext4_try_to_trim_range(struct
super_block *sb,
55a3430685e837 Wang Jianchao 2021-07-24 6222 struct ext4_buddy *e4b,
ext4_grpblk_t start,
55a3430685e837 Wang Jianchao 2021-07-24 6223 ext4_grpblk_t max,
ext4_grpblk_t minblocks)
55a3430685e837 Wang Jianchao 2021-07-24 6224 {
55a3430685e837 Wang Jianchao 2021-07-24 6225 ext4_grpblk_t next,
count, free_count;
55a3430685e837 Wang Jianchao 2021-07-24 6226 void *bitmap;
55a3430685e837 Wang Jianchao 2021-07-24 6227 int ret = 0;
55a3430685e837 Wang Jianchao 2021-07-24 6228 55a3430685e837 Wang
Jianchao 2021-07-24 6229 bitmap = e4b->bd_bitmap;
55a3430685e837 Wang Jianchao 2021-07-24 6230 start =
(e4b->bd_info->bb_first_free > start) ?
55a3430685e837 Wang Jianchao 2021-07-24 6231
e4b->bd_info->bb_first_free : start;
55a3430685e837 Wang Jianchao 2021-07-24 6232 count = 0;
55a3430685e837 Wang Jianchao 2021-07-24 6233 free_count = 0;
55a3430685e837 Wang Jianchao 2021-07-24 6234 55a3430685e837 Wang
Jianchao 2021-07-24 6235 while (start <= max) {
55a3430685e837 Wang Jianchao 2021-07-24 6236 start =
mb_find_next_zero_bit(bitmap, max + 1, start);
55a3430685e837 Wang Jianchao 2021-07-24 6237 if (start > max)
55a3430685e837 Wang Jianchao 2021-07-24 6238 break;
55a3430685e837 Wang Jianchao 2021-07-24 6239 next =
mb_find_next_bit(bitmap, max + 1, start);
55a3430685e837 Wang Jianchao 2021-07-24 6240 55a3430685e837 Wang
Jianchao 2021-07-24 6241 if ((next - start) >= minblocks) {
55a3430685e837 Wang Jianchao 2021-07-24 6242 ret =
ext4_trim_extent(sb, start, next - start, e4b);
55a3430685e837 Wang Jianchao 2021-07-24 6243 if (ret && ret !=
-EOPNOTSUPP)
55a3430685e837 Wang Jianchao 2021-07-24 6244 break;
55a3430685e837 Wang Jianchao 2021-07-24 @6245 ret = 0;
55a3430685e837 Wang Jianchao 2021-07-24 6246 count += next - start;
55a3430685e837 Wang Jianchao 2021-07-24 6247 }
55a3430685e837 Wang Jianchao 2021-07-24 6248 free_count += next - start;
55a3430685e837 Wang Jianchao 2021-07-24 6249 start = next + 1;
55a3430685e837 Wang Jianchao 2021-07-24 6250 55a3430685e837 Wang
Jianchao 2021-07-24 6251 if (fatal_signal_pending(current)) {
55a3430685e837 Wang Jianchao 2021-07-24 6252 count = -ERESTARTSYS;
55a3430685e837 Wang Jianchao 2021-07-24 6253 break;
55a3430685e837 Wang Jianchao 2021-07-24 6254 }
55a3430685e837 Wang Jianchao 2021-07-24 6255 55a3430685e837 Wang
Jianchao 2021-07-24 6256 if (need_resched()) {
55a3430685e837 Wang Jianchao 2021-07-24 6257 ext4_unlock_group(sb,
e4b->bd_group);
55a3430685e837 Wang Jianchao 2021-07-24 6258 cond_resched();
55a3430685e837 Wang Jianchao 2021-07-24 6259 ext4_lock_group(sb,
e4b->bd_group);
55a3430685e837 Wang Jianchao 2021-07-24 6260 }
55a3430685e837 Wang Jianchao 2021-07-24 6261 55a3430685e837 Wang
Jianchao 2021-07-24 6262 if ((e4b->bd_info->bb_free - free_count) <
minblocks)
55a3430685e837 Wang Jianchao 2021-07-24 6263 break;
55a3430685e837 Wang Jianchao 2021-07-24 6264 }
55a3430685e837 Wang Jianchao 2021-07-24 6265 55a3430685e837 Wang
Jianchao 2021-07-24 6266 return count;
55a3430685e837 Wang Jianchao 2021-07-24 6267 }
55a3430685e837 Wang Jianchao 2021-07-24 6268
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29411 bytes --]
[-- Attachment #3: Attached Message Part --]
[-- Type: text/plain, Size: 150 bytes --]
_______________________________________________
kbuild mailing list -- kbuild@lists.01.org
To unsubscribe send an email to kbuild-leave@lists.01.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
2021-08-12 17:44 ` Theodore Ts'o
@ 2021-08-26 7:19 ` Wang Jianchao
0 siblings, 0 replies; 5+ messages in thread
From: Wang Jianchao @ 2021-08-26 7:19 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: linux-ext4, linux-kernel, adilger.kernel
On 2021/8/13 1:44 AM, Theodore Ts'o wrote:
> On Sat, Jul 24, 2021 at 03:41:21PM +0800, Wang Jianchao wrote:
>> From: Wang Jianchao <wangjianchao@kuaishou.com>
>>
>> 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 <adilger@dilger.ca>
>> Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
>> ---
>> 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.
>
OK, I'll do it in next version
Thanks so much
Jianchao
> - Ted
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
2021-07-24 7:41 ` [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range() Wang Jianchao
2021-08-04 15:29 ` Jan Kara
@ 2021-08-12 17:44 ` Theodore Ts'o
2021-08-26 7:19 ` Wang Jianchao
1 sibling, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2021-08-12 17:44 UTC (permalink / raw)
To: Wang Jianchao; +Cc: linux-ext4, linux-kernel, adilger.kernel
On Sat, Jul 24, 2021 at 03:41:21PM +0800, Wang Jianchao wrote:
> From: Wang Jianchao <wangjianchao@kuaishou.com>
>
> 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 <adilger@dilger.ca>
> Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
> ---
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
2021-07-24 7:41 ` [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range() Wang Jianchao
@ 2021-08-04 15:29 ` Jan Kara
2021-08-12 17:44 ` Theodore Ts'o
1 sibling, 0 replies; 5+ messages in thread
From: Jan Kara @ 2021-08-04 15:29 UTC (permalink / raw)
To: Wang Jianchao; +Cc: linux-ext4, linux-kernel, tytso, adilger.kernel
On Sat 24-07-21 15:41:21, Wang Jianchao wrote:
> From: Wang Jianchao <wangjianchao@kuaishou.com>
>
> 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 <adilger@dilger.ca>
> Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> 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;
> + }
> + free_count += next - start;
> + start = next + 1;
> +
> + if (fatal_signal_pending(current)) {
> + count = -ERESTARTSYS;
> + break;
> + }
> +
> + if (need_resched()) {
> + ext4_unlock_group(sb, e4b->bd_group);
> + cond_resched();
> + ext4_lock_group(sb, e4b->bd_group);
> + }
> +
> + if ((e4b->bd_info->bb_free - free_count) < minblocks)
> + break;
> + }
> +
> + return count;
> +}
> +
> /**
> * ext4_trim_all_free -- function to trim all free space in alloc. group
> * @sb: super block for file system
> @@ -6241,10 +6289,8 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
> ext4_grpblk_t start, ext4_grpblk_t max,
> ext4_grpblk_t minblocks)
> {
> - void *bitmap;
> - ext4_grpblk_t next, count = 0, free_count = 0;
> struct ext4_buddy e4b;
> - int ret = 0;
> + int ret;
>
> trace_ext4_trim_all_free(sb, group, start, max);
>
> @@ -6254,57 +6300,23 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
> ret, group);
> return ret;
> }
> - bitmap = e4b.bd_bitmap;
>
> ext4_lock_group(sb, group);
> - if (EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) &&
> - minblocks >= atomic_read(&EXT4_SB(sb)->s_last_trim_minblks))
> - goto out;
> -
> - start = (e4b.bd_info->bb_first_free > start) ?
> - e4b.bd_info->bb_first_free : start;
>
> - 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;
> - }
> - free_count += next - start;
> - start = next + 1;
> -
> - if (fatal_signal_pending(current)) {
> - count = -ERESTARTSYS;
> - break;
> - }
> -
> - if (need_resched()) {
> - ext4_unlock_group(sb, group);
> - cond_resched();
> - ext4_lock_group(sb, group);
> - }
> -
> - if ((e4b.bd_info->bb_free - free_count) < minblocks)
> - break;
> + if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) ||
> + minblocks < atomic_read(&EXT4_SB(sb)->s_last_trim_minblks)) {
> + ret = ext4_try_to_trim_range(sb, &e4b, start, max, minblocks);
> + if (ret >= 0)
> + EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
> + } else {
> + ret = 0;
> }
>
> - if (!ret) {
> - ret = count;
> - EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
> - }
> -out:
> ext4_unlock_group(sb, group);
> ext4_mb_unload_buddy(&e4b);
>
> ext4_debug("trimmed %d blocks in the group %d\n",
> - count, group);
> + ret, group);
>
> return ret;
> }
> --
> 2.17.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
2021-07-24 7:41 [PATCH V3 0/5] ext4: get discard out of jbd2 commit context Wang Jianchao
@ 2021-07-24 7:41 ` Wang Jianchao
2021-08-04 15:29 ` Jan Kara
2021-08-12 17:44 ` Theodore Ts'o
0 siblings, 2 replies; 5+ messages in thread
From: Wang Jianchao @ 2021-07-24 7:41 UTC (permalink / raw)
To: linux-ext4, linux-kernel; +Cc: tytso, adilger.kernel
From: Wang Jianchao <wangjianchao@kuaishou.com>
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 <adilger@dilger.ca>
Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
---
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;
+ }
+ free_count += next - start;
+ start = next + 1;
+
+ if (fatal_signal_pending(current)) {
+ count = -ERESTARTSYS;
+ break;
+ }
+
+ if (need_resched()) {
+ ext4_unlock_group(sb, e4b->bd_group);
+ cond_resched();
+ ext4_lock_group(sb, e4b->bd_group);
+ }
+
+ if ((e4b->bd_info->bb_free - free_count) < minblocks)
+ break;
+ }
+
+ return count;
+}
+
/**
* ext4_trim_all_free -- function to trim all free space in alloc. group
* @sb: super block for file system
@@ -6241,10 +6289,8 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
ext4_grpblk_t start, ext4_grpblk_t max,
ext4_grpblk_t minblocks)
{
- void *bitmap;
- ext4_grpblk_t next, count = 0, free_count = 0;
struct ext4_buddy e4b;
- int ret = 0;
+ int ret;
trace_ext4_trim_all_free(sb, group, start, max);
@@ -6254,57 +6300,23 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
ret, group);
return ret;
}
- bitmap = e4b.bd_bitmap;
ext4_lock_group(sb, group);
- if (EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) &&
- minblocks >= atomic_read(&EXT4_SB(sb)->s_last_trim_minblks))
- goto out;
-
- start = (e4b.bd_info->bb_first_free > start) ?
- e4b.bd_info->bb_first_free : start;
- 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;
- }
- free_count += next - start;
- start = next + 1;
-
- if (fatal_signal_pending(current)) {
- count = -ERESTARTSYS;
- break;
- }
-
- if (need_resched()) {
- ext4_unlock_group(sb, group);
- cond_resched();
- ext4_lock_group(sb, group);
- }
-
- if ((e4b.bd_info->bb_free - free_count) < minblocks)
- break;
+ if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) ||
+ minblocks < atomic_read(&EXT4_SB(sb)->s_last_trim_minblks)) {
+ ret = ext4_try_to_trim_range(sb, &e4b, start, max, minblocks);
+ if (ret >= 0)
+ EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
+ } else {
+ ret = 0;
}
- if (!ret) {
- ret = count;
- EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
- }
-out:
ext4_unlock_group(sb, group);
ext4_mb_unload_buddy(&e4b);
ext4_debug("trimmed %d blocks in the group %d\n",
- count, group);
+ ret, group);
return ret;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-26 7:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <202107251600.qcLierqr-lkp@intel.com>
2021-07-26 3:42 ` [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range() kernel test robot
2021-07-24 7:41 [PATCH V3 0/5] ext4: get discard out of jbd2 commit context Wang Jianchao
2021-07-24 7:41 ` [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range() Wang Jianchao
2021-08-04 15:29 ` Jan Kara
2021-08-12 17:44 ` Theodore Ts'o
2021-08-26 7:19 ` Wang Jianchao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).