Skip to content

Commit a970f05

Browse files
committed
Linux 5.11 compat: bio_start_io_acct() / bio_end_io_acct()
The generic IO accounting functions have been removed in favor of the bio_start_io_acct() and bio_end_io_acct() functions which provide a better interface. These new functions were introduced in the 5.8 kernels but it wasn't until the 5.11 kernel that the previous generic IO accounting interfaces were removed. This commit updates the blk_generic_*_io_acct() wrappers to provide and interface similar to the updated kernel interface. It's slightly different because for older kernels we need to pass the request queue as well as the bio. Reviewed-by: Rafael Kitover <[email protected]> Reviewed-by: Coleman Kane <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #11387 Closes #11390
1 parent b7281c8 commit a970f05

File tree

3 files changed

+92
-39
lines changed

3 files changed

+92
-39
lines changed

config/kernel-generic_io_acct.m4

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ dnl #
22
dnl # Check for generic io accounting interface.
33
dnl #
44
AC_DEFUN([ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT], [
5+
ZFS_LINUX_TEST_SRC([bio_io_acct], [
6+
#include <linux/blkdev.h>
7+
], [
8+
struct bio *bio = NULL;
9+
unsigned long start_time;
10+
11+
start_time = bio_start_io_acct(bio);
12+
bio_end_io_acct(bio, start_time);
13+
])
14+
515
ZFS_LINUX_TEST_SRC([generic_acct_3args], [
616
#include <linux/bio.h>
717
@@ -29,36 +39,49 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT], [
2939

3040
AC_DEFUN([ZFS_AC_KERNEL_GENERIC_IO_ACCT], [
3141
dnl #
32-
dnl # 3.19 API addition
42+
dnl # 5.7 API,
3343
dnl #
34-
dnl # torvalds/linux@394ffa50 allows us to increment iostat
35-
dnl # counters without generic_make_request().
44+
dnl # Added bio_start_io_acct() and bio_end_io_acct() helpers.
3645
dnl #
37-
AC_MSG_CHECKING([whether generic IO accounting wants 3 args])
38-
ZFS_LINUX_TEST_RESULT_SYMBOL([generic_acct_3args],
39-
[generic_start_io_acct], [block/bio.c], [
46+
AC_MSG_CHECKING([whether generic bio_*_io_acct() are available])
47+
ZFS_LINUX_TEST_RESULT([bio_io_acct], [
4048
AC_MSG_RESULT(yes)
41-
AC_DEFINE(HAVE_GENERIC_IO_ACCT_3ARG, 1,
42-
[generic_start_io_acct()/generic_end_io_acct() available])
49+
AC_DEFINE(HAVE_BIO_IO_ACCT, 1, [bio_*_io_acct() available])
4350
], [
4451
AC_MSG_RESULT(no)
4552
4653
dnl #
47-
dnl # Linux 4.14 API,
54+
dnl # 4.14 API,
4855
dnl #
4956
dnl # generic_start_io_acct/generic_end_io_acct now require
5057
dnl # request_queue to be provided. No functional changes,
5158
dnl # but preparation for inflight accounting.
5259
dnl #
53-
AC_MSG_CHECKING([whether generic IO accounting wants 4 args])
60+
AC_MSG_CHECKING([whether generic_*_io_acct wants 4 args])
5461
ZFS_LINUX_TEST_RESULT_SYMBOL([generic_acct_4args],
5562
[generic_start_io_acct], [block/bio.c], [
5663
AC_MSG_RESULT(yes)
5764
AC_DEFINE(HAVE_GENERIC_IO_ACCT_4ARG, 1,
58-
[generic_start_io_acct()/generic_end_io_acct() ]
59-
[4 arg available])
65+
[generic_*_io_acct() 4 arg available])
6066
], [
6167
AC_MSG_RESULT(no)
68+
69+
dnl #
70+
dnl # 3.19 API addition
71+
dnl #
72+
dnl # torvalds/linux@394ffa50 allows us to increment
73+
dnl # iostat counters without generic_make_request().
74+
dnl #
75+
AC_MSG_CHECKING(
76+
[whether generic_*_io_acct wants 3 args])
77+
ZFS_LINUX_TEST_RESULT_SYMBOL([generic_acct_3args],
78+
[generic_start_io_acct], [block/bio.c], [
79+
AC_MSG_RESULT(yes)
80+
AC_DEFINE(HAVE_GENERIC_IO_ACCT_3ARG, 1,
81+
[generic_*_io_acct() 3 arg available])
82+
], [
83+
AC_MSG_RESULT(no)
84+
])
6285
])
6386
])
6487
])

include/os/linux/kernel/linux/blkdev_compat.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,25 +523,38 @@ blk_queue_discard_secure(struct request_queue *q)
523523
*/
524524
#define VDEV_HOLDER ((void *)0x2401de7)
525525

526-
static inline void
527-
blk_generic_start_io_acct(struct request_queue *q, int rw,
528-
unsigned long sectors, struct hd_struct *part)
526+
static inline unsigned long
527+
blk_generic_start_io_acct(struct request_queue *q __attribute__((unused)),
528+
struct gendisk *disk __attribute__((unused)),
529+
int rw __attribute__((unused)), struct bio *bio)
529530
{
530-
#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
531-
generic_start_io_acct(rw, sectors, part);
531+
#if defined(HAVE_BIO_IO_ACCT)
532+
return (bio_start_io_acct(bio));
533+
#elif defined(HAVE_GENERIC_IO_ACCT_3ARG)
534+
unsigned long start_time = jiffies;
535+
generic_start_io_acct(rw, bio_sectors(bio), &disk->part0);
536+
return (start_time);
532537
#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
533-
generic_start_io_acct(q, rw, sectors, part);
538+
unsigned long start_time = jiffies;
539+
generic_start_io_acct(q, rw, bio_sectors(bio), &disk->part0);
540+
return (start_time);
541+
#else
542+
/* Unsupported */
543+
return (0);
534544
#endif
535545
}
536546

537547
static inline void
538-
blk_generic_end_io_acct(struct request_queue *q, int rw,
539-
struct hd_struct *part, unsigned long start_time)
548+
blk_generic_end_io_acct(struct request_queue *q __attribute__((unused)),
549+
struct gendisk *disk __attribute__((unused)),
550+
int rw __attribute__((unused)), struct bio *bio, unsigned long start_time)
540551
{
541-
#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
542-
generic_end_io_acct(rw, part, start_time);
552+
#if defined(HAVE_BIO_IO_ACCT)
553+
bio_end_io_acct(bio, start_time);
554+
#elif defined(HAVE_GENERIC_IO_ACCT_3ARG)
555+
generic_end_io_acct(rw, &disk->part0, start_time);
543556
#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
544-
generic_end_io_acct(q, rw, part, start_time);
557+
generic_end_io_acct(q, rw, &disk->part0, start_time);
545558
#endif
546559
}
547560

module/os/linux/zfs/zvol_os.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ zvol_write(void *arg)
106106
return;
107107
}
108108

109+
struct request_queue *q = zv->zv_zso->zvo_queue;
110+
struct gendisk *disk = zv->zv_zso->zvo_disk;
109111
ssize_t start_resid = uio.uio_resid;
110-
unsigned long start_jif = jiffies;
111-
blk_generic_start_io_acct(zv->zv_zso->zvo_queue, WRITE,
112-
bio_sectors(bio), &zv->zv_zso->zvo_disk->part0);
112+
unsigned long start_time;
113+
114+
boolean_t acct = blk_queue_io_stat(q);
115+
if (acct)
116+
start_time = blk_generic_start_io_acct(q, disk, WRITE, bio);
113117

114118
boolean_t sync =
115119
bio_is_fua(bio) || zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS;
@@ -153,8 +157,10 @@ zvol_write(void *arg)
153157
zil_commit(zv->zv_zilog, ZVOL_OBJ);
154158

155159
rw_exit(&zv->zv_suspend_lock);
156-
blk_generic_end_io_acct(zv->zv_zso->zvo_queue,
157-
WRITE, &zv->zv_zso->zvo_disk->part0, start_jif);
160+
161+
if (acct)
162+
blk_generic_end_io_acct(q, disk, WRITE, bio, start_time);
163+
158164
BIO_END_IO(bio, -error);
159165
kmem_free(zvr, sizeof (zv_request_t));
160166
}
@@ -171,15 +177,18 @@ zvol_discard(void *arg)
171177
boolean_t sync;
172178
int error = 0;
173179
dmu_tx_t *tx;
174-
unsigned long start_jif;
175180

176181
ASSERT3P(zv, !=, NULL);
177182
ASSERT3U(zv->zv_open_count, >, 0);
178183
ASSERT3P(zv->zv_zilog, !=, NULL);
179184

180-
start_jif = jiffies;
181-
blk_generic_start_io_acct(zv->zv_zso->zvo_queue, WRITE,
182-
bio_sectors(bio), &zv->zv_zso->zvo_disk->part0);
185+
struct request_queue *q = zv->zv_zso->zvo_queue;
186+
struct gendisk *disk = zv->zv_zso->zvo_disk;
187+
unsigned long start_time;
188+
189+
boolean_t acct = blk_queue_io_stat(q);
190+
if (acct)
191+
start_time = blk_generic_start_io_acct(q, disk, WRITE, bio);
183192

184193
sync = bio_is_fua(bio) || zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS;
185194

@@ -224,8 +233,10 @@ zvol_discard(void *arg)
224233

225234
unlock:
226235
rw_exit(&zv->zv_suspend_lock);
227-
blk_generic_end_io_acct(zv->zv_zso->zvo_queue, WRITE,
228-
&zv->zv_zso->zvo_disk->part0, start_jif);
236+
237+
if (acct)
238+
blk_generic_end_io_acct(q, disk, WRITE, bio, start_time);
239+
229240
BIO_END_IO(bio, -error);
230241
kmem_free(zvr, sizeof (zv_request_t));
231242
}
@@ -244,10 +255,14 @@ zvol_read(void *arg)
244255
ASSERT3P(zv, !=, NULL);
245256
ASSERT3U(zv->zv_open_count, >, 0);
246257

258+
struct request_queue *q = zv->zv_zso->zvo_queue;
259+
struct gendisk *disk = zv->zv_zso->zvo_disk;
247260
ssize_t start_resid = uio.uio_resid;
248-
unsigned long start_jif = jiffies;
249-
blk_generic_start_io_acct(zv->zv_zso->zvo_queue, READ, bio_sectors(bio),
250-
&zv->zv_zso->zvo_disk->part0);
261+
unsigned long start_time;
262+
263+
boolean_t acct = blk_queue_io_stat(q);
264+
if (acct)
265+
start_time = blk_generic_start_io_acct(q, disk, READ, bio);
251266

252267
zfs_locked_range_t *lr = zfs_rangelock_enter(&zv->zv_rangelock,
253268
uio.uio_loffset, uio.uio_resid, RL_READER);
@@ -275,8 +290,10 @@ zvol_read(void *arg)
275290
task_io_account_read(nread);
276291

277292
rw_exit(&zv->zv_suspend_lock);
278-
blk_generic_end_io_acct(zv->zv_zso->zvo_queue, READ,
279-
&zv->zv_zso->zvo_disk->part0, start_jif);
293+
294+
if (acct)
295+
blk_generic_end_io_acct(q, disk, READ, bio, start_time);
296+
280297
BIO_END_IO(bio, -error);
281298
kmem_free(zvr, sizeof (zv_request_t));
282299
}

0 commit comments

Comments
 (0)