Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 14 Feb 2002 10:26:40 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 14 Feb 2002 10:26:32 -0500 Received: from dell-paw-3.cambridge.redhat.com ([195.224.55.237]:753 "HELO executor.cambridge.redhat.com") by vger.kernel.org with SMTP id ; Thu, 14 Feb 2002 10:26:23 -0500 To: torvalds@transmeta.com Cc: davidm@hpl.hp.com, "David S. Miller" , David Howells , anton@samba.org, linux-kernel@vger.kernel.org, zippel@linux-m68k.org Subject: [PATCH] move task_struct allocation to arch User-Agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (=?ISO-8859-4?Q?Unebigory=F2mae?=) APEL/10.3 Emacs/21.1 (i386-redhat-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Date: Thu, 14 Feb 2002 15:26:20 +0000 Message-ID: <11830.1013700380@warthog.cambridge.redhat.com> From: David Howells Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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 #include +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 #include -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; - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/