2.6.6-rc3-mm2
Subsystems (5)
Hello.
Quoted 1 line · Andrew Morton
+filtered-wakeups-core.patch
i beleive, there is better alternative, patch at the end.
Review
Quoted 9 lines
(quoted diff) +9
-0+void fastcall wake_up_filtered(wait_queue_head_t *q, void *key) +{ + struct filtered_wait_queue *wait, *save; + + list_for_each_entry_safe(wait, save, &q->task_list, wait.task_list) { + if (wait->key == key) + wait->wait.func(&wait->wait, mode, 0); + } +}
this way we cannot mix filtered/nonfiltered waiters on one wait_queue_head_t, and we have to modify both waiters and wakers.
i think we can shift this check in wait_queue_t.func:
struct wait_bit_queue {
unsigned long *flags;
int bit_nr;
wait_queue_t wait;
};#define DEFINE_WAIT_BIT(name, _flags, _bit_nr) \
struct wait_bit_queue name = { \
.flags = _flags, \
.bit_nr = _bit_nr, \
.wait = { \
.task = current, \
.func = wake_bit_function, \
.task_list = LIST_HEAD_INIT(name.wait.task_list), \
}, \
}int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync)
{
struct wait_bit_queue *wait_bit =
container_of(wait, struct wait_bit_queue, wait);
if (test_bit(wait_bit->bit_nr, wait_bit->flags))
return 0;
return autoremove_wake_function(wait, mode, sync);
}This way only waiters must be modified, and we can use page_waitqueue(page) for nonfiltered wait too.
void fastcall wait_on_page_bit(struct page *page, int bit_nr)
{
wait_queue_head_t *waitqueue = page_waitqueue(page);
DEFINE_WAIT_BIT(wait, &page->flags, bit_nr);
prepare_to_wait(waitqueue, &wait.wait, TASK_UNINTERRUPTIBLE);
if (test_bit(bit_nr, &page->flags)) {
sync_page(page);
io_schedule();
}
finish_wait(waitqueue, &wait.wait);
}__wait_on_buffer() can use DEFINE_WAIT_BIT(wait, &bh->b_state, BH_Lock)
fs/jbd/transaction.c
Quoted 6 lines
fs/jbd/transaction.c renamed from fs/jbd/transaction.c~filtered-buffer_head-wakeups-tweaks +2
-2- wqh =bh_waitq_head (jh2bh (jh)); -wait_event_filtered (*wqh,jh2bh (jh), (jh->b_jlist != BJ_Shadow)); + wqh =bh_waitq_head (bh); +wait_event_filtered (*wqh, bh, jh->b_jlist != BJ_Shadow);
becomes unneeded.
i tested this idea on i386, what do you think about it?
Oleg.
include/linux/wait.h +20 -0
@@ -258,6 +258,26 @@ int autoremove_wake_function(wait_queue_INIT_LIST_HEAD (&wait->task_list); \ } while (0) + +struct wait_bit_queue { +unsigned long *flags; +int bit_nr; +wait_queue_t wait; +}; + +#define DEFINE_WAIT_BIT (name, _flags, _bit_nr) \ + struct wait_bit_queue name = { \ + .flags = _flags, \ + .bit_nr = _bit_nr, \ + .wait = { \ + .task = current, \ + .func = wake_bit_function, \ + .task_list = LIST_HEAD_INIT(name.wait.task_list), \ + }, \ + } + +int wake_bit_function (wait_queue_t *wait,unsigned mode,int sync); +#endif /* __KERNEL__ */ #endif
kernel/fork.c +12 -0
@@ -206,6 +206,18 @@ int autoremove_wake_function(wait_queue_EXPORT_SYMBOL (autoremove_wake_function); +int wake_bit_function (wait_queue_t *wait,unsigned mode,int sync) +{ +struct wait_bit_queue *wait_bit = + container_of(wait, struct wait_bit_queue, wait); + +if (test_bit (wait_bit->bit_nr, wait_bit->flags)) +return 0 ; + +return autoremove_wake_function (wait, mode, sync); +} + +void __init fork_init (unsigned long mempages) {#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
mm/filemap.c +11 -20
@@ -297,16 +297,16 @@ static wait_queue_head_t *page_waitqueue void fastcall wait_on_page_bit(struct page *page, int bit_nr) {wait_queue_head_t *waitqueue =page_waitqueue (page); -DEFINE_WAIT (wait); +DEFINE_WAIT_BIT (wait, &page->flags, bit_nr); -do { -prepare_to_wait (waitqueue, &wait,TASK_UNINTERRUPTIBLE ); -if (test_bit (bit_nr, &page->flags)) { -sync_page (page); -io_schedule (); - } - }while (test_bit (bit_nr, &page->flags)); -finish_wait (waitqueue, &wait); +prepare_to_wait (waitqueue, &wait.wait,TASK_UNINTERRUPTIBLE ); + +if (test_bit (bit_nr, &page->flags)) { +sync_page (page); +io_schedule (); + } + +finish_wait (waitqueue, &wait.wait); }EXPORT_SYMBOL (wait_on_page_bit);
@@ -369,17 +369,8 @@ EXPORT_SYMBOL(end_page_writeback);*/ void fastcall __lock_page(struct page *page) { -wait_queue_head_t *wqh =page_waitqueue (page); -DEFINE_WAIT (wait); - -while (TestSetPageLocked (page)) { -prepare_to_wait (wqh, &wait,TASK_UNINTERRUPTIBLE ); -if (PageLocked (page)) { -sync_page (page); -io_schedule (); - } - } -finish_wait (wqh, &wait); +while (TestSetPageLocked (page)) +wait_on_page_bit (page, PG_locked); }EXPORT_SYMBOL (__lock_page);
Hello.
Quoted 2 lines
This way only waiters must be modified, and we can use
page_waitqueue(page)for nonfiltered wait too.
also, exclusive wakeups have no problems, and process waiting in wait_on_page_writeback() won't be waken by unlock_page(). it will be waken _only_ when that bit will be cleared.
Quoted 6 lines
(quoted diff) +4
-0+wake-one-pg_locked-bh_lock-semantics.patch +static void *page_key(struct page *page, unsigned long bit) +{ + return (void *)(page_to_pfn(page) | bit << PAGE_KEY_SHIFT);}
become unneeded as well.
Oleg.
Quoted 4 lines · Oleg Nesterov
also, exclusive wakeups have no problems, and process waiting in
wait_on_page_writeback()won't be waken byunlock_page(). it will be waken _only_ when that bit will be cleared.
I didn't feel obligated to answer the last time since I suspected you'd not press the issue after realizing the error.
The object isn't passed down to the wake function at all, so it can't avoid falsely scheduling waiters on the wrong objects and/or bits.
-- wli
Hello.
Quoted 9 lines · William Lee Irwin III
Quoted 4 lines · Oleg Nesterov
also, exclusive wakeups have no problems, and process waiting in
wait_on_page_writeback()won't be waken byunlock_page(). it will be waken _only_ when that bit will be cleared.The object isn't passed down to the wake function at all, so it can't avoid falsely scheduling waiters on the wrong objects and/or bits.
I think you are wrong. __wake_up_common() calls wait_queue_t().func, which is wake_bit_function(). It casts wait argument to wait_bit_queue, and checks test_bit(wait_bit->bit_nr, wait_bit->flags) in _waker_ context, and wakes up wait->task _only_ if that bit is cleared, so there is no false wakeups.
Oleg.