Skip to content

Commit

Permalink
3537 want pool io kstats
Browse files Browse the repository at this point in the history
Reviewed by: George Wilson <[email protected]>
Reviewed by: Adam Leventhal <[email protected]>
Reviewed by: Eric Schrock <[email protected]>
Reviewed by: Sašo Kiselkov <[email protected]>
Reviewed by: Garrett D'Amore <[email protected]>
Reviewed by: Brendan Gregg <[email protected]>
Approved by: Gordon Ross <[email protected]>
  • Loading branch information
ahrens authored and Christopher Siden committed Feb 12, 2013
1 parent ccc71be commit c3a6601
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
34 changes: 32 additions & 2 deletions usr/src/lib/libzpool/common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ zk_thread_create(void (*func)(), void *arg)
*/
/*ARGSUSED*/
kstat_t *
kstat_create(char *module, int instance, char *name, char *class,
uchar_t type, ulong_t ndata, uchar_t ks_flag)
kstat_create(const char *module, int instance, const char *name,
const char *class, uchar_t type, ulong_t ndata, uchar_t ks_flag)
{
return (NULL);
}
Expand All @@ -96,6 +96,36 @@ void
kstat_delete(kstat_t *ksp)
{}

/*ARGSUSED*/
void
kstat_waitq_enter(kstat_io_t *kiop)
{}

/*ARGSUSED*/
void
kstat_waitq_exit(kstat_io_t *kiop)
{}

/*ARGSUSED*/
void
kstat_runq_enter(kstat_io_t *kiop)
{}

/*ARGSUSED*/
void
kstat_runq_exit(kstat_io_t *kiop)
{}

/*ARGSUSED*/
void
kstat_waitq_to_runq(kstat_io_t *kiop)
{}

/*ARGSUSED*/
void
kstat_runq_back_to_waitq(kstat_io_t *kiop)
{}

/*
* =========================================================================
* mutexes
Expand Down
10 changes: 8 additions & 2 deletions usr/src/lib/libzpool/common/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,16 @@ extern void cv_broadcast(kcondvar_t *cv);
/*
* kstat creation, installation and deletion
*/
extern kstat_t *kstat_create(char *, int,
char *, char *, uchar_t, ulong_t, uchar_t);
extern kstat_t *kstat_create(const char *, int,
const char *, const char *, uchar_t, ulong_t, uchar_t);
extern void kstat_install(kstat_t *);
extern void kstat_delete(kstat_t *);
extern void kstat_waitq_enter(kstat_io_t *);
extern void kstat_waitq_exit(kstat_io_t *);
extern void kstat_runq_enter(kstat_io_t *);
extern void kstat_runq_exit(kstat_io_t *);
extern void kstat_waitq_to_runq(kstat_io_t *);
extern void kstat_runq_back_to_waitq(kstat_io_t *);

/*
* Kernel memory
Expand Down
12 changes: 12 additions & 0 deletions usr/src/uts/common/fs/zfs/spa_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ spa_add(const char *name, nvlist_t *config, const char *altroot)
mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);

cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
Expand Down Expand Up @@ -559,6 +560,13 @@ spa_add(const char *name, nvlist_t *config, const char *altroot)
KM_SLEEP) == 0);
}

spa->spa_iokstat = kstat_create("zfs", 0, name,
"disk", KSTAT_TYPE_IO, 1, 0);
if (spa->spa_iokstat) {
spa->spa_iokstat->ks_lock = &spa->spa_iokstat_lock;
kstat_install(spa->spa_iokstat);
}

return (spa);
}

Expand Down Expand Up @@ -608,6 +616,9 @@ spa_remove(spa_t *spa)

spa_config_lock_destroy(spa);

kstat_delete(spa->spa_iokstat);
spa->spa_iokstat = NULL;

for (int t = 0; t < TXG_SIZE; t++)
bplist_destroy(&spa->spa_free_bplist[t]);

Expand All @@ -625,6 +636,7 @@ spa_remove(spa_t *spa)
mutex_destroy(&spa->spa_scrub_lock);
mutex_destroy(&spa->spa_suspend_lock);
mutex_destroy(&spa->spa_vdev_top_lock);
mutex_destroy(&spa->spa_iokstat_lock);

kmem_free(spa, sizeof (spa_t));
}
Expand Down
2 changes: 2 additions & 0 deletions usr/src/uts/common/fs/zfs/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ struct spa {
uint64_t spa_deadman_calls; /* number of deadman calls */
uint64_t spa_sync_starttime; /* starting time fo spa_sync */
uint64_t spa_deadman_synctime; /* deadman expiration timer */
kmutex_t spa_iokstat_lock; /* protects spa_iokstat_* */
struct kstat *spa_iokstat; /* kstat of io to this pool */
/*
* spa_refcnt & spa_config_lock must be the last elements
* because refcount_t changes size based on compilation options.
Expand Down
54 changes: 51 additions & 3 deletions usr/src/uts/common/fs/zfs/vdev_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <sys/zfs_context.h>
#include <sys/vdev_impl.h>
#include <sys/spa_impl.h>
#include <sys/zio.h>
#include <sys/avl.h>

Expand Down Expand Up @@ -142,15 +143,62 @@ vdev_queue_fini(vdev_t *vd)
static void
vdev_queue_io_add(vdev_queue_t *vq, zio_t *zio)
{
spa_t *spa = zio->io_spa;
avl_add(&vq->vq_deadline_tree, zio);
avl_add(zio->io_vdev_tree, zio);

if (spa->spa_iokstat != NULL) {
mutex_enter(&spa->spa_iokstat_lock);
kstat_waitq_enter(spa->spa_iokstat->ks_data);
mutex_exit(&spa->spa_iokstat_lock);
}
}

static void
vdev_queue_io_remove(vdev_queue_t *vq, zio_t *zio)
{
spa_t *spa = zio->io_spa;
avl_remove(&vq->vq_deadline_tree, zio);
avl_remove(zio->io_vdev_tree, zio);

if (spa->spa_iokstat != NULL) {
mutex_enter(&spa->spa_iokstat_lock);
kstat_waitq_exit(spa->spa_iokstat->ks_data);
mutex_exit(&spa->spa_iokstat_lock);
}
}

static void
vdev_queue_pending_add(vdev_queue_t *vq, zio_t *zio)
{
spa_t *spa = zio->io_spa;
avl_add(&vq->vq_pending_tree, zio);
if (spa->spa_iokstat != NULL) {
mutex_enter(&spa->spa_iokstat_lock);
kstat_runq_enter(spa->spa_iokstat->ks_data);
mutex_exit(&spa->spa_iokstat_lock);
}
}

static void
vdev_queue_pending_remove(vdev_queue_t *vq, zio_t *zio)
{
spa_t *spa = zio->io_spa;
avl_remove(&vq->vq_pending_tree, zio);
if (spa->spa_iokstat != NULL) {
kstat_io_t *ksio = spa->spa_iokstat->ks_data;

mutex_enter(&spa->spa_iokstat_lock);
kstat_runq_exit(spa->spa_iokstat->ks_data);
if (zio->io_type == ZIO_TYPE_READ) {
ksio->reads++;
ksio->nread += zio->io_size;
} else if (zio->io_type == ZIO_TYPE_WRITE) {
ksio->writes++;
ksio->nwritten += zio->io_size;
}
mutex_exit(&spa->spa_iokstat_lock);
}
}

static void
Expand Down Expand Up @@ -317,7 +365,7 @@ vdev_queue_io_to_issue(vdev_queue_t *vq, uint64_t pending_limit)
zio_execute(dio);
} while (dio != lio);

avl_add(&vq->vq_pending_tree, aio);
vdev_queue_pending_add(vq, aio);

return (aio);
}
Expand All @@ -339,7 +387,7 @@ vdev_queue_io_to_issue(vdev_queue_t *vq, uint64_t pending_limit)
goto again;
}

avl_add(&vq->vq_pending_tree, fio);
vdev_queue_pending_add(vq, fio);

return (fio);
}
Expand Down Expand Up @@ -395,7 +443,7 @@ vdev_queue_io_done(zio_t *zio)

mutex_enter(&vq->vq_lock);

avl_remove(&vq->vq_pending_tree, zio);
vdev_queue_pending_remove(vq, zio);

vq->vq_io_complete_ts = ddi_get_lbolt64();
vq->vq_io_delta_ts = vq->vq_io_complete_ts - zio->io_timestamp;
Expand Down

0 comments on commit c3a6601

Please sign in to comment.