linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Alistair John Strachan <s0348365@sms.ed.ac.uk>
Cc: linux-kernel@vger.kernel.org,
	"David Martínez Moreno" <ender@debian.org>,
	"Andrew Morton" <akpm@osdl.org>,
	linux-mm@kvack.org
Subject: Fix sleep_on abuse in XFS, Was: Re: 2.6.2-rc2-mm1 (Breakage?)
Date: Wed, 28 Jan 2004 13:33:58 +0000	[thread overview]
Message-ID: <20040128133357.A28038@infradead.org> (raw)
In-Reply-To: <200401281225.37234.s0348365@sms.ed.ac.uk>; from s0348365@sms.ed.ac.uk on Wed, Jan 28, 2004 at 12:25:37PM +0000

Okay, okay, I give up, here's a patch to remove sleep_on usage from XFS.

It's not actually racy but such horrible code deserves to be replaced
anyway.


Index: fs/xfs/linux-2.6/xfs_buf.c
===================================================================
RCS file: /cvs/linux-2.6-xfs/fs/xfs/linux-2.6/xfs_buf.c,v
retrieving revision 1.136
diff -u -p -r1.136 xfs_buf.c
--- fs/xfs/linux-2.6/xfs_buf.c	27 Jan 2004 18:47:46 -0000	1.136
+++ fs/xfs/linux-2.6/xfs_buf.c	28 Jan 2004 13:09:33 -0000
@@ -80,7 +80,7 @@
  */
 
 STATIC kmem_cache_t *pagebuf_cache;
-STATIC void pagebuf_daemon_wakeup(int);
+STATIC void pagebuf_daemon_wakeup(void);
 STATIC void pagebuf_delwri_queue(page_buf_t *, int);
 STATIC struct workqueue_struct *pagebuf_logio_workqueue;
 STATIC struct workqueue_struct *pagebuf_dataio_workqueue;
