summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorotto <>2023-05-10 07:58:06 +0000
committerotto <>2023-05-10 07:58:06 +0000
commit11d060ebfebf1118b35368fbf7d74f0777c8086e (patch)
tree0a07aa503d5da080782cc75f8016e831cbb37b47
parent4172ef82dd12eeda3308828629cdfb83b39b96cf (diff)
downloadopenbsd-11d060ebfebf1118b35368fbf7d74f0777c8086e.tar.gz
openbsd-11d060ebfebf1118b35368fbf7d74f0777c8086e.tar.bz2
openbsd-11d060ebfebf1118b35368fbf7d74f0777c8086e.zip
As mmap(2) is no longer a LOCK syscall, do away with the extra
unlock-lock dance it serves no real purpose any more. Confirmed by a small performance increase in tests. ok @tb
-rw-r--r--src/lib/libc/stdlib/malloc.c24
1 files changed, 1 insertions, 23 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index 5cd7ff876a..a6728b2606 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: malloc.c,v 1.282 2023/04/21 06:19:40 jsg Exp $ */ 1/* $OpenBSD: malloc.c,v 1.283 2023/05/10 07:58:06 otto Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -264,24 +264,6 @@ static void malloc_exit(void);
264 (sz) = (uintptr_t)(r)->p & MALLOC_PAGEMASK, \ 264 (sz) = (uintptr_t)(r)->p & MALLOC_PAGEMASK, \
265 (sz) = ((sz) == 0 ? (r)->size : B2SIZE((sz) - 1)) 265 (sz) = ((sz) == 0 ? (r)->size : B2SIZE((sz) - 1))
266 266
267static inline void
268_MALLOC_LEAVE(struct dir_info *d)
269{
270 if (d->malloc_mt) {
271 d->active--;
272 _MALLOC_UNLOCK(d->mutex);
273 }
274}
275
276static inline void
277_MALLOC_ENTER(struct dir_info *d)
278{
279 if (d->malloc_mt) {
280 _MALLOC_LOCK(d->mutex);
281 d->active++;
282 }
283}
284
285static inline size_t 267static inline size_t
286hash(void *p) 268hash(void *p)
287{ 269{
@@ -879,9 +861,7 @@ map(struct dir_info *d, size_t sz, int zero_fill)
879 return p; 861 return p;
880 } 862 }
881 if (psz <= 1) { 863 if (psz <= 1) {
882 _MALLOC_LEAVE(d);
883 p = MMAP(cache->max * sz, d->mmap_flag); 864 p = MMAP(cache->max * sz, d->mmap_flag);
884 _MALLOC_ENTER(d);
885 if (p != MAP_FAILED) { 865 if (p != MAP_FAILED) {
886 STATS_ADD(d->malloc_used, cache->max * sz); 866 STATS_ADD(d->malloc_used, cache->max * sz);
887 cache->length = cache->max - 1; 867 cache->length = cache->max - 1;
@@ -901,9 +881,7 @@ map(struct dir_info *d, size_t sz, int zero_fill)
901 } 881 }
902 882
903 } 883 }
904 _MALLOC_LEAVE(d);
905 p = MMAP(sz, d->mmap_flag); 884 p = MMAP(sz, d->mmap_flag);
906 _MALLOC_ENTER(d);
907 if (p != MAP_FAILED) 885 if (p != MAP_FAILED)
908 STATS_ADD(d->malloc_used, sz); 886 STATS_ADD(d->malloc_used, sz);
909 /* zero fill not needed */ 887 /* zero fill not needed */