From 23e13b2e9bd30dab0a774edef0d3b1b8b4059a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 21 Aug 2005 12:20:43 +0000 Subject: [PATCH] The number of semaphores available is now computed based on the amount of memory. Just like on BeOS, the overall maximum is 65536 semaphores for now - the mechanism tends to make more semaphores available than the one under BeOS, though (which is intended). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14035 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/sem.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/sem.c b/src/system/kernel/sem.c index b623c1cac8..9f841cedd7 100644 --- a/src/system/kernel/sem.c +++ b/src/system/kernel/sem.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -57,8 +58,9 @@ struct sem_entry { } u; }; -// ToDo: Compute based on the amount of available memory. +static const int32 kMaxSemaphores = 65536; static int32 sMaxSems = 4096; + // Final value is computed based on the amount of available memory static int32 sUsedSems = 0; static struct sem_entry *sSems = NULL; @@ -204,9 +206,18 @@ sem_init(kernel_args *args) TRACE(("sem_init: entry\n")); + // compute maximal number of semaphores depending on the available memory + // 128 MB -> 16384 semaphores, 448 kB fixed array size + // 256 MB -> 32768, 896 kB + // 512 MB and more -> 1.75 MB + i = vm_page_num_pages() / 2; + while (sMaxSems < i && sMaxSems < kMaxSemaphores) + sMaxSems <<= 1; + // create and initialize semaphore table area = create_area("sem_table", (void **)&sSems, B_ANY_KERNEL_ADDRESS, - sizeof(struct sem_entry) * sMaxSems, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + sizeof(struct sem_entry) * sMaxSems, B_FULL_LOCK, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (area < 0) panic("unable to allocate semaphore table!\n");