Re: [PATCH 02/14] DRBD: lru_cache

From: Philipp Reisner
Date: Wed Apr 15 2009 - 11:30:49 EST


[...]
> > +struct lc_element *lc_find(struct lru_cache *lc, unsigned int enr)
> > +{
> > + struct hlist_node *n;
> > + struct lc_element *e;
> > +
> > + BUG_ON(!lc);
> > + BUG_ON(!lc->nr_elements);
>
> This BUG_ON() could be moved/added to lc_init().
>

You are right. Done.

> > +struct lc_element *lc_get(struct lru_cache *lc, unsigned int enr)
> > +{
> > + struct lc_element *e;
> > +
> > + BUG_ON(!lc);
> > + BUG_ON(!lc->nr_elements);
> > +
> > + PARANOIA_ENTRY();
> > + if (lc->flags & LC_STARVING) {
> > + ++lc->starving;
> > + RETURN(NULL);
> > + }
> > +
>
> Even if LC_STARVING, the element could still be available in the cache?
> Shouldn't this check be done after lc_find()?
>

[...]
> > +/* similar to lc_get,
> > + * but only gets a new reference on an existing element.
> > + * you either get the requested element, or NULL.
> > + */
> > +struct lc_element *lc_try_get(struct lru_cache *lc, unsigned int enr)
> > +{
> > + struct lc_element *e;
> > +
> > + BUG_ON(!lc);
> > + BUG_ON(!lc->nr_elements);
> > +
> > + PARANOIA_ENTRY();
> > + if (lc->flags & LC_STARVING) {
> > + ++lc->starving;
> > + RETURN(NULL);
> > + }
> > +
>
> This check shouldn't be done at all, as we are not at all trying to add a
> new element?
>

That check is okay.

We set LC_STARVING if we need to change a cache slot to an other object
of the space of cacheable objects, but not a single slot was available.

If LC_STARVING is set we do not give out any further references, since we
want to finish that ongoing single object change first.

With this policy the changes in the LRU cache will never deadlock, and
eventually delay others trying to get new references to already cached
objects.

-Phil
--
: Dipl-Ing Philipp Reisner
: LINBIT | Your Way to High Availability
: Tel: +43-1-8178292-50, Fax: +43-1-8178292-82
: http://www.linbit.com

DRBD(R) and LINBIT(R) are registered trademarks of LINBIT, Austria.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/