@@ -510,7 +510,7 @@ _pagebuf_lookup_pages(
 			if (!page) {
 				if (--retry_count > 0) {
 					PB_STATS_INC(pb_page_retries);
-					pagebuf_daemon_wakeup(1);
+					pagebuf_daemon_wakeup();
 					current->state = TASK_UNINTERRUPTIBLE;
 					schedule_timeout(10);
 					goto retry;
@@ -1640,7 +1605,6 @@ pagebuf_iomove(
  * Pagebuf delayed write buffer handling
  */
 
-STATIC int pbd_active = 1;
 STATIC LIST_HEAD(pbd_delwrite_queue);
 STATIC spinlock_t pbd_delwrite_lock = SPIN_LOCK_UNLOCKED;
 
@@ -1687,21 +1651,19 @@ pagebuf_runall_queues(
 }
 
 /* Defines for pagebuf daemon */
-DECLARE_WAIT_QUEUE_HEAD(pbd_waitq);
+STATIC DECLARE_COMPLETION(pagebuf_daemon_done);
+STATIC struct task_struct *pagebuf_daemon_task;
+STATIC int pagebuf_daemon_active;
 STATIC int force_flush;
 
 STATIC void
-pagebuf_daemon_wakeup(
-	int			flag)
+pagebuf_daemon_wakeup(void)
 {
-	force_flush = flag;
-	if (waitqueue_active(&pbd_waitq)) {
-		wake_up_interruptible(&pbd_waitq);
-	}
+	force_flush = 1;
+	barrier();
+	wake_up_process(pagebuf_daemon_task);
 }
 
-typedef void (*timeout_fn)(unsigned long);
-
 STATIC int
 pagebuf_daemon(
 	void			*data)
@@ -1709,29 +1671,22 @@ pagebuf_daemon(
 	int			count;
 	page_buf_t		*pb;
 	struct list_head	*curr, *next, tmp;
-	struct timer_list	pb_daemon_timer =
-		TIMER_INITIALIZER((timeout_fn)pagebuf_daemon_wakeup, 0, 0);
 
 	/*  Set up the thread  */
 	daemonize("pagebufd");
-
 	current->flags |= PF_MEMALLOC;
 
+	pagebuf_daemon_task = current;
+	pagebuf_daemon_active = 1;
+	barrier();
+
 	INIT_LIST_HEAD(&tmp);
 	do {
 		/* swsusp */
 		if (current->flags & PF_FREEZE)
 			refrigerator(PF_IOTHREAD);
 
-		if (pbd_active == 1) {
-			mod_timer(&pb_daemon_timer,
-				  jiffies + pb_params.flush_interval.val);
-			interruptible_sleep_on(&pbd_waitq);
-		}
-
-		if (pbd_active == 0) {
-			del_timer_sync(&pb_daemon_timer);
-		}
+		schedule_timeout(pb_params.flush_interval.val);
 
 		spin_lock(&pbd_delwrite_lock);
 
@@ -1775,11 +1730,9 @@ pagebuf_daemon(
 			blk_run_queues();
 
 		force_flush = 0;
-	} while (pbd_active == 1);
-
-	pbd_active = -1;
-	wake_up_interruptible(&pbd_waitq);
+	} while (pagebuf_daemon_active);
 
+	complete(&pagebuf_daemon_done);
 	return 0;
 }
 
@@ -1890,9 +1843,10 @@ pagebuf_daemon_start(void)
 STATIC void
 pagebuf_daemon_stop(void)
 {
-	pbd_active = 0;
-	wake_up_interruptible(&pbd_waitq);
-	wait_event_interruptible(pbd_waitq, pbd_active);
+	pagebuf_daemon_active = 0;
+	barrier();
+	wait_for_completion(&pagebuf_daemon_done);
+
 	destroy_workqueue(pagebuf_logio_workqueue);
 	destroy_workqueue(pagebuf_dataio_workqueue);
 }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

  reply	other threads:[~2004-01-28 13:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-28  7:34 2.6.2-rc2-mm1 Andrew Morton
2004-01-28  7:55 ` 2.6.2-rc2-mm1 Mike Fedyk
2004-01-28  8:18 ` ALSA noise (was: Re: 2.6.2-rc2-mm1) Joshua Kwan
2004-01-28  9:41 ` 2.6.2-rc2-mm1 Christoph Hellwig
2004-01-28 19:38   ` 2.6.2-rc2-mm1 David S. Miller
2004-01-28 12:08 ` 2.6.2-rc2-mm1 Ramon Rey Vicente
2004-01-28 12:13 ` 2.6.2-rc2-mm1 (Breakage?) David Martínez Moreno
2004-01-28 12:25   ` Alistair John Strachan
2004-01-28 13:33     ` Christoph Hellwig [this message]
2004-01-28 14:28       ` Fix sleep_on abuse in XFS, Was: " David Woodhouse
2004-01-28 15:02         ` Christoph Hellwig
2004-01-29  6:20           ` Nathan Scott
2004-01-29 23:37     ` Alexander Hoogerhuis
2004-01-28 12:17 ` 2.6.2-rc2-mm1 Nikita Danilov
2004-01-28 13:08 ` 2.6.2-rc2-mm1 Stian Jordet
2004-01-28 15:32 ` 2.6.2-rc2-mm1 Randy.Dunlap
2004-01-28 21:25   ` 2.6.2-rc2-mm1 Andrew Morton
2004-01-28 17:02 ` [BUG] [2.6.2-rc2-mm1] Badness in try_to_wake_up at kernel/sched.c:722 (was Re: 2.6.2-rc2-mm1) Ramon Rey Vicente
2004-01-28 19:55 ` 2.6.2-rc2-mm1 Torrey Hoffman
2004-01-29 16:15 ` 2.6.2-rc2-mm1 Zephaniah E. Hull
2004-01-30 10:48 ` 2.6.2-rc2-mm1 Zephaniah E. Hull
2004-01-30 11:02   ` 2.6.2-rc2-mm1 Vojtech Pavlik
2004-01-30 11:18     ` 2.6.2-rc2-mm1 Zephaniah E. Hull
2004-01-30 11:20       ` 2.6.2-rc2-mm1 Vojtech Pavlik
2004-01-30 12:41         ` 2.6.2-rc2-mm1 Zephaniah E. Hull

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=20040128133357.A28038@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@osdl.org \
    --cc=ender@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=s0348365@sms.ed.ac.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox