From: Suresh Siddha <suresh.b.siddha@intel.com>
To: mingo@elte.hu, hpa@zytor.com, tglx@linutronix.de, andi@firstfloor.org
Cc: linux-kernel@vger.kernel.org,
Suresh Siddha <suresh.b.siddha@intel.com>,
Arjan van de Ven <arjan@linux.intel.com>
Subject: [patch 2/2] x86,fpu: lazy allocation of FPU area
Date: Sat, 23 Feb 2008 18:34:39 -0800 [thread overview]
Message-ID: <20080224023547.412501000@linux-os.sc.intel.com> (raw)
In-Reply-To: 20080224023547.264625000@linux-os.sc.intel.com
[-- Attachment #1: x86-lazy-fp-allocation.patch --]
[-- Type: text/plain, Size: 5837 bytes --]
Only allocate the FPU area when the application actually uses FPU, i.e., in the
first lazy FPU trap. This could save memory for non-fpu using apps.
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
---
Index: linux-2.6-x86/arch/x86/kernel/i387.c
===================================================================
--- linux-2.6-x86.orig/arch/x86/kernel/i387.c 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/arch/x86/kernel/i387.c 2008-02-23 18:27:41.000000000 -0800
@@ -9,7 +9,6 @@
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/regset.h>
-#include <linux/bootmem.h>
#include <asm/processor.h>
#include <asm/i387.h>
#include <asm/math_emu.h>
@@ -67,7 +66,6 @@
else
math_cntxt_size = sizeof(struct i387_fsave_struct);
#endif
- init_task.thread.cntxt = alloc_bootmem(math_cntxt_size);
}
#ifdef CONFIG_X86_64
@@ -105,6 +103,9 @@
return;
}
+ if (!tsk->thread.cntxt)
+ tsk->thread.cntxt = alloc_cntxt_struct();
+
if (cpu_has_fxsr) {
memset(FXSAVE(tsk), 0, math_cntxt_size);
FXSAVE(tsk)->cwd = 0x37f;
Index: linux-2.6-x86/arch/x86/kernel/process.c
===================================================================
--- linux-2.6-x86.orig/arch/x86/kernel/process.c 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/arch/x86/kernel/process.c 2008-02-23 18:27:49.000000000 -0800
@@ -8,21 +8,25 @@
static struct kmem_cache *task_struct_cachep;
static struct kmem_cache *task_cntxt_cachep;
-struct task_struct * alloc_task_struct(void)
+union thread_cntxt *alloc_cntxt_struct(void)
+{
+ return kmem_cache_alloc(task_cntxt_cachep, GFP_KERNEL);
+}
+
+struct task_struct * alloc_task_struct(struct task_struct *src)
{
struct task_struct *tsk;
tsk = kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
- if (!tsk)
- return NULL;
- tsk->thread.cntxt = kmem_cache_alloc(task_cntxt_cachep, GFP_KERNEL);
- if (!tsk->thread.cntxt)
- goto error;
- WARN_ON((unsigned long)tsk->thread.cntxt & 15);
+ if (tsk && src->thread.cntxt) {
+ tsk->thread.cntxt = alloc_cntxt_struct();
+ if (!tsk->thread.cntxt) {
+ kmem_cache_free(task_struct_cachep, tsk);
+ return NULL;
+ }
+ WARN_ON((unsigned long)tsk->thread.cntxt & 15);
+ } else if (tsk)
+ tsk->thread.cntxt = NULL;
return tsk;
-
-error:
- kmem_cache_free(task_struct_cachep, tsk);
- return NULL;
}
void memcpy_task_struct(struct task_struct *dst, struct task_struct *src)
@@ -31,13 +35,21 @@
ptr = dst->thread.cntxt;
*dst = *src;
dst->thread.cntxt = ptr;
- memcpy(dst->thread.cntxt, src->thread.cntxt, math_cntxt_size);
+ if (src->thread.cntxt)
+ memcpy(dst->thread.cntxt, src->thread.cntxt, math_cntxt_size);
+}
+
+void free_cntxt_struct(struct task_struct *tsk)
+{
+ if (tsk->thread.cntxt) {
+ kmem_cache_free(task_cntxt_cachep, tsk->thread.cntxt);
+ tsk->thread.cntxt = NULL;
+ }
}
void free_task_struct(struct task_struct *tsk)
{
- kmem_cache_free(task_cntxt_cachep, tsk->thread.cntxt);
- tsk->thread.cntxt=NULL;
+ free_cntxt_struct(tsk);
kmem_cache_free(task_struct_cachep, tsk);
}
Index: linux-2.6-x86/include/asm-x86/i387.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/i387.h 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/include/asm-x86/i387.h 2008-02-23 18:27:41.000000000 -0800
@@ -25,6 +25,7 @@
extern asmlinkage void math_state_restore(void);
extern void init_thread_context(void);
extern unsigned int math_cntxt_size;
+extern union thread_cntxt *alloc_cntxt_struct(void);
extern user_regset_active_fn fpregs_active, xfpregs_active;
extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get;
Index: linux-2.6-x86/include/asm-x86/processor.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/processor.h 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/include/asm-x86/processor.h 2008-02-23 18:27:41.000000000 -0800
@@ -743,6 +743,8 @@
.io_bitmap = { [0 ... IO_BITMAP_LONGS] = ~0 }, \
}
+extern void free_cntxt_struct(struct task_struct *);
+
#define start_thread(regs, new_eip, new_esp) do { \
__asm__("movl %0,%%gs": :"r" (0)); \
regs->fs = 0; \
@@ -753,6 +755,7 @@
regs->cs = __USER_CS; \
regs->ip = new_eip; \
regs->sp = new_esp; \
+ free_cntxt_struct(current); \
} while (0)
Index: linux-2.6-x86/include/asm-x86/thread_info.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/thread_info.h 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/include/asm-x86/thread_info.h 2008-02-23 18:27:41.000000000 -0800
@@ -6,7 +6,7 @@
#ifndef __ASSEMBLY__
#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
-extern struct task_struct * alloc_task_struct(void);
+extern struct task_struct * alloc_task_struct(struct task_struct *src);
extern void free_task_struct(struct task_struct *tsk);
extern void memcpy_task_struct(struct task_struct *dst, struct task_struct *src
);
Index: linux-2.6-x86/kernel/fork.c
===================================================================
--- linux-2.6-x86.orig/kernel/fork.c 2008-02-23 18:27:40.000000000 -0800
+++ linux-2.6-x86/kernel/fork.c 2008-02-23 18:27:41.000000000 -0800
@@ -85,7 +85,7 @@
}
#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
-# define alloc_task_struct() kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
+# define alloc_task_struct(src) kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
# define free_task_struct(tsk) kmem_cache_free(task_struct_cachep, (tsk))
# define memcpy_task_struct(dst, src) do { *dst = *src; } while (0)
static struct kmem_cache *task_struct_cachep;
@@ -174,7 +174,7 @@
prepare_to_copy(orig);
- tsk = alloc_task_struct();
+ tsk = alloc_task_struct(orig);
if (!tsk)
return NULL;
--
next prev parent reply other threads:[~2008-02-24 2:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-24 2:34 [patch 1/2] x86,fpu: split FPU state from task struct Suresh Siddha
2008-02-24 2:34 ` Suresh Siddha [this message]
2008-02-24 3:08 ` [patch 2/2] x86,fpu: lazy allocation of FPU area Christoph Hellwig
2008-02-24 12:20 ` Andi Kleen
2008-02-24 16:32 ` Siddha, Suresh B
2008-02-24 3:04 ` [patch 1/2] x86,fpu: split FPU state from task struct Christoph Hellwig
2008-02-24 7:22 ` Ingo Molnar
2008-02-24 16:30 ` Siddha, Suresh B
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=20080224023547.412501000@linux-os.sc.intel.com \
--to=suresh.b.siddha@intel.com \
--cc=andi@firstfloor.org \
--cc=arjan@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
/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.