[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140515154506.GF11096@twins.programming.kicks-ass.net>
Date: Thu, 15 May 2014 17:45:06 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Oleg Nesterov <oleg@...hat.com>
Cc: Mel Gorman <mgorman@...e.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Johannes Weiner <hannes@...xchg.org>,
Vlastimil Babka <vbabka@...e.cz>, Jan Kara <jack@...e.cz>,
Michal Hocko <mhocko@...e.cz>, Hugh Dickins <hughd@...gle.com>,
Dave Hansen <dave.hansen@...el.com>,
Linux Kernel <linux-kernel@...r.kernel.org>,
Linux-MM <linux-mm@...ck.org>,
Linux-FSDevel <linux-fsdevel@...r.kernel.org>,
Paul McKenney <paulmck@...ux.vnet.ibm.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
David Howells <dhowells@...hat.com>
Subject: Re: [PATCH] mm: filemap: Avoid unnecessary barries and waitqueue
lookups in unlock_page fastpath v4
On Thu, May 15, 2014 at 05:34:24PM +0200, Oleg Nesterov wrote:
> On 05/15, Peter Zijlstra wrote:
> >
> > So I suppose I'm failing to see the problem with something like:
>
> Yeeees, I was thinking about something like this too ;)
>
> > static inline void lock_page(struct page *page)
> > {
> > if (!trylock_page(page))
> > __lock_page(page);
> > }
> >
> > static inline void unlock_page(struct page *page)
> > {
> > clear_bit_unlock(&page->flags, PG_locked);
> > if (PageWaiters(page))
> > __unlock_page();
> > }
>
> but in this case we need mb() before PageWaiters(), I guess.
Ah indeed so, or rather, this is a good reason to use smp_mb__after_atomic().
> > void __lock_page(struct page *page)
> > {
> > struct wait_queue_head_t *wqh = page_waitqueue(page);
> > DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
> >
> > spin_lock_irq(&wqh->lock);
> > if (!PageWaiters(page))
> > SetPageWaiters(page);
> >
> > wait.flags |= WQ_FLAG_EXCLUSIVE;
> > preempt_disable();
>
> why?
>
> > do {
> > if (list_empty(&wait->task_list))
> > __add_wait_queue_tail(wqh, &wait);
> >
> > set_current_state(TASK_UNINTERRUPTIBLE);
> >
> > if (test_bit(wait.key.bit_nr, wait.key.flags)) {
> > spin_unlock_irq(&wqh->lock);
> > schedule_preempt_disabled();
> > spin_lock_irq(&wqh->lock);
>
> OK, probably to avoid the preemption before schedule().
Indeed.
> Still can't undestand why this makes sense,
Because calling schedule twice in a row is like a bit of wasted effort.
Its just annoying there isn't a more convenient way to express this,
because its a fairly common thing in wait loops.
> but in this case it would be better
> to do disable/enable under "if (test_bit())" ?
Ah yes.. that code grew and the preempt_disable came about before that
test_bit() block.. :-)
> Of course, this needs more work for lock_page_killable(), but this
> should be simple.
Yeah, I just wanted to illustrate the point, and cobbling one together
from various wait loops was plenty I thought ;-)
Content of type "application/pgp-signature" skipped
Powered by blists - more mailing lists