public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: torvalds@transmeta.com
Cc: davidm@hpl.hp.com, "David S. Miller" <davem@redhat.com>,
	David Howells <dhowells@redhat.com>,
	anton@samba.org, linux-kernel@vger.kernel.org,
	zippel@linux-m68k.org
Subject: [PATCH] move task_struct allocation to arch
Date: Thu, 14 Feb 2002 15:26:20 +0000	[thread overview]
Message-ID: <11830.1013700380@warthog.cambridge.redhat.com> (raw)


Hi Linus,

This patch moves task_struct allocation from kernel/fork.c into
arch/*/kernel/process.c.

David Mosberger wrote:

>   David.H> What might be worth doing is to move the task_struct slab
>   David.H> cache and (de-)allocator out of fork.c and to stick it in
>   David.H> the arch somewhere. Then archs aren't bound to have the two
>   David.H> separate. So for a system that can handle lots of memory,
>   David.H> you can allocate the thread_info, task_struct and
>   David.H> supervisor stack all on one very large chunk if you so
>   David.H> wish.
>
> Could you do this?  I'd prefer if task_info could be completely hidden
> inside the x86/sparc arch-specific code, but if things are set up such
> that we at least have the option to keep the stack, task_info, and
> task_struct in a single chunk of memory (and without pointers between
> them), I'd have much less of an issue with it.

David

diff -uNr linux-2.5.5-pre1/arch/i386/kernel/process.c linux-tib-255p1/arch/i386/kernel/process.c
--- linux-2.5.5-pre1/arch/i386/kernel/process.c	Thu Feb 14 14:31:13 2002
+++ linux-tib-255p1/arch/i386/kernel/process.c	Thu Feb 14 14:32:35 2002
@@ -54,6 +54,8 @@
 
 int hlt_counter;
 
+static kmem_cache_t *task_struct_cachep;
+
 /*
  * Return saved PC of a blocked thread.
  */
@@ -522,8 +524,49 @@
 }
 
 /*
- * Free current thread data structures etc..
+ * allocate and free task and thread data structures etc..
  */
+void __init init_task_struct_cache(void)
+{
+	/* create a slab on which task_structs can be allocated */
+	task_struct_cachep =
+		kmem_cache_create("task_struct",
+				  sizeof(struct task_struct),0,
+				  SLAB_HWCACHE_ALIGN, NULL, NULL);
+	if (!task_struct_cachep)
+		panic("fork_init(): cannot create task_struct SLAB cache");
+
+}
+
+struct task_struct *dup_task_struct(struct task_struct *orig)
+{
+	struct task_struct *tsk;
+	struct thread_info *ti;
+
+	ti = alloc_thread_info();
+	if (!ti) return NULL;
+
+	tsk = kmem_cache_alloc(task_struct_cachep,GFP_ATOMIC);
+	if (!tsk) {
+		free_thread_info(ti);
+		return NULL;
+	}
+
+	*ti = *orig->thread_info;
+	*tsk = *orig;
+	tsk->thread_info = ti;
+	ti->task = tsk;
+	atomic_set(&tsk->usage,1);
+
+	return tsk;
+}
+
+void __put_task_struct(struct task_struct *tsk)
+{
+	free_thread_info(tsk->thread_info);
+	kmem_cache_free(task_struct_cachep,tsk);
+}
+
 void exit_thread(void)
 {
 	/* nothing to do ... */
diff -uNr linux-2.5.5-pre1/arch/sparc64/kernel/process.c linux-tib-255p1/arch/sparc64/kernel/process.c
--- linux-2.5.5-pre1/arch/sparc64/kernel/process.c	Thu Feb 14 14:04:42 2002
+++ linux-tib-255p1/arch/sparc64/kernel/process.c	Thu Feb 14 14:21:26 2002
@@ -40,6 +40,8 @@
 #include <asm/elf.h>
 #include <asm/fpumacro.h>
 
+static kmem_cache_t *task_struct_cachep;
+
 /* #define VERBOSE_SHOWREGS */
 
 #ifndef CONFIG_SMP
@@ -398,7 +400,50 @@
 	return ret;
 }
 
-/* Free current thread data structures etc.. */
+/*
+ * allocate and free task and thread data structures etc..
+ */
+void __init init_task_struct_cache(void)
+{
+	/* create a slab on which task_structs can be allocated */
+	task_struct_cachep =
+		kmem_cache_create("task_struct",
+				  sizeof(struct task_struct),0,
+				  SLAB_HWCACHE_ALIGN, NULL, NULL);
+	if (!task_struct_cachep)
+		panic("fork_init(): cannot create task_struct SLAB cache");
+
+}
+
+struct task_struct *dup_task_struct(struct task_struct *orig)
+{
+	struct task_struct *tsk;
+	struct thread_info *ti;
+
+	ti = alloc_thread_info();
+	if (!ti) return NULL;
+
+	tsk = kmem_cache_alloc(task_struct_cachep,GFP_ATOMIC);
+	if (!tsk) {
+		free_thread_info(ti);
+		return NULL;
+	}
+
+	*ti = *orig->thread_info;
+	*tsk = *orig;
+	tsk->thread_info = ti;
+	ti->task = tsk;
+	atomic_set(&tsk->usage,1);
+
+	return tsk;
+}
+
+void __put_task_struct(struct task_struct *tsk)
+{
+	free_thread_info(tsk->thread_info);
+	kmem_cache_free(task_struct_cachep,tsk);
+}
+
 void exit_thread(void)
 {
 	struct thread_info *t = current_thread_info();
diff -uNr linux-2.5.5-pre1/include/asm-i386/processor.h linux-tib-255p1/include/asm-i386/processor.h
--- linux-2.5.5-pre1/include/asm-i386/processor.h	Thu Feb 14 14:31:18 2002
+++ linux-tib-255p1/include/asm-i386/processor.h	Thu Feb 14 14:38:55 2002
@@ -425,6 +425,11 @@
 struct task_struct;
 struct mm_struct;
 
+/* task structure allocation */
+extern void init_task_struct_cache(void);
+extern struct task_struct *dup_task_struct(struct task_struct *orig);
+extern void __put_task_struct(struct task_struct *tsk);
+
 /* Free all resources held by a thread. */
 extern void release_thread(struct task_struct *);
 /*
diff -uNr linux-2.5.5-pre1/include/asm-sparc64/processor.h linux-tib-255p1/include/asm-sparc64/processor.h
--- linux-2.5.5-pre1/include/asm-sparc64/processor.h	Thu Feb 14 14:03:47 2002
+++ linux-tib-255p1/include/asm-sparc64/processor.h	Thu Feb 14 14:34:38 2002
@@ -175,6 +175,11 @@
 #define copy_segments(tsk, mm)		do { } while (0)
 #define release_segments(mm)		do { } while (0)
 
+/* task structure allocation */
+extern void init_task_struct_cache(void);
+extern struct task_struct *dup_task_struct(struct task_struct *orig);
+extern void __put_task_struct(struct task_struct *tsk);
+
 #define get_wchan(__TSK) \
 ({	extern void scheduling_functions_start_here(void); \
 	extern void scheduling_functions_end_here(void); \
diff -uNr linux-2.5.5-pre1/kernel/fork.c linux-tib-255p1/kernel/fork.c
--- linux-2.5.5-pre1/kernel/fork.c	Thu Feb 14 14:31:19 2002
+++ linux-tib-255p1/kernel/fork.c	Thu Feb 14 14:32:40 2002
@@ -30,8 +30,6 @@
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
 
-static kmem_cache_t *task_struct_cachep;
-
 /* The idle threads do not count.. */
 int nr_threads;
 
@@ -74,13 +72,7 @@
 
 void __init fork_init(unsigned long mempages)
 {
-	/* create a slab on which task_structs can be allocated */
-	task_struct_cachep =
-		kmem_cache_create("task_struct",
-				  sizeof(struct task_struct),0,
-				  SLAB_HWCACHE_ALIGN, NULL, NULL);
-	if (!task_struct_cachep)
-		panic("fork_init(): cannot create task_struct SLAB cache");
+	init_task_struct_cache();
 
 	/*
 	 * The default maximum number of threads is set to a safe
@@ -93,35 +85,6 @@
 	init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
 }
 
-struct task_struct *dup_task_struct(struct task_struct *orig)
-{
-	struct task_struct *tsk;
-	struct thread_info *ti;
-
-	ti = alloc_thread_info();
-	if (!ti) return NULL;
-
-	tsk = kmem_cache_alloc(task_struct_cachep,GFP_ATOMIC);
-	if (!tsk) {
-		free_thread_info(ti);
-		return NULL;
-	}
-
-	*ti = *orig->thread_info;
-	*tsk = *orig;
-	tsk->thread_info = ti;
-	ti->task = tsk;
-	atomic_set(&tsk->usage,1);
-
-	return tsk;
-}
-
-void __put_task_struct(struct task_struct *tsk)
-{
-	free_thread_info(tsk->thread_info);
-	kmem_cache_free(task_struct_cachep,tsk);
-}
-
 /* Protects next_safe and last_pid. */
 spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED;
 


             reply	other threads:[~2002-02-14 15:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-14 15:26 David Howells [this message]
2002-02-14 16:13 ` [PATCH] move task_struct allocation to arch Jeff Garzik
2002-02-14 16:32   ` David Howells
2002-02-14 16:46     ` Jeff Garzik
2002-02-14 17:03       ` David Howells
2002-02-14 20:48         ` Roman Zippel
2002-02-14 23:53         ` Richard Henderson
2002-02-15  9:56         ` Jeff Garzik
2002-02-15 10:01           ` Jeff Garzik
2002-02-15 11:25           ` Roman Zippel
2002-02-15 11:37             ` David Howells
2002-02-15 12:20               ` Roman Zippel
2002-02-15 12:56                 ` David Howells
2002-02-15 13:49                   ` Roman Zippel
2002-02-15 13:51                     ` Jeff Garzik
2002-02-15 14:22                       ` Roman Zippel
2002-02-15 14:07                     ` David Howells
2002-02-15 14:28                       ` Roman Zippel
2002-02-15 21:56                       ` Richard Henderson
2002-02-15 21:52                   ` Richard Henderson

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=11830.1013700380@warthog.cambridge.redhat.com \
    --to=dhowells@redhat.com \
    --cc=anton@samba.org \
    --cc=davem@redhat.com \
    --cc=davidm@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=zippel@linux-m68k.org \
    /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