summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thread.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2009-09-01 11:41:51 +0000
committerkib <kib@FreeBSD.org>2009-09-01 11:41:51 +0000
commitbae5df8cbb88dd3a3930f1c4f5281e1782961a36 (patch)
treecba3987f868648d34d432849ac13b04378d79b4c /sys/kern/kern_thread.c
parentce36458bc885a611a3164145f2e49ae15cfa896a (diff)
downloadFreeBSD-src-bae5df8cbb88dd3a3930f1c4f5281e1782961a36.zip
FreeBSD-src-bae5df8cbb88dd3a3930f1c4f5281e1782961a36.tar.gz
Reintroduce the r196640, after fixing the problem with my testing.
Remove the altkstacks, instead instantiate threads with kernel stack allocated with the right size from the start. For the thread that has kernel stack cached, verify that requested stack size is equial to the actual, and reallocate the stack if sizes differ [1]. This fixes the bug introduced by r173361 that was committed several days after r173004 and consisted of kthread_add(9) ignoring the non-default kernel stack size. Also, r173361 removed the caching of the kernel stacks for a non-first thread in the process. Introduce separate kernel stack cache that keeps some limited amount of preallocated kernel stacks to lower the latency of thread allocation. Add vm_lowmem handler to prune the cache on low memory condition. This way, system with reasonable amount of the threads get lower latency of thread creation, while still not exhausting significant portion of KVA for unused kstacks. Submitted by: peter [1] Discussed with: jhb, julian, peter Reviewed by: jhb Tested by: pho (and retested according to new test scenarious) MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_thread.c')
-rw-r--r--sys/kern/kern_thread.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index d47bd8c..4f3b32c 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -283,7 +283,7 @@ thread_reap(void)
* Allocate a thread.
*/
struct thread *
-thread_alloc(void)
+thread_alloc(int pages)
{
struct thread *td;
@@ -291,7 +291,7 @@ thread_alloc(void)
td = (struct thread *)uma_zalloc(thread_zone, M_WAITOK);
KASSERT(td->td_kstack == 0, ("thread_alloc got thread with kstack"));
- if (!vm_thread_new(td, 0)) {
+ if (!vm_thread_new(td, pages)) {
uma_zfree(thread_zone, td);
return (NULL);
}
@@ -299,6 +299,17 @@ thread_alloc(void)
return (td);
}
+int
+thread_alloc_stack(struct thread *td, int pages)
+{
+
+ KASSERT(td->td_kstack == 0,
+ ("thread_alloc_stack called on a thread with kstack"));
+ if (!vm_thread_new(td, pages))
+ return (0);
+ cpu_thread_alloc(td);
+ return (1);
+}
/*
* Deallocate a thread.
@@ -312,8 +323,6 @@ thread_free(struct thread *td)
cpuset_rel(td->td_cpuset);
td->td_cpuset = NULL;
cpu_thread_free(td);
- if (td->td_altkstack != 0)
- vm_thread_dispose_altkstack(td);
if (td->td_kstack != 0)
vm_thread_dispose(td);
uma_zfree(thread_zone, td);
OpenPOWER on IntegriCloud