All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: linux-kernel@vger.kernel.org,
	William Lee Irwin III <wli@holomorphy.com>,
	Andrew Morton <akpm@osdl.org>
Subject: Re: 2.6.6-rc3-mm2
Date: Wed, 05 May 2004 15:28:43 +0400	[thread overview]
Message-ID: <4098CFEB.468E6326@tv-sign.ru> (raw)

Hello.

Andrew Morton wrote:
> +filtered-wakeups-core.patch

i beleive, there is better alternative, patch at the end.

> +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)

> --- 25/fs/jbd/transaction.c~filtered-buffer_head-wakeups-tweaks	2004-05-04 23:58:14.719170368 -0700
> +++ 25-akpm/fs/jbd/transaction.c	2004-05-04 23:58:24.840631672 -0700
> -			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.

diff -urp 6.5-clean/include/linux/wait.h 6.5-waitb/include/linux/wait.h
--- 6.5-clean/include/linux/wait.h	2004-03-11 05:55:28.000000000 +0300
+++ 6.5-waitb/include/linux/wait.h	2004-05-05 14:13:23.000000000 +0400
@@ -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
diff -urp 6.5-clean/kernel/fork.c 6.5-waitb/kernel/fork.c
--- 6.5-clean/kernel/fork.c	2004-03-11 05:55:22.000000000 +0300
+++ 6.5-waitb/kernel/fork.c	2004-05-05 13:53:32.000000000 +0400
@@ -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
diff -urp 6.5-clean/mm/filemap.c 6.5-waitb/mm/filemap.c
--- 6.5-clean/mm/filemap.c	2004-04-11 13:35:37.000000000 +0400
+++ 6.5-waitb/mm/filemap.c	2004-05-05 14:38:22.000000000 +0400
@@ -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);

             reply	other threads:[~2004-05-05 11:27 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-05 11:28 Oleg Nesterov [this message]
2004-05-05 12:17 ` 2.6.6-rc3-mm2 Oleg Nesterov
2004-05-05 15:59   ` 2.6.6-rc3-mm2 William Lee Irwin III
2004-05-05 17:17     ` 2.6.6-rc3-mm2 Oleg Nesterov
     [not found] <fa.gcf87gs.1sjkoj6@ifi.uio.no>
     [not found] ` <fa.freqmjk.11j6bhe@ifi.uio.no>
2004-05-08 19:29   ` 2.6.6-rc3-mm2 Andy Lutomirski
2004-05-09 13:32     ` 2.6.6-rc3-mm2 Andi Kleen
2004-05-09 22:16       ` 2.6.6-rc3-mm2 Rusty Russell
2004-05-10  5:40         ` 2.6.6-rc3-mm2 Andi Kleen
2004-05-10 10:48           ` 2.6.6-rc3-mm2 Rusty Russell
2004-05-10  9:59         ` 2.6.6-rc3-mm2 Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2004-05-05 19:10 2.6.6-rc3-mm2 Jan Killius
2004-05-05  8:31 2.6.6-rc3-mm2 Andrew Morton
2004-05-05  8:46 ` 2.6.6-rc3-mm2 Fabio Coatti
2004-05-05  9:07 ` 2.6.6-rc3-mm2 Onur Kucuk
2004-05-05 15:33 ` 2.6.6-rc3-mm2 Christoph Hellwig
2004-05-05 17:59   ` 2.6.6-rc3-mm2 Arnd Bergmann
2004-05-05 16:06 ` 2.6.6-rc3-mm2 Paul Jackson
2004-05-05 16:40   ` 2.6.6-rc3-mm2 Christoph Hellwig
2004-05-05 16:49     ` 2.6.6-rc3-mm2 Paul Jackson
2004-05-05 20:16   ` 2.6.6-rc3-mm2 R. J. Wysocki
2004-05-06  1:51     ` 2.6.6-rc3-mm2 Paul Jackson
2004-05-06 19:38       ` 2.6.6-rc3-mm2 R. J. Wysocki
2004-05-06 14:53 ` 2.6.6-rc3-mm2 Antonio Dolcetta
2004-05-06 15:12   ` 2.6.6-rc3-mm2 Andrew Morton
2004-05-06 15:56     ` 2.6.6-rc3-mm2 Antonio Dolcetta
2004-05-06 17:26       ` 2.6.6-rc3-mm2 Adrian Bunk
2004-05-06 21:46 ` 2.6.6-rc3-mm2 Bruce Guenter
2004-05-07  2:52   ` 2.6.6-rc3-mm2 Andrew Morton
2004-05-07  4:16     ` 2.6.6-rc3-mm2 Rusty Russell
2004-05-07 16:05       ` 2.6.6-rc3-mm2 Bruce Guenter
2004-05-07 20:13       ` 2.6.6-rc3-mm2 R. J. Wysocki
2004-05-08  6:09         ` 2.6.6-rc3-mm2 Andrew Morton
     [not found]           ` <200405081329.43017.rjwysocki@sisk.pl>
2004-05-08 11:31             ` 2.6.6-rc3-mm2 Andrew Morton
2004-05-08 16:25               ` 2.6.6-rc3-mm2 R. J. Wysocki
2004-05-08 11:43             ` 2.6.6-rc3-mm2 Andrew Morton
2004-05-08 12:16               ` 2.6.6-rc3-mm2 R. J. Wysocki
2004-05-08 16:59           ` 2.6.6-rc3-mm2 Bruce Guenter
2004-05-08 18:46             ` 2.6.6-rc3-mm2 Andrew Morton
2004-05-08 18:31 ` 2.6.6-rc3-mm2 Joseph Fannin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4098CFEB.468E6326@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wli@holomorphy.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.