On Mon, Jun 20, 2005 at 09:31:26PM +0530, Suparna Bhattacharya wrote: > > (1) Updating AIO to use wait-bit based filtered wakeups (me/wli) > > Status: Updated to 2.6.12-rc6, needs review > Define low-level page wait and lock page routines which take a wait queue entry pointer as an additional parameter and return status (which may be non-zero when the wait queue parameter signifies an asynchronous wait, typically during AIO). Synchronous IO waits become a special case where the wait queue parameter is the running task's default io wait context. Asynchronous IO waits happen when the wait queue parameter is the io wait context of a kiocb. Code paths which choose to execute synchronous or asynchronous behaviour depending on the called context specify the current io wait context (which points to sync or async context as the case may be) as the wait parameter. Signed-off-by: Suparna Bhattacharya Signed-off-by: Benjamin LaHaise diff -purN --exclude=description 75_aio-wait_bit/include/linux/pagemap.h 76_aio-wait_page/include/linux/pagemap.h --- 75_aio-wait_bit/include/linux/pagemap.h 2005-08-08 17:15:54.000000000 -0400 +++ 76_aio-wait_page/include/linux/pagemap.h 2005-08-08 17:16:00.000000000 -0400 @@ -159,21 +159,25 @@ static inline pgoff_t linear_page_index( return pgoff >> (PAGE_CACHE_SHIFT - PAGE_SHIFT); } -extern void FASTCALL(lock_page_slow(struct page *page)); +extern int FASTCALL(lock_page_slow(struct page *page, wait_queue_t *wait)); extern void FASTCALL(unlock_page(struct page *page)); -static inline void lock_page(struct page *page) +static inline int __lock_page(struct page *page, wait_queue_t *wait) { might_sleep(); if (TestSetPageLocked(page)) - lock_page_slow(page); + return lock_page_slow(page, wait); + return 0; } + +#define lock_page(page) __lock_page(page, ¤t->__wait.wait) /* * This is exported only for wait_on_page_locked/wait_on_page_writeback. * Never use this directly! */ -extern void FASTCALL(wait_on_page_bit(struct page *page, int bit_nr)); +extern int FASTCALL(wait_on_page_bit(struct page *page, int bit_nr, + wait_queue_t *wait)); /* * Wait for a page to be unlocked. @@ -182,21 +186,30 @@ extern void FASTCALL(wait_on_page_bit(st * ie with increased "page->count" so that the page won't * go away during the wait.. */ -static inline void wait_on_page_locked(struct page *page) +static inline int __wait_on_page_locked(struct page *page, wait_queue_t *wait) { if (PageLocked(page)) - wait_on_page_bit(page, PG_locked); + return wait_on_page_bit(page, PG_locked, wait); + return 0; } +#define wait_on_page_locked(page) \ + __wait_on_page_locked(page, ¤t->__wait.wait) + /* * Wait for a page to complete writeback */ -static inline void wait_on_page_writeback(struct page *page) +static inline int __wait_on_page_writeback(struct page *page, + wait_queue_t *wait) { if (PageWriteback(page)) - wait_on_page_bit(page, PG_writeback); + return wait_on_page_bit(page, PG_writeback, wait); + return 0; } +#define wait_on_page_writeback(page) \ + __wait_on_page_writeback(page, ¤t->__wait.wait) + extern void end_page_writeback(struct page *page); /* diff -purN --exclude=description 75_aio-wait_bit/include/linux/sched.h 76_aio-wait_page/include/linux/sched.h --- 75_aio-wait_bit/include/linux/sched.h 2005-08-08 17:15:57.000000000 -0400 +++ 76_aio-wait_page/include/linux/sched.h 2005-08-08 17:16:00.000000000 -0400 @@ -170,6 +170,7 @@ extern void show_stack(struct task_struc void io_schedule(void); long io_schedule_timeout(long timeout); +int io_wait_schedule(wait_queue_t *wait); extern void cpu_init (void); extern void trap_init(void); diff -purN --exclude=description 75_aio-wait_bit/kernel/sched.c 76_aio-wait_page/kernel/sched.c --- 75_aio-wait_bit/kernel/sched.c 2005-08-04 15:56:08.000000000 -0400 +++ 76_aio-wait_page/kernel/sched.c 2005-08-08 17:16:00.000000000 -0400 @@ -3993,6 +3993,20 @@ long __sched io_schedule_timeout(long ti return ret; } +/* + * Sleep only if the wait context passed is not async, + * otherwise return so that a retry can be issued later. + */ +int __sched io_wait_schedule(wait_queue_t *wait) +{ + if (!is_sync_wait(wait)) + return -EIOCBRETRY; + io_schedule(); + return 0; +} + +EXPORT_SYMBOL(io_wait_schedule); + /** * sys_sched_get_priority_max - return maximum RT priority. * @policy: scheduling class. diff -purN --exclude=description 75_aio-wait_bit/mm/filemap.c 76_aio-wait_page/mm/filemap.c --- 75_aio-wait_bit/mm/filemap.c 2005-08-08 17:15:54.000000000 -0400 +++ 76_aio-wait_page/mm/filemap.c 2005-08-08 17:16:00.000000000 -0400 @@ -158,8 +158,7 @@ static int sync_page(void *word, wait_qu mapping = page_mapping(page); if (mapping && mapping->a_ops && mapping->a_ops->sync_page) mapping->a_ops->sync_page(page); - io_schedule(); - return 0; + return io_wait_schedule(wait); } /** @@ -428,13 +427,17 @@ static inline void wake_up_page(struct p __wake_up_bit(page_waitqueue(page), &page->flags, bit); } -void fastcall wait_on_page_bit(struct page *page, int bit_nr) +int fastcall wait_on_page_bit(struct page *page, int bit_nr, + wait_queue_t *wait) { - DEFINE_WAIT_BIT(wait, &page->flags, bit_nr); - - if (test_bit(bit_nr, &page->flags)) - __wait_on_bit(page_waitqueue(page), &wait, sync_page, + if (test_bit(bit_nr, &page->flags)) { + struct wait_bit_queue *wait_bit + = container_of(wait, struct wait_bit_queue, wait); + init_wait_bit_key(wait_bit, &page->flags, bit_nr); + return __wait_on_bit(page_waitqueue(page), wait_bit, sync_page, TASK_UNINTERRUPTIBLE); + } + return 0; } EXPORT_SYMBOL(wait_on_page_bit); @@ -478,18 +481,20 @@ void end_page_writeback(struct page *pag EXPORT_SYMBOL(end_page_writeback); /* - * Get a lock on the page, assuming we need to sleep to get it. + * Get a lock on the page, assuming we need to wait to get it. * * Ugly: running sync_page() in state TASK_UNINTERRUPTIBLE is scary. If some * random driver's requestfn sets TASK_RUNNING, we could busywait. However * chances are that on the second loop, the block layer's plug list is empty, * so sync_page() will then return in state TASK_UNINTERRUPTIBLE. */ -void fastcall lock_page_slow(struct page *page) +int fastcall lock_page_slow(struct page *page, wait_queue_t *wait) { - DEFINE_WAIT_BIT(wait, &page->flags, PG_locked); + struct wait_bit_queue *wait_bit + = container_of(wait, struct wait_bit_queue, wait); - __wait_on_bit_lock(page_waitqueue(page), &wait, sync_page, + init_wait_bit_key(wait_bit, &page->flags, PG_locked); + return __wait_on_bit_lock(page_waitqueue(page), wait_bit, sync_page, TASK_UNINTERRUPTIBLE); } EXPORT_SYMBOL(lock_page_slow);