mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 04:07:45 +03:00
Fix long POSIX_FADV_DONTNEED for single block files
dbuf_whichblock() is not made to handle offsets beyond the block end for single-block objects. Handle it in dmu_evict_range(), similar to dmu_prefetch_by_dnode(). Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com> Closes #18399 Closes #18489
This commit is contained in:
committed by
Tony Hutter
parent
4bb7592745
commit
38501e1821
+8
-2
@@ -918,8 +918,14 @@ dmu_evict_range(objset_t *os, uint64_t object, uint64_t offset, uint64_t len)
|
|||||||
* access patterns are rare.
|
* access patterns are rare.
|
||||||
*/
|
*/
|
||||||
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
||||||
uint64_t start = dbuf_whichblock(dn, 0, offset);
|
uint64_t start, end;
|
||||||
uint64_t end = dbuf_whichblock(dn, 0, offset + len);
|
if (dn->dn_datablkshift != 0) {
|
||||||
|
start = dbuf_whichblock(dn, 0, offset);
|
||||||
|
end = dbuf_whichblock(dn, 0, offset + len);
|
||||||
|
} else {
|
||||||
|
start = (offset >= dn->dn_datablksz);
|
||||||
|
end = (offset + len >= dn->dn_datablksz);
|
||||||
|
}
|
||||||
if (end > start)
|
if (end > start)
|
||||||
dbuf_evict_range(dn, start, end - 1);
|
dbuf_evict_range(dn, start, end - 1);
|
||||||
rw_exit(&dn->dn_struct_rwlock);
|
rw_exit(&dn->dn_struct_rwlock);
|
||||||
|
|||||||
@@ -32,11 +32,13 @@
|
|||||||
# 2. Record cache_count from dbufstats
|
# 2. Record cache_count from dbufstats
|
||||||
# 3. Call file_fadvise with POSIX_FADV_DONTNEED on the file
|
# 3. Call file_fadvise with POSIX_FADV_DONTNEED on the file
|
||||||
# 4. Verify that cache_count decreased
|
# 4. Verify that cache_count decreased
|
||||||
|
# 5. Sanity-check eviction for single-block files.
|
||||||
#
|
#
|
||||||
|
|
||||||
verify_runnable "global"
|
verify_runnable "global"
|
||||||
|
|
||||||
FILE=$TESTDIR/$TESTFILE0
|
FILE0=$TESTDIR/$TESTFILE0
|
||||||
|
FILE1=$TESTDIR/$TESTFILE1
|
||||||
BLKSZ=$(get_prop recordsize $TESTPOOL)
|
BLKSZ=$(get_prop recordsize $TESTPOOL)
|
||||||
|
|
||||||
function cleanup
|
function cleanup
|
||||||
@@ -48,16 +50,21 @@ log_assert "Ensure POSIX_FADV_DONTNEED evicts data from the dbuf cache"
|
|||||||
|
|
||||||
log_onexit cleanup
|
log_onexit cleanup
|
||||||
|
|
||||||
log_must file_write -o create -f $FILE -b $BLKSZ -c 100
|
log_must file_write -o create -f $FILE0 -b $BLKSZ -c 100
|
||||||
sync_pool $TESTPOOL
|
sync_pool $TESTPOOL
|
||||||
|
|
||||||
evicts1=$(kstat dbufstats.cache_count)
|
evicts1=$(kstat dbufstats.cache_count)
|
||||||
|
|
||||||
log_must file_fadvise -f $FILE -a POSIX_FADV_DONTNEED
|
log_must file_fadvise -f $FILE0 -a POSIX_FADV_DONTNEED
|
||||||
|
|
||||||
evicts2=$(kstat dbufstats.cache_count)
|
evicts2=$(kstat dbufstats.cache_count)
|
||||||
log_note "cache_count before=$evicts1 after=$evicts2"
|
log_note "cache_count before=$evicts1 after=$evicts2"
|
||||||
|
|
||||||
log_must [ $evicts1 -gt $evicts2 ]
|
log_must [ $evicts1 -gt $evicts2 ]
|
||||||
|
|
||||||
|
log_must file_write -o create -f $FILE1 -b 12000 -c 1
|
||||||
|
sync_pool $TESTPOOL
|
||||||
|
|
||||||
|
log_must file_fadvise -f $FILE1 -a POSIX_FADV_DONTNEED
|
||||||
|
|
||||||
log_pass "POSIX_FADV_DONTNEED evicts data from the dbuf cache"
|
log_pass "POSIX_FADV_DONTNEED evicts data from the dbuf cache"
|
||||||
|
|||||||
Reference in New Issue
Block a user