mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-25 21:54:06 +08:00
dm cache policy mq: keep track of the number of entries in a multiqueue
Small optimisation, now queue_empty() doesn't need to walk all levels of the multiqueue. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
This commit is contained in:
parent
ac1f9ef211
commit
75da39bf25
@ -126,6 +126,7 @@ static void iot_examine_bio(struct io_tracker *t, struct bio *bio)
|
|||||||
#define NR_QUEUE_LEVELS 16u
|
#define NR_QUEUE_LEVELS 16u
|
||||||
|
|
||||||
struct queue {
|
struct queue {
|
||||||
|
unsigned nr_elts;
|
||||||
struct list_head qs[NR_QUEUE_LEVELS];
|
struct list_head qs[NR_QUEUE_LEVELS];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,23 +134,14 @@ static void queue_init(struct queue *q)
|
|||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
q->nr_elts = 0;
|
||||||
for (i = 0; i < NR_QUEUE_LEVELS; i++)
|
for (i = 0; i < NR_QUEUE_LEVELS; i++)
|
||||||
INIT_LIST_HEAD(q->qs + i);
|
INIT_LIST_HEAD(q->qs + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks to see if the queue is empty.
|
|
||||||
* FIXME: reduce cpu usage.
|
|
||||||
*/
|
|
||||||
static bool queue_empty(struct queue *q)
|
static bool queue_empty(struct queue *q)
|
||||||
{
|
{
|
||||||
unsigned i;
|
return q->nr_elts == 0;
|
||||||
|
|
||||||
for (i = 0; i < NR_QUEUE_LEVELS; i++)
|
|
||||||
if (!list_empty(q->qs + i))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -157,11 +149,13 @@ static bool queue_empty(struct queue *q)
|
|||||||
*/
|
*/
|
||||||
static void queue_push(struct queue *q, unsigned level, struct list_head *elt)
|
static void queue_push(struct queue *q, unsigned level, struct list_head *elt)
|
||||||
{
|
{
|
||||||
|
q->nr_elts++;
|
||||||
list_add_tail(elt, q->qs + level);
|
list_add_tail(elt, q->qs + level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queue_remove(struct list_head *elt)
|
static void queue_remove(struct queue *q, struct list_head *elt)
|
||||||
{
|
{
|
||||||
|
q->nr_elts--;
|
||||||
list_del(elt);
|
list_del(elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +191,7 @@ static struct list_head *queue_pop(struct queue *q)
|
|||||||
struct list_head *r = queue_peek(q);
|
struct list_head *r = queue_peek(q);
|
||||||
|
|
||||||
if (r) {
|
if (r) {
|
||||||
|
q->nr_elts--;
|
||||||
list_del(r);
|
list_del(r);
|
||||||
|
|
||||||
/* have we just emptied the bottom level? */
|
/* have we just emptied the bottom level? */
|
||||||
@ -496,7 +491,11 @@ static void push(struct mq_policy *mq, struct entry *e)
|
|||||||
*/
|
*/
|
||||||
static void del(struct mq_policy *mq, struct entry *e)
|
static void del(struct mq_policy *mq, struct entry *e)
|
||||||
{
|
{
|
||||||
queue_remove(&e->list);
|
if (in_cache(mq, e))
|
||||||
|
queue_remove(e->dirty ? &mq->cache_dirty : &mq->cache_clean, &e->list);
|
||||||
|
else
|
||||||
|
queue_remove(&mq->pre_cache, &e->list);
|
||||||
|
|
||||||
hash_remove(e);
|
hash_remove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user