Message ID | 20220314175532.GB8165@magnolia (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] btrfs: fix fallocate to use file_modified to update permissions consistently | expand |
On Mon, Mar 14, 2022 at 10:55:32AM -0700, Darrick J. Wong wrote: > From: Darrick J. Wong <djwong@kernel.org> > > Since the initial introduction of (posix) fallocate back at the turn of > the century, it has been possible to use this syscall to change the > user-visible contents of files. This can happen by extending the file > size during a preallocation, or through any of the newer modes (punch, > zero range). Because the call can be used to change file contents, we > should treat it like we do any other modification to a file -- update > the mtime, and drop set[ug]id privileges/capabilities. > > The VFS function file_modified() does all this for us if pass it a > locked inode, so let's make fallocate drop permissions correctly. > > Signed-off-by: Darrick J. Wong <djwong@kernel.org> > --- > v2: move up file_modified to catch a case where we could modify file > contents but fail on something else before we end up calling > file_modified Reviewed-by: Filipe Manana <fdmanana@suse.com> Thanks, it looks good Darrick. It also survived a few full fstests runs. > --- > fs/btrfs/file.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > index a0179cc62913..28ddd9cf2069 100644 > --- a/fs/btrfs/file.c > +++ b/fs/btrfs/file.c > @@ -2918,8 +2918,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, > return ret; > } > > -static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) > +static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) > { > + struct inode *inode = file_inode(file); > struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); > struct btrfs_root *root = BTRFS_I(inode)->root; > struct extent_state *cached_state = NULL; > @@ -2951,6 +2952,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) > goto out_only_mutex; > } > > + ret = file_modified(file); > + if (ret) > + goto out_only_mutex; > + > lockstart = round_up(offset, btrfs_inode_sectorsize(BTRFS_I(inode))); > lockend = round_down(offset + len, > btrfs_inode_sectorsize(BTRFS_I(inode))) - 1; > @@ -3391,7 +3396,7 @@ static long btrfs_fallocate(struct file *file, int mode, > return -EOPNOTSUPP; > > if (mode & FALLOC_FL_PUNCH_HOLE) > - return btrfs_punch_hole(inode, offset, len); > + return btrfs_punch_hole(file, offset, len); > > /* > * Only trigger disk allocation, don't trigger qgroup reserve > @@ -3413,6 +3418,10 @@ static long btrfs_fallocate(struct file *file, int mode, > goto out; > } > > + ret = file_modified(file); > + if (ret) > + goto out; > + > /* > * TODO: Move these two operations after we have checked > * accurate reserved space, or fallocate can still fail but
On Mon, Mar 14, 2022 at 10:55:32AM -0700, Darrick J. Wong wrote: > From: Darrick J. Wong <djwong@kernel.org> > > Since the initial introduction of (posix) fallocate back at the turn of > the century, it has been possible to use this syscall to change the > user-visible contents of files. This can happen by extending the file > size during a preallocation, or through any of the newer modes (punch, > zero range). Because the call can be used to change file contents, we > should treat it like we do any other modification to a file -- update > the mtime, and drop set[ug]id privileges/capabilities. > > The VFS function file_modified() does all this for us if pass it a > locked inode, so let's make fallocate drop permissions correctly. > > Signed-off-by: Darrick J. Wong <djwong@kernel.org> > --- > v2: move up file_modified to catch a case where we could modify file > contents but fail on something else before we end up calling > file_modified Added to misc-next, thanks.
Greeting, FYI, we noticed a 29.3% improvement of fio.write_iops due to commit: commit: 7664aed02431897aff0c2c96c683176ba7ba72f6 ("[PATCH v2] btrfs: fix fallocate to use file_modified to update permissions consistently") url: https://github.com/0day-ci/linux/commits/Darrick-J-Wong/btrfs-fix-fallocate-to-use-file_modified-to-update-permissions-consistently/20220315-015717 base: https://git.kernel.org/cgit/linux/kernel/git/kdave/linux.git for-next patch link: https://lore.kernel.org/linux-btrfs/20220314175532.GB8165@magnolia in testcase: fio-basic on test machine: 96 threads 2 sockets Ice Lake with 256G memory with following parameters: runtime: 300s disk: 1HDD fs: btrfs nr_task: 100% test_size: 128G rw: randwrite bs: 4k ioengine: ftruncate cpufreq_governor: performance ucode: 0xb000280 test-description: Fio is a tool that will spawn a number of threads or processes doing a particular type of I/O action as specified by the user. test-url: https://github.com/axboe/fio Details are as below: --------------------------------------------------------------------------------------------------> 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. ========================================================================================= bs/compiler/cpufreq_governor/disk/fs/ioengine/kconfig/nr_task/rootfs/runtime/rw/tbox_group/test_size/testcase/ucode: 4k/gcc-9/performance/1HDD/btrfs/ftruncate/x86_64-rhel-8.3/100%/debian-10.4-x86_64-20200603.cgz/300s/randwrite/lkp-icl-2sp1/128G/fio-basic/0xb000280 commit: 89a925d756 ("Merge branch 'for-next-current-v5.16-20220314' into for-next-20220314") 7664aed024 ("btrfs: fix fallocate to use file_modified to update permissions consistently") 89a925d7560844e1 7664aed02431897aff0c2c96c68 ---------------- --------------------------- %stddev %change %stddev \ | \ 25.54 -15.7 9.87 fio.latency_1000us% 9.23 ± 4% +9.9 19.17 fio.latency_10us% 9.58 +3.5 13.06 ± 2% fio.latency_20us% 0.31 ± 21% +0.3 0.62 ± 11% fio.latency_250us% 31.76 -4.3 27.44 fio.latency_2ms% 0.49 ± 29% +2.1 2.62 ± 10% fio.latency_4us% 4.48 -2.0 2.50 ± 3% fio.latency_500us% 1.29 ± 5% +0.4 1.64 ± 15% fio.latency_50us% 16.58 +5.5 22.06 fio.latency_750us% 274.60 -22.6% 212.58 fio.time.elapsed_time 274.60 -22.6% 212.58 fio.time.elapsed_time.max 4151 -25.2% 3103 ± 3% fio.time.involuntary_context_switches 39815 -19.3% 32135 ± 2% fio.time.minor_page_faults 949.33 -10.6% 848.83 fio.time.percent_of_cpu_this_job_got 2577 -31.1% 1774 fio.time.system_time 1.044e+08 -31.4% 71667735 fio.time.voluntary_context_switches 478.06 +29.3% 617.97 fio.write_bw_MBps 1318912 -6.4% 1234261 fio.write_clat_90%_us 1378986 -5.9% 1297066 fio.write_clat_95%_us 778778 -23.0% 599675 fio.write_clat_mean_us 122382 +29.3% 158201 fio.write_iops 485.84 -2.2% 475.03 pmeter.Average_Active_Power 2.374e+10 -21.6% 1.86e+10 cpuidle..time 1.498e+08 -28.4% 1.072e+08 cpuidle..usage 89.67 +1.3% 90.80 iostat.cpu.idle 10.18 -11.4% 9.02 iostat.cpu.system 81910 ± 15% -29.1% 58108 ± 21% meminfo.Active 2072 ± 2% -15.4% 1752 ± 2% meminfo.Active(file) 326.84 -19.2% 263.93 uptime.boot 28026 -18.5% 22848 uptime.idle 246.33 +22.1% 300.67 ± 5% vmstat.io.bo 748973 -11.5% 662479 vmstat.system.cs 0.01 ± 2% +0.0 0.01 ± 3% mpstat.cpu.all.iowait% 9.49 -1.1 8.35 mpstat.cpu.all.sys% 0.14 ± 5% +0.0 0.18 ± 5% mpstat.cpu.all.usr% 850.50 ± 22% +48.1% 1259 ± 6% numa-meminfo.node0.Active(file) 833.17 ± 89% +1557.5% 13809 ± 3% numa-meminfo.node0.Inactive(file) 75084 ± 11% -31.1% 51711 ± 18% numa-meminfo.node1.Active 73861 ± 11% -30.6% 51230 ± 19% numa-meminfo.node1.Active(anon) 1222 ± 15% -60.7% 480.00 ± 23% numa-meminfo.node1.Active(file) 96944 ± 20% +80.8% 175278 ± 30% numa-meminfo.node1.Inactive 83244 ± 24% +110.2% 174993 ± 30% numa-meminfo.node1.Inactive(anon) 13700 ± 5% -97.9% 284.67 ± 43% numa-meminfo.node1.Inactive(file) 25892 ± 33% +84.7% 47819 ± 26% numa-meminfo.node1.Mapped 517.00 ± 2% -15.9% 434.67 ± 3% proc-vmstat.nr_active_file 72537 +2.2% 74150 proc-vmstat.nr_anon_pages 17664 -13.5% 15278 proc-vmstat.nr_dirtied 3057 +3.8% 3174 proc-vmstat.nr_page_table_pages 16195 -9.3% 14686 ± 2% proc-vmstat.nr_written 517.00 ± 2% -15.9% 434.67 ± 3% proc-vmstat.nr_zone_active_file 1222395 ± 3% -14.6% 1043907 ± 5% proc-vmstat.pgfault 69030 -5.3% 65348 ± 4% proc-vmstat.pgpgout 59434 -20.0% 47550 proc-vmstat.pgreuse 375.33 -9.4% 340.17 turbostat.Avg_MHz 11.81 -1.1 10.72 turbostat.Busy% 803952 ± 4% -20.1% 642465 ± 11% turbostat.C1 1.474e+08 -28.6% 1.052e+08 turbostat.C1E 63.17 ± 3% +11.6% 70.50 ± 3% turbostat.CoreTmp 56497141 -22.1% 44010000 turbostat.IRQ 222267 -27.2% 161739 ± 2% turbostat.POLL 0.05 -0.0 0.04 turbostat.POLL% 63.33 ± 3% +11.6% 70.67 ± 3% turbostat.PkgTmp 206.89 +2.5% 212.16 turbostat.RAMWatt 211.00 ± 22% +49.3% 315.00 ± 6% numa-vmstat.node0.nr_active_file 1852 ± 53% +352.7% 8387 ± 5% numa-vmstat.node0.nr_dirtied 208.67 ± 89% +1552.1% 3447 ± 3% numa-vmstat.node0.nr_inactive_file 1806 ± 54% +360.4% 8317 ± 5% numa-vmstat.node0.nr_written 211.00 ± 22% +49.3% 315.00 ± 6% numa-vmstat.node0.nr_zone_active_file 208.67 ± 89% +1552.1% 3447 ± 3% numa-vmstat.node0.nr_zone_inactive_file 304.17 ± 15% -60.3% 120.83 ± 23% numa-vmstat.node1.nr_active_file 8877 ± 11% -92.1% 700.00 ± 80% numa-vmstat.node1.nr_dirtied 20207 ± 25% +115.1% 43458 ± 29% numa-vmstat.node1.nr_inactive_anon 3424 ± 5% -97.9% 70.83 ± 44% numa-vmstat.node1.nr_inactive_file 8813 ± 11% -92.5% 663.83 ± 83% numa-vmstat.node1.nr_written 304.17 ± 15% -60.3% 120.83 ± 23% numa-vmstat.node1.nr_zone_active_file 20208 ± 25% +115.1% 43458 ± 29% numa-vmstat.node1.nr_zone_inactive_anon 3424 ± 5% -97.9% 70.83 ± 44% numa-vmstat.node1.nr_zone_inactive_file 1.698e+09 +3.7% 1.761e+09 ± 2% perf-stat.i.branch-instructions 43843771 +4.5% 45825714 perf-stat.i.cache-misses 757981 -11.3% 672443 perf-stat.i.context-switches 4.42 -13.3% 3.83 perf-stat.i.cpi 3.73e+10 -9.6% 3.373e+10 perf-stat.i.cpu-cycles 2.303e+09 +4.8% 2.413e+09 perf-stat.i.dTLB-loads 1.214e+09 +6.4% 1.292e+09 perf-stat.i.dTLB-stores 8.441e+09 +4.5% 8.819e+09 perf-stat.i.instructions 0.23 +15.6% 0.27 perf-stat.i.ipc 18.63 +29.2% 24.08 perf-stat.i.major-faults 0.39 -9.6% 0.35 perf-stat.i.metric.GHz 55.76 +4.7% 58.39 perf-stat.i.metric.M/sec 309205 ± 3% +10.9% 342860 ± 3% perf-stat.i.node-loads 6312089 +4.1% 6571951 ± 2% perf-stat.i.node-store-misses 4.42 -13.4% 3.83 perf-stat.overall.cpi 850.93 -13.5% 736.28 perf-stat.overall.cycles-between-cache-misses 0.23 +15.5% 0.26 perf-stat.overall.ipc 69450 -19.1% 56170 perf-stat.overall.path-length 1.691e+09 +3.6% 1.752e+09 ± 2% perf-stat.ps.branch-instructions 43679256 +4.4% 45604378 perf-stat.ps.cache-misses 755089 -11.4% 669172 perf-stat.ps.context-switches 3.716e+10 -9.7% 3.357e+10 perf-stat.ps.cpu-cycles 2.295e+09 +4.7% 2.402e+09 perf-stat.ps.dTLB-loads 1.21e+09 +6.3% 1.286e+09 perf-stat.ps.dTLB-stores 8.41e+09 +4.4% 8.778e+09 perf-stat.ps.instructions 18.53 +29.1% 23.92 perf-stat.ps.major-faults 308133 ± 3% +10.8% 341314 ± 3% perf-stat.ps.node-loads 6288209 +4.0% 6540203 ± 2% perf-stat.ps.node-store-misses 2.33e+12 -19.1% 1.885e+12 perf-stat.total.instructions 21.14 -7.8 13.34 perf-profile.calltrace.cycles-pp.btrfs_search_slot.btrfs_truncate_inode_items.btrfs_setsize.btrfs_setattr.notify_change 17.67 -7.6 10.11 ± 2% perf-profile.calltrace.cycles-pp.native_queued_spin_lock_slowpath._raw_spin_lock_irq.rwsem_down_read_slowpath.__btrfs_tree_read_lock.btrfs_read_lock_root_node 24.00 -7.5 16.50 perf-profile.calltrace.cycles-pp.btrfs_truncate_inode_items.btrfs_setsize.btrfs_setattr.notify_change.do_truncate 18.11 -7.4 10.71 ± 2% perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.rwsem_down_read_slowpath.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot 5.86 -4.8 1.05 ± 2% perf-profile.calltrace.cycles-pp.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_get_extent 5.96 -4.8 1.18 ± 2% perf-profile.calltrace.cycles-pp.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_get_extent.btrfs_cont_expand 5.61 -4.6 0.97 ± 3% perf-profile.calltrace.cycles-pp.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items.btrfs_setsize 5.74 -4.6 1.11 ± 2% perf-profile.calltrace.cycles-pp.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items.btrfs_setsize.btrfs_setattr 5.41 -4.5 0.89 ± 2% perf-profile.calltrace.cycles-pp.rwsem_down_read_slowpath.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items 7.12 -4.1 3.00 perf-profile.calltrace.cycles-pp.btrfs_lookup_file_extent.btrfs_get_extent.btrfs_cont_expand.btrfs_setsize.btrfs_setattr 7.11 -4.1 2.99 perf-profile.calltrace.cycles-pp.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_get_extent.btrfs_cont_expand.btrfs_setsize 7.89 ± 2% -3.9 3.97 perf-profile.calltrace.cycles-pp.btrfs_get_extent.btrfs_cont_expand.btrfs_setsize.btrfs_setattr.notify_change 14.14 ± 2% -3.5 10.61 ± 2% perf-profile.calltrace.cycles-pp.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items 14.35 ± 2% -3.5 10.86 ± 2% perf-profile.calltrace.cycles-pp.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items.btrfs_setsize 14.40 ± 2% -3.5 10.91 ± 2% perf-profile.calltrace.cycles-pp.btrfs_lock_root_node.btrfs_search_slot.btrfs_truncate_inode_items.btrfs_setsize.btrfs_setattr 10.27 -2.4 7.83 perf-profile.calltrace.cycles-pp.rwsem_down_read_slowpath.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_lookup_file_extent 77.81 -1.1 76.68 perf-profile.calltrace.cycles-pp.do_truncate.do_sys_ftruncate.do_syscall_64.entry_SYSCALL_64_after_hwframe.ftruncate64 77.91 -1.1 76.81 perf-profile.calltrace.cycles-pp.do_sys_ftruncate.do_syscall_64.entry_SYSCALL_64_after_hwframe.ftruncate64 77.98 -1.1 76.90 perf-profile.calltrace.cycles-pp.do_syscall_64.entry_SYSCALL_64_after_hwframe.ftruncate64 78.01 -1.1 76.95 perf-profile.calltrace.cycles-pp.entry_SYSCALL_64_after_hwframe.ftruncate64 78.31 -1.0 77.27 perf-profile.calltrace.cycles-pp.ftruncate64 0.67 -0.1 0.56 ± 3% perf-profile.calltrace.cycles-pp.rwsem_spin_on_owner.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot 0.55 ± 3% +0.0 0.60 ± 4% perf-profile.calltrace.cycles-pp.irq_exit_rcu.sysvec_apic_timer_interrupt.asm_sysvec_apic_timer_interrupt.cpuidle_enter_state.cpuidle_enter 0.58 ± 5% +0.1 0.67 ± 3% perf-profile.calltrace.cycles-pp.__hrtimer_run_queues.hrtimer_interrupt.__sysvec_apic_timer_interrupt.sysvec_apic_timer_interrupt.asm_sysvec_apic_timer_interrupt 0.61 ± 3% +0.2 0.76 ± 4% perf-profile.calltrace.cycles-pp.try_to_wake_up.wake_up_q.rwsem_wake.btrfs_unlock_up_safe.btrfs_search_slot 0.64 ± 3% +0.2 0.80 ± 4% perf-profile.calltrace.cycles-pp.wake_up_q.rwsem_wake.btrfs_unlock_up_safe.btrfs_search_slot.btrfs_insert_empty_items 0.68 ± 5% +0.2 0.87 ± 3% perf-profile.calltrace.cycles-pp.btrfs_del_items.btrfs_truncate_inode_items.btrfs_setsize.btrfs_setattr.notify_change 0.87 ± 3% +0.3 1.20 ± 3% perf-profile.calltrace.cycles-pp.rwsem_wake.btrfs_unlock_up_safe.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent 0.59 ± 3% +0.3 0.92 ± 30% perf-profile.calltrace.cycles-pp.start_transaction.btrfs_setsize.btrfs_setattr.notify_change.do_truncate 0.73 ± 5% +0.3 1.06 ± 4% perf-profile.calltrace.cycles-pp.memmove.memcpy_extent_buffer.setup_items_for_insert.btrfs_insert_empty_items.btrfs_insert_file_extent 0.91 ± 3% +0.3 1.26 ± 3% perf-profile.calltrace.cycles-pp.btrfs_unlock_up_safe.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand 0.78 ± 6% +0.4 1.14 ± 4% perf-profile.calltrace.cycles-pp.memcpy_extent_buffer.setup_items_for_insert.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand 11.54 ± 2% +0.4 11.96 perf-profile.calltrace.cycles-pp.intel_idle.cpuidle_enter_state.cpuidle_enter.do_idle.cpu_startup_entry 0.56 ± 3% +0.5 1.08 ± 14% perf-profile.calltrace.cycles-pp.btrfs_dirty_inode.btrfs_setattr.notify_change.do_truncate.do_sys_ftruncate 0.08 ±223% +0.5 0.63 ± 3% perf-profile.calltrace.cycles-pp.btrfs_get_token_32.setup_items_for_insert.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand 0.00 +0.5 0.55 ± 3% perf-profile.calltrace.cycles-pp.schedule.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot 14.93 ± 2% +0.6 15.55 ± 2% perf-profile.calltrace.cycles-pp.cpuidle_enter_state.cpuidle_enter.do_idle.cpu_startup_entry.start_secondary 15.22 ± 2% +0.7 15.88 ± 2% perf-profile.calltrace.cycles-pp.cpuidle_enter.do_idle.cpu_startup_entry.start_secondary.secondary_startup_64_no_verify 1.63 ± 5% +0.7 2.29 ± 3% perf-profile.calltrace.cycles-pp.setup_items_for_insert.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand.btrfs_setsize 20.42 ± 2% +0.8 21.22 perf-profile.calltrace.cycles-pp.secondary_startup_64_no_verify 20.12 ± 2% +0.8 20.93 perf-profile.calltrace.cycles-pp.do_idle.cpu_startup_entry.start_secondary.secondary_startup_64_no_verify 20.19 ± 2% +0.8 20.99 perf-profile.calltrace.cycles-pp.start_secondary.secondary_startup_64_no_verify 20.18 ± 2% +0.8 20.98 perf-profile.calltrace.cycles-pp.cpu_startup_entry.start_secondary.secondary_startup_64_no_verify 3.79 ± 3% +1.2 5.04 ± 2% perf-profile.calltrace.cycles-pp.rwsem_down_read_slowpath.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items 4.00 ± 2% +1.3 5.32 ± 2% perf-profile.calltrace.cycles-pp.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent 4.11 ± 3% +1.4 5.47 ± 2% perf-profile.calltrace.cycles-pp.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand 15.63 ± 2% +1.9 17.51 perf-profile.calltrace.cycles-pp.native_queued_spin_lock_slowpath._raw_spin_lock_irq.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node 16.14 +1.9 18.06 perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot 4.85 +2.3 7.14 perf-profile.calltrace.cycles-pp.__btrfs_tree_read_lock.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_drop_extents 4.97 ± 2% +2.3 7.29 perf-profile.calltrace.cycles-pp.btrfs_read_lock_root_node.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_drop_extents.btrfs_cont_expand 6.14 +2.9 9.02 perf-profile.calltrace.cycles-pp.btrfs_search_slot.btrfs_lookup_file_extent.btrfs_drop_extents.btrfs_cont_expand.btrfs_setsize 6.15 +2.9 9.04 perf-profile.calltrace.cycles-pp.btrfs_lookup_file_extent.btrfs_drop_extents.btrfs_cont_expand.btrfs_setsize.btrfs_setattr 72.34 +3.1 75.38 perf-profile.calltrace.cycles-pp.btrfs_setsize.btrfs_setattr.notify_change.do_truncate.do_sys_ftruncate 6.84 +3.1 9.96 perf-profile.calltrace.cycles-pp.btrfs_drop_extents.btrfs_cont_expand.btrfs_setsize.btrfs_setattr.notify_change 73.03 +3.6 76.62 perf-profile.calltrace.cycles-pp.notify_change.do_truncate.do_sys_ftruncate.do_syscall_64.entry_SYSCALL_64_after_hwframe 72.95 +3.6 76.55 perf-profile.calltrace.cycles-pp.btrfs_setattr.notify_change.do_truncate.do_sys_ftruncate.do_syscall_64 21.84 ± 2% +6.9 28.79 perf-profile.calltrace.cycles-pp.rwsem_down_write_slowpath.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items 22.01 ± 2% +7.0 29.02 perf-profile.calltrace.cycles-pp.__btrfs_tree_lock.btrfs_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent 22.05 ± 2% +7.0 29.08 perf-profile.calltrace.cycles-pp.btrfs_lock_root_node.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand 27.98 +9.1 37.05 perf-profile.calltrace.cycles-pp.btrfs_search_slot.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand.btrfs_setsize 46.10 +9.5 55.63 perf-profile.calltrace.cycles-pp.btrfs_cont_expand.btrfs_setsize.btrfs_setattr.notify_change.do_truncate 29.65 +9.8 39.40 perf-profile.calltrace.cycles-pp.btrfs_insert_empty_items.btrfs_insert_file_extent.btrfs_cont_expand.btrfs_setsize.btrfs_setattr 29.89 +9.8 39.70 perf-profile.calltrace.cycles-pp.btrfs_insert_file_extent.btrfs_cont_expand.btrfs_setsize.btrfs_setattr.notify_change 24.00 -7.5 16.51 perf-profile.children.cycles-pp.btrfs_truncate_inode_items 23.01 -7.4 15.61 perf-profile.children.cycles-pp.btrfs_read_lock_root_node 22.50 -7.4 15.13 perf-profile.children.cycles-pp.__btrfs_tree_read_lock 21.42 -7.1 14.32 perf-profile.children.cycles-pp.rwsem_down_read_slowpath 34.64 -4.8 29.83 perf-profile.children.cycles-pp._raw_spin_lock_irq 34.32 ± 2% -4.3 30.00 ± 2% perf-profile.children.cycles-pp.native_queued_spin_lock_slowpath 67.15 -4.1 63.10 perf-profile.children.cycles-pp.btrfs_search_slot 7.90 ± 2% -3.9 3.98 perf-profile.children.cycles-pp.btrfs_get_extent 13.27 -1.2 12.04 perf-profile.children.cycles-pp.btrfs_lookup_file_extent 77.81 -1.1 76.69 perf-profile.children.cycles-pp.do_truncate 77.91 -1.1 76.82 perf-profile.children.cycles-pp.do_sys_ftruncate 78.22 -1.1 77.15 perf-profile.children.cycles-pp.do_syscall_64 78.25 -1.1 77.19 perf-profile.children.cycles-pp.entry_SYSCALL_64_after_hwframe 78.33 -1.0 77.30 perf-profile.children.cycles-pp.ftruncate64 1.43 -0.3 1.14 ± 3% perf-profile.children.cycles-pp.generic_bin_search 1.03 ± 2% -0.3 0.76 ± 3% perf-profile.children.cycles-pp.down_read 1.00 ± 2% -0.2 0.82 perf-profile.children.cycles-pp.up_read 2.49 ± 2% -0.2 2.31 ± 3% perf-profile.children.cycles-pp.btrfs_free_path 1.61 -0.2 1.45 perf-profile.children.cycles-pp.read_block_for_search 2.66 ± 2% -0.1 2.55 ± 2% perf-profile.children.cycles-pp.btrfs_release_path 0.59 ± 3% -0.1 0.51 ± 3% perf-profile.children.cycles-pp.btrfs_get_64 0.69 ± 2% -0.1 0.63 ± 3% perf-profile.children.cycles-pp.btrfs_root_node 0.74 ± 2% -0.0 0.70 perf-profile.children.cycles-pp.pick_next_task_fair 0.06 ± 7% +0.0 0.08 ± 6% perf-profile.children.cycles-pp.sysvec_call_function_single 0.08 +0.0 0.10 ± 5% perf-profile.children.cycles-pp.asm_sysvec_call_function_single 0.05 ± 7% +0.0 0.07 ± 8% perf-profile.children.cycles-pp.syscall_exit_to_user_mode 0.04 ± 44% +0.0 0.06 ± 7% perf-profile.children.cycles-pp.btrfs_inode_safe_disk_i_size_write 0.29 ± 2% +0.0 0.31 ± 3% perf-profile.children.cycles-pp.sched_clock_cpu 0.07 +0.0 0.09 ± 10% perf-profile.children.cycles-pp.__cond_resched 0.06 ± 6% +0.0 0.08 ± 8% perf-profile.children.cycles-pp.btrfs_leaf_free_space 0.08 ± 8% +0.0 0.10 ± 4% perf-profile.children.cycles-pp.leaf_space_used 0.07 ± 12% +0.0 0.10 ± 9% perf-profile.children.cycles-pp.fill_stack_inode_item 0.10 ± 6% +0.0 0.12 ± 8% perf-profile.children.cycles-pp.__lookup_extent_mapping 0.17 ± 5% +0.0 0.20 ± 2% perf-profile.children.cycles-pp.native_irq_return_iret 0.08 ± 12% +0.0 0.10 ± 10% perf-profile.children.cycles-pp.copy_pages 0.09 ± 7% +0.0 0.12 ± 9% perf-profile.children.cycles-pp.alloc_extent_state 0.07 ± 7% +0.0 0.09 ± 11% perf-profile.children.cycles-pp.free_extent_map 0.07 ± 5% +0.0 0.10 ± 10% perf-profile.children.cycles-pp.btrfs_block_rsv_migrate 0.09 ± 4% +0.0 0.12 ± 3% perf-profile.children.cycles-pp.memset_erms 0.11 ± 10% +0.0 0.14 ± 3% perf-profile.children.cycles-pp.btrfs_get_32 0.18 ± 2% +0.0 0.21 ± 6% perf-profile.children.cycles-pp.__might_resched 0.10 ± 5% +0.0 0.13 ± 4% perf-profile.children.cycles-pp.clear_extent_bit 0.07 ± 9% +0.0 0.11 ± 8% perf-profile.children.cycles-pp.get_io_u 0.10 ± 6% +0.0 0.14 ± 2% perf-profile.children.cycles-pp.up_write 0.14 ± 7% +0.0 0.17 ± 2% perf-profile.children.cycles-pp.btrfs_mark_buffer_dirty 0.09 ± 5% +0.0 0.12 ± 4% perf-profile.children.cycles-pp.clear_state_bit 0.15 ± 6% +0.0 0.19 ± 8% perf-profile.children.cycles-pp.kmem_cache_free 0.54 ± 3% +0.0 0.59 ± 5% perf-profile.children.cycles-pp.__softirqentry_text_start 0.11 ± 6% +0.0 0.15 ± 3% perf-profile.children.cycles-pp.btrfs_inode_clear_file_extent_range 0.08 ± 6% +0.0 0.12 ± 5% perf-profile.children.cycles-pp.fio_gettime 0.36 ± 3% +0.0 0.41 ± 2% perf-profile.children.cycles-pp.read_extent_buffer 0.61 ± 3% +0.0 0.66 ± 4% perf-profile.children.cycles-pp.irq_exit_rcu 0.02 ±142% +0.1 0.08 ± 6% perf-profile.children.cycles-pp.ktime_get_real_ts64 0.07 ± 12% +0.1 0.13 ± 4% perf-profile.children.cycles-pp.btrfs_put_transaction 0.16 ± 5% +0.1 0.22 ± 5% perf-profile.children.cycles-pp.alloc_extent_map 0.17 ± 6% +0.1 0.24 ± 7% perf-profile.children.cycles-pp.__reserve_bytes 0.44 ± 6% +0.1 0.51 ± 6% perf-profile.children.cycles-pp.tick_sched_timer 0.24 ± 4% +0.1 0.31 ± 5% perf-profile.children.cycles-pp.check_setget_bounds 0.32 ± 7% +0.1 0.40 ± 2% perf-profile.children.cycles-pp.memmove_extent_buffer 0.18 ± 3% +0.1 0.26 ± 4% perf-profile.children.cycles-pp.btrfs_block_rsv_add_bytes 0.25 ± 5% +0.1 0.34 ± 4% perf-profile.children.cycles-pp.wake_q_add 0.21 ± 5% +0.1 0.30 ± 4% perf-profile.children.cycles-pp.__clear_extent_bit 0.21 ± 4% +0.1 0.30 ± 4% perf-profile.children.cycles-pp.btrfs_reserve_metadata_bytes 0.69 ± 4% +0.1 0.78 ± 3% perf-profile.children.cycles-pp.__hrtimer_run_queues 0.70 ± 2% +0.1 0.80 ± 3% perf-profile.children.cycles-pp.rwsem_mark_wake 0.41 ± 2% +0.1 0.50 ± 3% perf-profile.children.cycles-pp.kmem_cache_alloc 0.18 ± 5% +0.1 0.28 ± 3% perf-profile.children.cycles-pp.mutex_lock 0.99 +0.1 1.09 ± 2% perf-profile.children.cycles-pp.rwsem_spin_on_owner 0.22 ± 6% +0.1 0.32 ± 3% perf-profile.children.cycles-pp.btrfs_set_token_32 0.46 ± 4% +0.1 0.56 perf-profile.children.cycles-pp.down_write 0.20 ± 6% +0.1 0.31 ± 6% perf-profile.children.cycles-pp.btrfs_update_root_times 0.41 ± 2% +0.1 0.54 ± 4% perf-profile.children.cycles-pp.btrfs_drop_extent_cache 0.37 ± 2% +0.2 0.52 ± 4% perf-profile.children.cycles-pp.btrfs_block_rsv_add 2.61 +0.2 2.79 ± 2% perf-profile.children.cycles-pp.wake_up_q 0.34 ± 8% +0.2 0.52 ± 7% perf-profile.children.cycles-pp.mutex_unlock 0.69 ± 5% +0.2 0.89 ± 2% perf-profile.children.cycles-pp.btrfs_del_items 0.18 ± 4% +0.2 0.38 ± 78% perf-profile.children.cycles-pp.wait_current_trans 0.67 ± 5% +0.2 0.88 ± 2% perf-profile.children.cycles-pp.btrfs_get_token_32 0.22 ± 5% +0.2 0.46 ± 4% perf-profile.children.cycles-pp.btrfs_trans_release_metadata 0.28 ± 3% +0.2 0.53 ± 26% perf-profile.children.cycles-pp.join_transaction 0.59 ± 2% +0.3 0.84 ± 3% perf-profile.children.cycles-pp._raw_spin_lock_irqsave 0.24 ± 5% +0.3 0.49 ± 4% perf-profile.children.cycles-pp.btrfs_block_rsv_release 0.92 ± 2% +0.3 1.26 ± 2% perf-profile.children.cycles-pp.btrfs_unlock_up_safe 3.17 ± 2% +0.4 3.52 ± 2% perf-profile.children.cycles-pp.rwsem_wake 0.88 ± 6% +0.4 1.28 ± 4% perf-profile.children.cycles-pp.memcpy_extent_buffer 11.72 ± 2% +0.4 12.15 perf-profile.children.cycles-pp.intel_idle 1.10 ± 5% +0.4 1.54 ± 3% perf-profile.children.cycles-pp.memmove 0.48 ± 4% +0.4 0.93 ± 3% perf-profile.children.cycles-pp.__btrfs_end_transaction 0.56 ± 4% +0.5 1.09 ± 14% perf-profile.children.cycles-pp.btrfs_dirty_inode 15.41 ± 2% +0.7 16.06 ± 2% perf-profile.children.cycles-pp.cpuidle_enter 15.38 ± 2% +0.7 16.03 ± 2% perf-profile.children.cycles-pp.cpuidle_enter_state 1.66 ± 5% +0.7 2.33 ± 3% perf-profile.children.cycles-pp.setup_items_for_insert 1.12 +0.7 1.83 ± 24% perf-profile.children.cycles-pp.start_transaction 20.41 ± 2% +0.8 21.20 perf-profile.children.cycles-pp.do_idle 20.42 ± 2% +0.8 21.22 perf-profile.children.cycles-pp.secondary_startup_64_no_verify 20.42 ± 2% +0.8 21.22 perf-profile.children.cycles-pp.cpu_startup_entry 20.19 ± 2% +0.8 20.99 perf-profile.children.cycles-pp.start_secondary 72.34 +3.1 75.40 perf-profile.children.cycles-pp.btrfs_setsize 6.85 +3.1 9.96 perf-profile.children.cycles-pp.btrfs_drop_extents 36.09 ± 2% +3.5 39.62 perf-profile.children.cycles-pp.rwsem_down_write_slowpath 36.46 ± 2% +3.5 40.00 perf-profile.children.cycles-pp.btrfs_lock_root_node 72.96 +3.6 76.55 perf-profile.children.cycles-pp.btrfs_setattr 73.03 +3.6 76.63 perf-profile.children.cycles-pp.notify_change 36.52 ± 2% +3.6 40.16 perf-profile.children.cycles-pp.__btrfs_tree_lock 46.11 +9.5 55.64 perf-profile.children.cycles-pp.btrfs_cont_expand 29.65 +9.7 39.40 perf-profile.children.cycles-pp.btrfs_insert_empty_items 29.89 +9.8 39.70 perf-profile.children.cycles-pp.btrfs_insert_file_extent 34.31 ± 2% -4.3 29.99 ± 2% perf-profile.self.cycles-pp.native_queued_spin_lock_slowpath 1.24 -0.3 0.96 ± 3% perf-profile.self.cycles-pp.generic_bin_search 0.98 ± 2% -0.3 0.72 ± 3% perf-profile.self.cycles-pp.down_read 1.27 ± 2% -0.2 1.03 ± 2% perf-profile.self.cycles-pp.rwsem_down_read_slowpath 0.99 ± 2% -0.2 0.81 perf-profile.self.cycles-pp.up_read 1.74 -0.1 1.61 perf-profile.self.cycles-pp.btrfs_search_slot 0.48 ± 2% -0.1 0.40 ± 3% perf-profile.self.cycles-pp.btrfs_get_64 1.01 ± 2% -0.1 0.95 ± 3% perf-profile.self.cycles-pp._raw_spin_lock_irq 0.68 ± 3% -0.1 0.63 ± 3% perf-profile.self.cycles-pp.btrfs_root_node 0.05 +0.0 0.07 ± 7% perf-profile.self.cycles-pp.btrfs_drop_extent_cache 0.08 ± 7% +0.0 0.10 ± 7% perf-profile.self.cycles-pp.schedule 0.21 ± 4% +0.0 0.23 ± 3% perf-profile.self.cycles-pp.read_tsc 0.07 ± 11% +0.0 0.09 ± 8% perf-profile.self.cycles-pp.btrfs_setsize 0.17 ± 5% +0.0 0.20 ± 2% perf-profile.self.cycles-pp.try_to_wake_up 0.17 ± 5% +0.0 0.20 ± 2% perf-profile.self.cycles-pp.native_irq_return_iret 0.07 ± 11% +0.0 0.10 ± 9% perf-profile.self.cycles-pp.setup_items_for_insert 0.08 ± 12% +0.0 0.10 ± 10% perf-profile.self.cycles-pp.copy_pages 0.06 ± 13% +0.0 0.09 ± 8% perf-profile.self.cycles-pp.btrfs_cont_expand 0.06 ± 7% +0.0 0.09 ± 11% perf-profile.self.cycles-pp.free_extent_map 0.09 +0.0 0.12 ± 3% perf-profile.self.cycles-pp.memset_erms 0.08 ± 13% +0.0 0.11 ± 5% perf-profile.self.cycles-pp.__btrfs_release_delayed_node 0.10 ± 10% +0.0 0.13 ± 6% perf-profile.self.cycles-pp.btrfs_get_32 0.16 ± 2% +0.0 0.20 ± 6% perf-profile.self.cycles-pp.__might_resched 0.10 ± 6% +0.0 0.14 ± 3% perf-profile.self.cycles-pp.up_write 0.07 ± 11% +0.0 0.10 ± 9% perf-profile.self.cycles-pp.get_io_u 0.07 ± 6% +0.0 0.11 ± 6% perf-profile.self.cycles-pp.fio_gettime 0.02 ±141% +0.0 0.06 ± 8% perf-profile.self.cycles-pp._raw_write_lock 0.19 ± 3% +0.0 0.23 ± 5% perf-profile.self.cycles-pp.kmem_cache_alloc 0.14 ± 8% +0.0 0.18 ± 7% perf-profile.self.cycles-pp.kmem_cache_free 0.19 ± 7% +0.0 0.24 ± 5% perf-profile.self.cycles-pp.check_setget_bounds 0.13 ± 6% +0.0 0.18 ± 2% perf-profile.self.cycles-pp.wake_up_q 0.36 ± 2% +0.0 0.40 ± 3% perf-profile.self.cycles-pp.read_extent_buffer 0.01 ±223% +0.0 0.06 ± 9% perf-profile.self.cycles-pp.btrfs_truncate_inode_items 0.06 ± 8% +0.0 0.10 ± 9% perf-profile.self.cycles-pp.btrfs_block_rsv_release 0.48 ± 4% +0.1 0.53 ± 2% perf-profile.self.cycles-pp.cpuidle_enter_state 0.01 ±223% +0.1 0.06 ± 7% perf-profile.self.cycles-pp.btrfs_reserve_metadata_bytes 0.08 ± 5% +0.1 0.15 ± 4% perf-profile.self.cycles-pp.btrfs_update_inode 0.07 ± 7% +0.1 0.13 ± 4% perf-profile.self.cycles-pp.btrfs_put_transaction 0.17 ± 6% +0.1 0.25 ± 4% perf-profile.self.cycles-pp.btrfs_set_token_32 0.17 ± 4% +0.1 0.25 ± 6% perf-profile.self.cycles-pp.start_transaction 0.14 ± 6% +0.1 0.22 ± 5% perf-profile.self.cycles-pp.mutex_lock 0.25 ± 5% +0.1 0.34 ± 4% perf-profile.self.cycles-pp.wake_q_add 0.38 ± 4% +0.1 0.48 ± 2% perf-profile.self.cycles-pp.down_write 0.32 ± 4% +0.1 0.41 ± 5% perf-profile.self.cycles-pp._raw_spin_lock_irqsave 0.97 ± 2% +0.1 1.06 ± 2% perf-profile.self.cycles-pp.rwsem_spin_on_owner 0.18 ± 6% +0.1 0.28 ± 3% perf-profile.self.cycles-pp.join_transaction 0.85 ± 3% +0.1 0.96 ± 2% perf-profile.self.cycles-pp.rwsem_down_write_slowpath 0.16 ± 2% +0.1 0.29 ± 2% perf-profile.self.cycles-pp.__btrfs_end_transaction 0.61 ± 5% +0.2 0.79 ± 3% perf-profile.self.cycles-pp.btrfs_get_token_32 0.33 ± 8% +0.2 0.52 ± 7% perf-profile.self.cycles-pp.mutex_unlock 11.69 ± 2% +0.4 12.12 perf-profile.self.cycles-pp.intel_idle 1.10 ± 5% +0.4 1.53 ± 3% perf-profile.self.cycles-pp.memmove 1.63 ± 2% +0.5 2.11 ± 2% perf-profile.self.cycles-pp._raw_spin_lock Disclaimer: Results have been estimated based on internal Intel analysis and are provided for informational purposes only. Any difference in system hardware or software design or configuration may affect actual performance.
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a0179cc62913..28ddd9cf2069 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2918,8 +2918,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, return ret; } -static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) +static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) { + struct inode *inode = file_inode(file); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; struct extent_state *cached_state = NULL; @@ -2951,6 +2952,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } + ret = file_modified(file); + if (ret) + goto out_only_mutex; + lockstart = round_up(offset, btrfs_inode_sectorsize(BTRFS_I(inode))); lockend = round_down(offset + len, btrfs_inode_sectorsize(BTRFS_I(inode))) - 1; @@ -3391,7 +3396,7 @@ static long btrfs_fallocate(struct file *file, int mode, return -EOPNOTSUPP; if (mode & FALLOC_FL_PUNCH_HOLE) - return btrfs_punch_hole(inode, offset, len); + return btrfs_punch_hole(file, offset, len); /* * Only trigger disk allocation, don't trigger qgroup reserve @@ -3413,6 +3418,10 @@ static long btrfs_fallocate(struct file *file, int mode, goto out; } + ret = file_modified(file); + if (ret) + goto out; + /* * TODO: Move these two operations after we have checked * accurate reserved space, or fallocate can still fail but