Skip to content

Commit b048bfa

Browse files
authored
Allow opt-in of zvol blocks in special class
Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Kjeld Schouten <[email protected]> Signed-off-by: Don Brady <[email protected]> Closes #14876
1 parent 9d76950 commit b048bfa

File tree

8 files changed

+75
-10
lines changed

8 files changed

+75
-10
lines changed

man/man7/zfsprops.7

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,12 +1281,12 @@ This feature must be enabled to be used
12811281
.Pc .
12821282
.It Sy special_small_blocks Ns = Ns Ar size
12831283
This value represents the threshold block size for including small file
1284-
blocks into the special allocation class.
1284+
or zvol blocks into the special allocation class.
12851285
Blocks smaller than or equal to this
12861286
value will be assigned to the special allocation class while greater blocks
12871287
will be assigned to the regular class.
12881288
Valid values are zero or a power of two from 512 up to 1048576 (1 MiB).
1289-
The default size is 0 which means no small file blocks
1289+
The default size is 0 which means no small file or zvol blocks
12901290
will be allocated in the special class.
12911291
.Pp
12921292
Before setting this property, a special class vdev must be added to the

man/man7/zpoolconcepts.7

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ current state of the pool won't be scanned during a scrub.
488488
Allocations in the special class are dedicated to specific block types.
489489
By default, this includes all metadata, the indirect blocks of user data, and
490490
any deduplication tables.
491-
The class can also be provisioned to accept small file blocks.
491+
The class can also be provisioned to accept small file blocks or zvol blocks
492+
on a per dataset granularity.
492493
.Pp
493494
A pool must always have at least one normal
494495
.Pq non- Ns Sy dedup Ns /- Ns Sy special
@@ -503,7 +504,7 @@ Deduplication tables can be excluded from the special class by unsetting the
503504
.Sy zfs_ddt_data_is_special
504505
ZFS module parameter.
505506
.Pp
506-
Inclusion of small file blocks in the special class is opt-in.
507+
Inclusion of small file or zvol blocks in the special class is opt-in.
507508
Each dataset can control the size of small file blocks allowed
508509
in the special class by setting the
509510
.Sy special_small_blocks

module/zcommon/zfs_prop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@ zfs_prop_init(void)
737737
ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE", B_FALSE,
738738
sfeatures);
739739
zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
740-
"special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
740+
"special_small_blocks", 0, PROP_INHERIT,
741+
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
741742
"zero or 512 to 1M, power of 2", "SPECIAL_SMALL_BLOCKS", B_FALSE,
742743
sfeatures);
743744

module/zfs/dmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,8 @@ dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
24892489
memset(zp->zp_salt, 0, ZIO_DATA_SALT_LEN);
24902490
memset(zp->zp_iv, 0, ZIO_DATA_IV_LEN);
24912491
memset(zp->zp_mac, 0, ZIO_DATA_MAC_LEN);
2492-
zp->zp_zpl_smallblk = DMU_OT_IS_FILE(zp->zp_type) ?
2492+
zp->zp_zpl_smallblk = (DMU_OT_IS_FILE(zp->zp_type) ||
2493+
zp->zp_type == DMU_OT_ZVOL) ?
24932494
os->os_zpl_special_smallblock : 0;
24942495
zp->zp_storage_type = dn ? dn->dn_storage_type : DMU_OT_NONE;
24952496

module/zfs/spa_misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,11 +2064,11 @@ spa_preferred_class(spa_t *spa, const zio_t *zio)
20642064
}
20652065

