lkml.org 
[lkml]   [2014]   [May]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm: filemap: Avoid unnecessary barries and waitqueue lookups in unlock_page fastpath v4
On 05/15, Mel Gorman wrote:
>
> This patch introduces a new page flag for 64-bit capable machines,
> PG_waiters, to signal there are processes waiting on PG_lock and uses it to
> avoid memory barriers and waitqueue hash lookup in the unlock_page fastpath.

I can't apply this patch, it depends on something else, so I am not sure
I read it correctly. I'll try to read it later, just one question for now.

> void unlock_page(struct page *page)
> {
> + wait_queue_head_t *wqh = clear_page_waiters(page);
> +
> VM_BUG_ON_PAGE(!PageLocked(page), page);
> - clear_bit_unlock(PG_locked, &page->flags);
> +
> + /*
> + * clear_bit_unlock is not necessary in this case as there is no
> + * need to strongly order the clearing of PG_waiters and PG_locked.

OK,

> + * The smp_mb__after_atomic() barrier is still required for RELEASE
> + * semantics as there is no guarantee that a wakeup will take place
> + */
> + clear_bit(PG_locked, &page->flags);
> smp_mb__after_atomic();

But clear_bit_unlock() provides the release semantics, so why mb__after is
better?

> - wake_up_page(page, PG_locked);
> +
> + /*
> + * Wake the queue if waiters were detected. Ordinarily this wakeup
> + * would be unconditional to catch races between the lock bit being
> + * set and a new process joining the queue. However, that would
> + * require the waitqueue to be looked up every time. Instead we
> + * optimse for the uncontended and non-race case and recover using
> + * a timeout in sleep_on_page.
> + */
> + if (wqh)
> + __wake_up_bit(wqh, &page->flags, PG_locked);

This is what I can't understand. Given that PageWaiters() logic is racy
anyway (and timeout(HZ) should save us), why do we need to call
clear_page_waiters() beforehand? Why unlock_page/end_page_writeback can't
simply call wake_up_page_bit() which checks/clears PG_waiters at the end?

Oleg.



\
 
 \ /
  Last update: 2014-05-15 17:41    [W:0.220 / U:0.772 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site