On Fri, Dec 04, 2015 at 10:16:38AM -0600, Christoph Lameter wrote:
> On Fri, 4 Dec 2015, Geliang Tang wrote:
> 
> > On Thu, Dec 03, 2015 at 08:53:21AM -0600, Christoph Lameter wrote:
> > > On Thu, 3 Dec 2015, Geliang Tang wrote:
> > >
> > > >         while (nr_freed < tofree && !list_empty(&n->slabs_free)) {
> > > >
> > > >                 spin_lock_irq(&n->list_lock);
> > > > -               p = n->slabs_free.prev;
> > > > -               if (p == &n->slabs_free) {
> > > > +               if (list_empty_careful(&n->slabs_free)) {
> > >
> > > We have taken the lock. Why do we need to be "careful"? list_empty()
> > > shoudl work right?
> >
> > Yes. list_empty() is OK.
> >
> > >
> > > >                         spin_unlock_irq(&n->list_lock);
> > > >                         goto out;
> > > >                 }
> > > >
> > > > -               page = list_entry(p, struct page, lru);
> > > > +               page = list_last_entry(&n->slabs_free, struct page, 
> > > > lru);
> > >
> > > last???
> >
> > The original code delete the page from the tail of slabs_free list.
> 
> Maybe make the code clearer by using another method to get the page
> pointer?
> 
> > >
> > > Would the the other new function that returns NULL on the empty list or
> > > the pointer not be useful here too and save some code?
> >
> > Sorry, I don't really understand what do you mean. Can you please specify
> > it a little bit?
> 
> I take that back. list_empty is the best choice here.

If we use list_empty(), there will be two list_empty() in the code:

        while (nr_freed < tofree && !list_empty(&n->slabs_free)) {
                spin_lock_irq(&n->list_lock);
                if (list_empty(&n->slabs_free)) {
                        spin_unlock_irq(&n->list_lock);
                        goto out; 
                }
                page = list_last_entry(&n->slabs_free, struct page, lru);
                list_del(&page->lru);
                spin_unlock_irq(&n->list_lock);
        }

Or can we drop the first list_empty() like this? It will function the same as 
the above code.

        while (nr_freed < tofree) {
                spin_lock_irq(&n->list_lock);
                if (list_empty(&n->slabs_free)) {
                        spin_unlock_irq(&n->list_lock);
                        goto out; 
                }
                page = list_last_entry(&n->slabs_free, struct page, lru);
                list_del(&page->lru);
                spin_unlock_irq(&n->list_lock);
        }

Please let me know which one is better?

Thanks.

- Geliang

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

Reply via email to