20662066
/*
2067-
* Allow small file blocks in special class in some cases (like
2068-
* for the dRAID vdev feature). But always leave a reserve of
2067+
* Allow small file or zvol blocks in special class if opted in by
2068+
* the special_smallblk property. However, always leave a reserve of
20692069
* zfs_special_class_metadata_reserve_pct exclusively for metadata.
20702070
*/
2071-
if (DMU_OT_IS_FILE(objtype) &&
2071+
if ((DMU_OT_IS_FILE(objtype) || objtype == DMU_OT_ZVOL) &&
20722072
has_special_class && zio->io_size <= zp->zp_zpl_smallblk) {
20732073
metaslab_class_t *special = spa_special_class(spa);
20742074
uint64_t alloc = metaslab_class_get_alloc(special);

tests/runfiles/common.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ tests = ['alloc_class_001_pos', 'alloc_class_002_neg', 'alloc_class_003_pos',
3737
'alloc_class_004_pos', 'alloc_class_005_pos', 'alloc_class_006_pos',
3838
'alloc_class_007_pos', 'alloc_class_008_pos', 'alloc_class_009_pos',
3939
'alloc_class_010_pos', 'alloc_class_011_neg', 'alloc_class_012_pos',
40-
'alloc_class_013_pos', 'alloc_class_014_neg', 'alloc_class_015_pos']
40+
'alloc_class_013_pos', 'alloc_class_014_neg', 'alloc_class_015_pos',
41+
'alloc_class_016_pos']
4142
tags = ['functional', 'alloc_class']
4243

4344
[tests/functional/append]

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
429429
functional/alloc_class/alloc_class_013_pos.ksh \
430430
functional/alloc_class/alloc_class_014_neg.ksh \
431431
functional/alloc_class/alloc_class_015_pos.ksh \
432+
functional/alloc_class/alloc_class_016_pos.ksh \
432433
functional/alloc_class/cleanup.ksh \
433434
functional/alloc_class/setup.ksh \
434435
functional/append/file_append.ksh \
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
4+
#
5+
# This file and its contents are supplied under the terms of the
6+
# Common Development and Distribution License ("CDDL"), version 1.0.
7+
# You may only use this file in accordance with the terms of version
8+
# 1.0 of the CDDL.
9+
#
10+
# A full copy of the text of the CDDL should have accompanied this
11+
# source. A copy of the CDDL is also available via the Internet at
12+
# http://www.illumos.org/license/CDDL.
13+
#
14+
15+
. $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib
16+
17+
#
18+
# DESCRIPTION:
19+
# File blocks and zvol blocks, where special_small_blocks is active,
20+
# are expected to end up in the special class.
21+
#
22+
23+
verify_runnable "global"
24+
25+
claim="File and zvol blocks using special_small_blocks end up in special class"
26+
27+
log_assert $claim
28+
log_onexit cleanup
29+
log_must disk_setup
30+
31+
log_must zpool create $TESTPOOL $ZPOOL_DISKS special $CLASS_DISK0
32+
33+
# Provision a filesystem with special_small_blocks and copy 10M to it
34+
log_must zfs create -o compression=off -o special_small_blocks=32K \
35+
-o recordsize=32K $TESTPOOL/$TESTFS
36+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/testfile bs=1M count=10
37+
38+
# Provision a volume with special_small_blocks and copy 10M to it
39+
log_must zfs create -V 100M -b 32K -o special_small_blocks=32K \
40+
-o compression=off $TESTPOOL/$TESTVOL
41+
block_device_wait "$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL"
42+
log_must dd if=/dev/urandom of=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL bs=1M count=10
43+
44+
sync_pool $TESTPOOL
45+
zpool list -v $TESTPOOL
46+
47+
# Get the amount allocated to special vdev using vdev 'allocated' property
48+
result=$(zpool get -Hp allocated $TESTPOOL $CLASS_DISK0)
49+
set -- $result
50+
allocated=$3
51+
echo $allocated bytes allocated on special device $CLASS_DISK0
52+
53+
# Confirm that at least 20M was allocated
54+
if [[ $allocated -lt 20971520 ]]
55+
then
56+
log_fail "$allocated on special vdev $CLASS_DISK0, but expecting 20M"
57+
fi
58+
59+
log_must zpool destroy -f "$TESTPOOL"
60+
log_pass $claim

0 commit comments

Comments
 (0)