Originally, the btrfs_check_data_free_space used round_down twice when
aligning the range, which to some extent increased the execution time of
the code.
After optimization, round_down only needs to be executed once, which can
improve code efficiency and increase code readability.
Signed-off-by: Lu Hongfei <[email protected]>
---
fs/btrfs/delalloc-space.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c
index 427abaf608b8..fd33b1cf1954 100644
--- a/fs/btrfs/delalloc-space.c
+++ b/fs/btrfs/delalloc-space.c
@@ -137,9 +137,8 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode,
int ret;
/* align the range */
- len = round_up(start + len, fs_info->sectorsize) -
- round_down(start, fs_info->sectorsize);
start = round_down(start, fs_info->sectorsize);
+ len = round_up(start + len, fs_info->sectorsize) - start;
if (noflush)
flush = BTRFS_RESERVE_NO_FLUSH;
--
2.39.0
On Mon, Jun 26, 2023 at 06:07:16PM +0800, Lu Hongfei wrote:
> Originally, the btrfs_check_data_free_space used round_down twice when
> aligning the range, which to some extent increased the execution time of
> the code.
> After optimization, round_down only needs to be executed once, which can
> improve code efficiency and increase code readability.
But the code is not equivalent, because there is dependency on the value
of start that changes when the line is moved.
> Signed-off-by: Lu Hongfei <[email protected]>
> ---
> fs/btrfs/delalloc-space.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c
> index 427abaf608b8..fd33b1cf1954 100644
> --- a/fs/btrfs/delalloc-space.c
> +++ b/fs/btrfs/delalloc-space.c
> @@ -137,9 +137,8 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode,
> int ret;
>
> /* align the range */
> - len = round_up(start + len, fs_info->sectorsize) -
> - round_down(start, fs_info->sectorsize);
Start is used unchanged, start + len
> start = round_down(start, fs_info->sectorsize);
> + len = round_up(start + len, fs_info->sectorsize) - start;
New code uses the rounded down start for round_up, then for "- start"
it's the same (that part is ok).
The changelog should explain why the code is still doing the same, not
just that it's reducing the number of round_down() calls.
Hello,
kernel test robot noticed "WARNING:at_fs/btrfs/space-info.h:#btrfs_add_reserved_bytes[btrfs]" on:
commit: 533c820308d1b334d45bcf76ce839e7696862d3d ("[PATCH] fs: btrfs: Optimize code execution process to save time")
url: https://github.com/intel-lab-lkp/linux/commits/Lu-Hongfei/fs-btrfs-Optimize-code-execution-process-to-save-time/20230626-180916
base: https://git.kernel.org/cgit/linux/kernel/git/kdave/linux.git for-next
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH] fs: btrfs: Optimize code execution process to save time
in testcase: xfstests
version: xfstests-x86_64-06c027a-1_20230706
with following parameters:
disk: 4HDD
fs: btrfs
test: generic-group-56
compiler: gcc-12
test machine: 4 threads Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (Skylake) with 32G memory
(please refer to attached dmesg/kmsg for entire log/backtrace)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
[ 162.967008][ T41] ------------[ cut here ]------------
[ 162.972420][ T41] WARNING: CPU: 2 PID: 41 at fs/btrfs/space-info.h:198 btrfs_add_reserved_bytes+0x5b0/0x760 [btrfs]
[ 162.983012][ T41] Modules linked in: dm_mod btrfs blake2b_generic xor raid6_pq zstd_compress libcrc32c sd_mod t10_pi crc64_rocksoft_generic intel_r
apl_msr crc64_rocksoft intel_rapl_common crc64 x86_pkg_temp_thermal sg intel_powerclamp coretemp kvm_intel kvm irqbypass crct10dif_pclmul ipmi_devintf c
rc32_pclmul mei_wdt ipmi_msghandler crc32c_intel ghash_clmulni_intel sha512_ssse3 i915 rapl wmi_bmof intel_cstate drm_buddy intel_gtt ahci libahci drm_d
isplay_helper intel_uncore drm_kms_helper libata mei_me mei syscopyarea sysfillrect sysimgblt intel_pch_thermal ttm video wmi intel_pmc_core acpi_pad dr
m fuse ip_tables
[ 163.036856][ T41] CPU: 2 PID: 41 Comm: kworker/u8:3 Tainted: G I 6.4.0-rc7-00205-g533c820308d1 #1
[ 163.047178][ T41] Hardware name: Dell Inc. OptiPlex 7040/0Y7WYT, BIOS 1.1.1 10/07/2015
[ 163.055179][ T41] Workqueue: writeback wb_workfn (flush-btrfs-10)
[ 163.061380][ T41] RIP: 0010:btrfs_add_reserved_bytes+0x5b0/0x760 [btrfs]
[ 163.068254][ T41] Code: d8 4c 0f 48 c0 e8 00 99 d6 ff 65 ff 0d a1 c7 57 3e 0f 85 29 fc ff ff 0f 1f 44 00 00 e9 1f fc ff ff 4c 39 e0 0f 83 40 fc ff
ff <0f> 0b 31 c0 e9 3a fc ff ff 48 b8 00 00 00 00 00 fc ff df 48 89 da
[ 163.087506][ T41] RSP: 0018:ffffc90000326d10 EFLAGS: 00010287
[ 163.093360][ T41] RAX: 0000000000007000 RBX: ffff88813e5db800 RCX: 0000000000000001
[ 163.101102][ T41] RDX: 1ffff11027cbb005 RSI: 0000000000000004 RDI: ffff88813e5d8020
[ 163.108845][ T41] RBP: 0000000000008000 R08: 0000000000000001 R09: 0000000000000003
[ 163.116589][ T41] R10: fffff52000064d97 R11: 0000000000008000 R12: 0000000000008000
[ 163.124333][ T41] R13: ffff88813e5d8000 R14: ffff88813e5d8028 R15: ffff88813e5d8070
[ 163.132076][ T41] FS: 0000000000000000(0000) GS:ffff888731300000(0000) knlGS:0000000000000000
[ 163.140763][ T41] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 163.147134][ T41] CR2: 00007fffc777e298 CR3: 000000086fe44002 CR4: 00000000003706e0
[ 163.154884][ T41] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 163.162624][ T41] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 163.170378][ T41] Call Trace:
[ 163.173489][ T41] <TASK>
[ 163.176259][ T41] ? __warn+0xcd/0x260
[ 163.180149][ T41] ? btrfs_add_reserved_bytes+0x5b0/0x760 [btrfs]
[ 163.186457][ T41] ? report_bug+0x267/0x2d0
[ 163.190780][ T41] ? handle_bug+0x3c/0x70
[ 163.194923][ T41] ? exc_invalid_op+0x17/0x40
[ 163.199407][ T41] ? asm_exc_invalid_op+0x1a/0x20
[ 163.204235][ T41] ? btrfs_add_reserved_bytes+0x5b0/0x760 [btrfs]
[ 163.210507][ T41] ? kmem_cache_free+0x183/0x490
[ 163.215251][ T41] find_free_extent+0x1382/0x2a80 [btrfs]
[ 163.220829][ T41] ? do_allocation+0x5e0/0x5e0 [btrfs]
[ 163.227175][ T41] btrfs_reserve_extent+0x2c2/0x600 [btrfs]
[ 163.232919][ T41] ? walk_down_tree+0x530/0x530 [btrfs]
[ 163.238317][ T41] ? __set_extent_bit+0xbb5/0x1260 [btrfs]
[ 163.243987][ T41] ? __lookup_extent_mapping+0x1d8/0x2d0 [btrfs]
[ 163.250165][ T41] cow_file_range+0x3d3/0xb30 [btrfs]
[ 163.255401][ T41] ? async_cow_start+0x80/0x80 [btrfs]
[ 163.260716][ T41] ? lock_delalloc_pages+0x160/0x160 [btrfs]
[ 163.266551][ T41] btrfs_run_delalloc_range+0x2b2/0x4b0 [btrfs]
[ 163.272641][ T41] ? submit_bio_noacct_nocheck+0x395/0x630
[ 163.278240][ T41] ? write_extent_buffer+0x1ae/0x2a0 [btrfs]
[ 163.284076][ T41] writepage_delalloc+0x175/0x290 [btrfs]
[ 163.289655][ T41] ? find_lock_delalloc_range+0x4c0/0x4c0 [btrfs]
[ 163.295926][ T41] __extent_writepage+0x248/0x810 [btrfs]
[ 163.301504][ T41] ? btrfs_do_readpage+0x1090/0x1090 [btrfs]
[ 163.307339][ T41] ? folio_clear_dirty_for_io+0x16a/0x400
[ 163.312855][ T41] extent_write_cache_pages+0x2b2/0x9a0 [btrfs]
[ 163.318949][ T41] ? __extent_writepage+0x810/0x810 [btrfs]
[ 163.324702][ T41] ? submit_eb_page+0x490/0x490 [btrfs]
[ 163.330110][ T41] ? orc_find+0x1da/0x3b0
[ 163.334853][ T41] extent_writepages+0x1cc/0x450 [btrfs]
[ 163.340347][ T41] ? extent_write_locked_range+0x830/0x830 [btrfs]
[ 163.346700][ T41] ? __module_address+0x4d/0x200
[ 163.351442][ T41] ? 0xffffffffc1825000
[ 163.355410][ T41] ? btrfs_work_helper+0x159/0x5e0 [btrfs]
[ 163.361078][ T41] do_writepages+0x17b/0x650
[ 163.365477][ T41] ? 0xffffffffc1825000
[ 163.369446][ T41] ? writeback_set_ratelimit+0x120/0x120
[ 163.374874][ T41] ? btrfs_work_helper+0x159/0x5e0 [btrfs]
[ 163.380540][ T41] ? _raw_spin_lock+0x85/0xe0
[ 163.385022][ T41] ? _raw_write_lock_irq+0xe0/0xe0
[ 163.389933][ T41] __writeback_single_inode+0xd5/0x610
[ 163.395190][ T41] ? _raw_spin_lock+0x85/0xe0
[ 163.399673][ T41] ? __mark_inode_dirty+0x800/0x800
[ 163.404676][ T41] ? wbc_attach_and_unlock_inode+0x319/0x590
[ 163.410454][ T41] ? inode_io_list_move_locked+0x25c/0x360
[ 163.416062][ T41] writeback_sb_inodes+0x4c1/0xd00
[ 163.420983][ T41] ? sync_inode_metadata+0xd0/0xd0
[ 163.425908][ T41] ? queue_io+0x284/0x380
[ 163.430053][ T41] ? ret_from_fork+0x1f/0x30
[ 163.434453][ T41] wb_writeback+0x22e/0x6b0
[ 163.438766][ T41] ? __writeback_inodes_wb+0x270/0x270
[ 163.444024][ T41] ? _raw_spin_lock_irq+0x86/0xe0
[ 163.448849][ T41] ? _raw_spin_lock_bh+0xe0/0xe0
[ 163.453592][ T41] wb_do_writeback+0x17c/0x770
[ 163.458160][ T41] ? wb_writeback+0x6b0/0x6b0
[ 163.462645][ T41] ? set_worker_desc+0x172/0x190
[ 163.467387][ T41] ? idle_cull_fn+0x3b0/0x3b0
[ 163.471872][ T41] ? btrfs_finish_one_ordered+0x425/0x1610 [btrfs]
[ 163.478224][ T41] ? kmem_cache_free+0x183/0x490
[ 163.482966][ T41] ? __btrfs_end_transaction+0x311/0x700 [btrfs]
[ 163.489143][ T41] wb_workfn+0xef/0x530
[ 163.493113][ T41] ? inode_wait_for_writeback+0x30/0x30
[ 163.498456][ T41] ? btrfs_unlink_subvol+0xc80/0xc80 [btrfs]
[ 163.504288][ T41] ? try_to_wake_up+0xf6/0x1250
[ 163.508946][ T41] ? _raw_spin_lock_irq+0x86/0xe0
[ 163.513775][ T41] ? read_word_at_a_time+0xe/0x20
[ 163.518600][ T41] ? strscpy+0xad/0x280
[ 163.522569][ T41] process_one_work+0x691/0x10b0
[ 163.527312][ T41] worker_thread+0x102/0x1360
[ 163.531796][ T41] ? process_one_work+0x10b0/0x10b0
[ 163.536794][ T41] kthread+0x2d6/0x3b0
[ 163.540681][ T41] ? kthread_complete_and_exit+0x30/0x30
[ 163.546110][ T41] ret_from_fork+0x1f/0x30
[ 163.550336][ T41] </TASK>
[ 163.553185][ T41] ---[ end trace 0000000000000000 ]---
To reproduce:
git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
sudo bin/lkp install job.yaml # job file is attached in this email
bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
sudo bin/lkp run generated-yaml-file
# if come across any failure that blocks the test,
# please remove ~/.lkp and /lkp dir to run from a clean state.
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki