mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
zvol: Enable zvol threading functionality on FreeBSD
Make zvol I/O requests processing asynchronous on FreeBSD side in some cases. Clone zvol threading logic and required module parameters from Linux side. Make zvol threadpool creation/destruction logic shared for both Linux and FreeBSD. The IO requests are processed asynchronously in next cases: - volmode=geom: if IO request thread is geom thread or cannot sleep. - volmode=cdev: if IO request passed thru struct cdevsw .d_strategy routine, mean is AIO request. In all other cases the IO requests are processed synchronously. The volthreading zvol property is ignored on FreeBSD side. Sponsored-by: vStack, Inc. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: @ImAwsumm Signed-off-by: Fedor Uporov <fuporov.vstack@gmail.com> Closes #17169
This commit is contained in:
@@ -90,11 +90,15 @@
|
||||
|
||||
unsigned int zvol_inhibit_dev = 0;
|
||||
unsigned int zvol_volmode = ZFS_VOLMODE_GEOM;
|
||||
unsigned int zvol_threads = 0;
|
||||
unsigned int zvol_num_taskqs = 0;
|
||||
unsigned int zvol_request_sync = 0;
|
||||
|
||||
struct hlist_head *zvol_htable;
|
||||
static list_t zvol_state_list;
|
||||
krwlock_t zvol_state_lock;
|
||||
extern int zfs_bclone_wait_dirty;
|
||||
zv_taskq_t zvol_taskqs;
|
||||
|
||||
typedef enum {
|
||||
ZVOL_ASYNC_REMOVE_MINORS,
|
||||
@@ -111,6 +115,22 @@ typedef struct {
|
||||
uint64_t value;
|
||||
} zvol_task_t;
|
||||
|
||||
zv_request_task_t *
|
||||
zv_request_task_create(zv_request_t zvr)
|
||||
{
|
||||
zv_request_task_t *task;
|
||||
task = kmem_alloc(sizeof (zv_request_task_t), KM_SLEEP);
|
||||
taskq_init_ent(&task->ent);
|
||||
task->zvr = zvr;
|
||||
return (task);
|
||||
}
|
||||
|
||||
void
|
||||
zv_request_task_free(zv_request_task_t *task)
|
||||
{
|
||||
kmem_free(task, sizeof (*task));
|
||||
}
|
||||
|
||||
uint64_t
|
||||
zvol_name_hash(const char *name)
|
||||
{
|
||||
@@ -2018,6 +2038,75 @@ zvol_init_impl(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* zvol_threads is the module param the user passes in.
|
||||
*
|
||||
* zvol_actual_threads is what we use internally, since the user can
|
||||
* pass zvol_thread = 0 to mean "use all the CPUs" (the default).
|
||||
*/
|
||||
static unsigned int zvol_actual_threads;
|
||||
|
||||
if (zvol_threads == 0) {
|
||||
/*
|
||||
* See dde9380a1 for why 32 was chosen here. This should
|
||||
* probably be refined to be some multiple of the number
|
||||
* of CPUs.
|
||||
*/
|
||||
zvol_actual_threads = MAX(max_ncpus, 32);
|
||||
} else {
|
||||
zvol_actual_threads = MIN(MAX(zvol_threads, 1), 1024);
|
||||
}
|
||||
|
||||
/*
|
||||
* Use at least 32 zvol_threads but for many core system,
|
||||
* prefer 6 threads per taskq, but no more taskqs
|
||||
* than threads in them on large systems.
|
||||
*
|
||||
* taskq total
|
||||
* cpus taskqs threads threads
|
||||
* ------- ------- ------- -------
|
||||
* 1 1 32 32
|
||||
* 2 1 32 32
|
||||
* 4 1 32 32
|
||||
* 8 2 16 32
|
||||
* 16 3 11 33
|
||||
* 32 5 7 35
|
||||
* 64 8 8 64
|
||||
* 128 11 12 132
|
||||
* 256 16 16 256
|
||||
*/
|
||||
zv_taskq_t *ztqs = &zvol_taskqs;
|
||||
int num_tqs = MIN(max_ncpus, zvol_num_taskqs);
|
||||
if (num_tqs == 0) {
|
||||
num_tqs = 1 + max_ncpus / 6;
|
||||
while (num_tqs * num_tqs > zvol_actual_threads)
|
||||
num_tqs--;
|
||||
}
|
||||
|
||||
int per_tq_thread = zvol_actual_threads / num_tqs;
|
||||
if (per_tq_thread * num_tqs < zvol_actual_threads)
|
||||
per_tq_thread++;
|
||||
|
||||
ztqs->tqs_cnt = num_tqs;
|
||||
ztqs->tqs_taskq = kmem_alloc(num_tqs * sizeof (taskq_t *), KM_SLEEP);
|
||||
|
||||
for (uint_t i = 0; i < num_tqs; i++) {
|
||||
char name[32];
|
||||
(void) snprintf(name, sizeof (name), "%s_tq-%u",
|
||||
ZVOL_DRIVER, i);
|
||||
ztqs->tqs_taskq[i] = taskq_create(name, per_tq_thread,
|
||||
maxclsyspri, per_tq_thread, INT_MAX,
|
||||
TASKQ_PREPOPULATE | TASKQ_DYNAMIC);
|
||||
if (ztqs->tqs_taskq[i] == NULL) {
|
||||
for (int j = i - 1; j >= 0; j--)
|
||||
taskq_destroy(ztqs->tqs_taskq[j]);
|
||||
kmem_free(ztqs->tqs_taskq, ztqs->tqs_cnt *
|
||||
sizeof (taskq_t *));
|
||||
ztqs->tqs_taskq = NULL;
|
||||
return (SET_ERROR(ENOMEM));
|
||||
}
|
||||
}
|
||||
|
||||
list_create(&zvol_state_list, sizeof (zvol_state_t),
|
||||
offsetof(zvol_state_t, zv_next));
|
||||
rw_init(&zvol_state_lock, NULL, RW_DEFAULT, NULL);
|
||||
@@ -2033,6 +2122,8 @@ zvol_init_impl(void)
|
||||
void
|
||||
zvol_fini_impl(void)
|
||||
{
|
||||
zv_taskq_t *ztqs = &zvol_taskqs;
|
||||
|
||||
zvol_remove_minors_impl(NULL);
|
||||
|
||||
/*
|
||||
@@ -2046,4 +2137,23 @@ zvol_fini_impl(void)
|
||||
kmem_free(zvol_htable, ZVOL_HT_SIZE * sizeof (struct hlist_head));
|
||||
list_destroy(&zvol_state_list);
|
||||
rw_destroy(&zvol_state_lock);
|
||||
|
||||
if (ztqs->tqs_taskq == NULL) {
|
||||
ASSERT3U(ztqs->tqs_cnt, ==, 0);
|
||||
} else {
|
||||
for (uint_t i = 0; i < ztqs->tqs_cnt; i++) {
|
||||
ASSERT3P(ztqs->tqs_taskq[i], !=, NULL);
|
||||
taskq_destroy(ztqs->tqs_taskq[i]);
|
||||
}
|
||||
kmem_free(ztqs->tqs_taskq, ztqs->tqs_cnt *
|
||||
sizeof (taskq_t *));
|
||||
ztqs->tqs_taskq = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ZFS_MODULE_PARAM(zfs, , zvol_threads, UINT, ZMOD_RW,
|
||||
"Number of threads for I/O requests. Set to 0 to use all active CPUs");
|
||||
ZFS_MODULE_PARAM(zfs, , zvol_num_taskqs, UINT, ZMOD_RW,
|
||||
"Number of zvol taskqs");
|
||||
ZFS_MODULE_PARAM(zfs, , zvol_request_sync, UINT, ZMOD_RW,
|
||||
"Synchronously handle bio requests");
|
||||
|
||||
Reference in New Issue
Block a user