#define NR_QUEUE_LEVELS 16u
struct queue {
+ unsigned nr_elts;
struct list_head qs[NR_QUEUE_LEVELS];
};
{
unsigned i;
+ q->nr_elts = 0;
for (i = 0; i < NR_QUEUE_LEVELS; 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)
{
- unsigned i;
-
- for (i = 0; i < NR_QUEUE_LEVELS; i++)
- if (!list_empty(q->qs + i))
- return false;
-
- return true;
+ return q->nr_elts == 0;
}
/*
*/
static void queue_push(struct queue *q, unsigned level, struct list_head *elt)
{
+ q->nr_elts++;
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);
}
struct list_head *r = queue_peek(q);
if (r) {
+ q->nr_elts--;
list_del(r);
/* have we just emptied the bottom level? */
*/
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);
}