From: Keith Owens <kaos@sgi.com>

New pdflush threads are launched on-demand by pdflush. 

It turns out that on some architectures (eg, ia64) a kernel thread inherits
its parent's stack utilisation.  So after the thread-launches-a-thread
cycle has progressed sufficiently far we run out of stack space and crash.

Simple fix: convert pdflush to use kthreads.  All kthreads are parented by
keventd so there is no stack windup as a result of pdflush launching
pdflush.


---

 mm/pdflush.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff -puN mm/pdflush.c~pdflush-use-kthread mm/pdflush.c
--- 25/mm/pdflush.c~pdflush-use-kthread	2004-02-28 21:31:37.000000000 -0800
+++ 25-akpm/mm/pdflush.c	2004-02-28 21:31:53.000000000 -0800
@@ -5,6 +5,9 @@
  *
  * 09Apr2002	akpm@zip.com.au
  *		Initial version
+ * 29Feb2004	kaos@sgi.com
+ *		Move worker thread creation to kthread to avoid chewing
+ *		up stack space with nested calls to kernel_thread.
  */
 
 #include <linux/sched.h>
@@ -17,6 +20,7 @@
 #include <linux/suspend.h>
 #include <linux/fs.h>		// Needed by writeback.h
 #include <linux/writeback.h>	// Prototypes pdflush_operation()
+#include <linux/kthread.h>
 
 
 /*
@@ -86,8 +90,6 @@ struct pdflush_work {
 
 static int __pdflush(struct pdflush_work *my_work)
 {
-	daemonize("pdflush");
-
 	current->flags |= PF_FLUSHER;
 	my_work->fn = NULL;
 	my_work->who = current;
@@ -207,7 +209,7 @@ int pdflush_operation(void (*fn)(unsigne
 
 static void start_one_pdflush_thread(void)
 {
-	kernel_thread(pdflush, NULL, CLONE_KERNEL);
+	kthread_run(pdflush, NULL, "pdflush");
 }
 
 static int __init pdflush_init(void)

_