[Devel] [PATCH rh7 2/4] ploop: introduce plo->free_qlen counter
Maxim Patlasov
mpatlasov at virtuozzo.com
Mon Jul 11 21:58:53 PDT 2016
ploop device maintains the list of free ploop requests: plo->free_list.
Let's count the number of items in the list: plo->free_qlen. The counter
will be used in next patches of this patch-set.
The patch also introduces plo->free_qmax counter -- total number of
allocated ploop requests. This is useful to compare plo->free_qlen
with (in case plo->tune.max_requests changed in flight).
https://jira.sw.ru/browse/PSBM-49454
Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
drivers/block/ploop/dev.c | 15 ++++++++++++++-
drivers/block/ploop/sysfs.c | 12 ++++++++++++
include/linux/ploop/ploop.h | 2 ++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 9992ae5..cc33b2d 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -191,6 +191,7 @@ ploop_alloc_request(struct ploop_device * plo)
preq = list_entry(plo->free_list.next, struct ploop_request, list);
list_del_init(&preq->list);
+ plo->free_qlen--;
ploop_congest(plo);
return preq;
}
@@ -231,6 +232,7 @@ void ploop_preq_drop(struct ploop_device * plo, struct list_head *drop_list,
int keep_locked)
{
struct ploop_request * preq;
+ int drop_qlen = 0;
list_for_each_entry(preq, drop_list, list) {
if (preq->ioc) {
@@ -240,11 +242,13 @@ void ploop_preq_drop(struct ploop_device * plo, struct list_head *drop_list,
}
BUG_ON (test_bit(PLOOP_REQ_ZERO, &preq->state));
+ drop_qlen++;
}
spin_lock_irq(&plo->lock);
list_splice_init(drop_list, plo->free_list.prev);
+ plo->free_qlen += drop_qlen;
if (waitqueue_active(&plo->req_waitq))
wake_up(&plo->req_waitq);
else if (test_bit(PLOOP_S_WAIT_PROCESS, &plo->state) &&
@@ -489,9 +493,11 @@ ploop_bio_queue(struct ploop_device * plo, struct bio * bio,
{
struct ploop_request * preq;
- BUG_ON (list_empty(&plo->free_list));
+ BUG_ON(list_empty(&plo->free_list));
+ BUG_ON(plo->free_qlen <= 0);
preq = list_entry(plo->free_list.next, struct ploop_request, list);
list_del_init(&preq->list);
+ plo->free_qlen--;
preq->req_cluster = bio->bi_sector >> plo->cluster_log;
bio->bi_next = NULL;
@@ -529,6 +535,7 @@ ploop_bio_queue(struct ploop_device * plo, struct bio * bio,
}
BIO_ENDIO(plo->queue, bio, err);
list_add(&preq->list, &plo->free_list);
+ plo->free_qlen++;
plo->bio_discard_qlen--;
plo->bio_total--;
return;
@@ -1387,6 +1394,7 @@ static void ploop_complete_request(struct ploop_request * preq)
} else {
ploop_uncongest(plo);
list_add(&preq->list, &plo->free_list);
+ plo->free_qlen++;
if (waitqueue_active(&plo->req_waitq))
wake_up(&plo->req_waitq);
else if (test_bit(PLOOP_S_WAIT_PROCESS, &plo->state) &&
@@ -3799,6 +3807,8 @@ static int ploop_start(struct ploop_device * plo, struct block_device *bdev)
preq->plo = plo;
INIT_LIST_HEAD(&preq->delay_list);
list_add(&preq->list, &plo->free_list);
+ plo->free_qlen++;
+ plo->free_qmax++;
}
list_for_each_entry_reverse(delta, &plo->map.delta_list, list) {
@@ -3951,8 +3961,11 @@ static int ploop_stop(struct ploop_device * plo, struct block_device *bdev)
preq = list_first_entry(&plo->free_list, struct ploop_request, list);
list_del(&preq->list);
+ plo->free_qlen--;
+ plo->free_qmax--;
kfree(preq);
}
+ BUG_ON(plo->free_qlen);
ploop_map_destroy(&plo->map);
if (plo->trans_map)
diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index d6dcc83..c062c1e 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -425,6 +425,16 @@ static ssize_t print_push_backup_uuid(struct ploop_device * plo, char * page)
return snprintf(page, PAGE_SIZE, "%pUB\n", uuid);
}
+static u32 show_free_reqs(struct ploop_device * plo)
+{
+ return plo->free_qlen;
+}
+
+static u32 show_free_qmax(struct ploop_device * plo)
+{
+ return plo->free_qmax;
+}
+
#define _TUNE_U32(_name) \
static u32 show_##_name(struct ploop_device * plo) \
{ \
@@ -507,6 +517,8 @@ static struct attribute *state_attributes[] = {
_A3(cookie),
_A3(push_backup_uuid),
_A(open_count),
+ _A(free_reqs),
+ _A(free_qmax),
NULL
};
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index b03565b..87a530e 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -364,6 +364,8 @@ struct ploop_device
struct list_head entry_queue;
int entry_qlen;
int read_sync_reqs;
+ int free_qlen; /* len of free_list */
+ int free_qmax; /* max len of free_list */
struct bio *bio_head;
struct bio *bio_tail;
More information about the Devel
mailing list