summaryrefslogtreecommitdiff
path: root/src/lib/libc
diff options
context:
space:
mode:
authorotto <>2018-01-18 20:06:16 +0000
committerotto <>2018-01-18 20:06:16 +0000
commit1d8e5453558fbe5e97fd1becfef826a261de138b (patch)
tree933a516d06567570ed43b303fa8dfdf5413926e6 /src/lib/libc
parent39f9d0d750f0517e592c2d361676578af5aeb0dd (diff)
downloadopenbsd-1d8e5453558fbe5e97fd1becfef826a261de138b.tar.gz
openbsd-1d8e5453558fbe5e97fd1becfef826a261de138b.tar.bz2
openbsd-1d8e5453558fbe5e97fd1becfef826a261de138b.zip
Zap the rotor, it was a wrong idea. Cluebat applied by kshe who
came also up with this diff. Simple, no bias and benchmarks show the extra random calls disappear in te measurement noise.
Diffstat (limited to 'src/lib/libc')
-rw-r--r--src/lib/libc/stdlib/malloc.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index 40c602a1ae..97d77b0a63 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.240 2018/01/18 08:37:28 otto Exp $ */ 1/* $OpenBSD: malloc.c,v 1.241 2018/01/18 20:06:16 otto Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -172,7 +172,6 @@ struct chunk_info {
172 u_short free; /* how many free chunks */ 172 u_short free; /* how many free chunks */
173 u_short total; /* how many chunks */ 173 u_short total; /* how many chunks */
174 u_short offset; /* requested size table offset */ 174 u_short offset; /* requested size table offset */
175 u_short rotor; /* randomization rotor */
176 u_short bits[1]; /* which chunks are free */ 175 u_short bits[1]; /* which chunks are free */
177}; 176};
178 177
@@ -941,7 +940,7 @@ malloc_bytes(struct dir_info *d, size_t size, void *f)
941 940
942 j = find_chunksize(size); 941 j = find_chunksize(size);
943 942
944 r = getrbyte(d); 943 r = ((u_int)getrbyte(d) << 8) | getrbyte(d);
945 listnum = r % MALLOC_CHUNK_LISTS; 944 listnum = r % MALLOC_CHUNK_LISTS;
946 /* If it's empty, make a page more of that size chunks */ 945 /* If it's empty, make a page more of that size chunks */
947 if ((bp = LIST_FIRST(&d->chunk_dir[j][listnum])) == NULL) { 946 if ((bp = LIST_FIRST(&d->chunk_dir[j][listnum])) == NULL) {
@@ -953,9 +952,7 @@ malloc_bytes(struct dir_info *d, size_t size, void *f)
953 if (bp->canary != (u_short)d->canary1) 952 if (bp->canary != (u_short)d->canary1)
954 wrterror(d, "chunk info corrupted"); 953 wrterror(d, "chunk info corrupted");
955 954
956 if (bp->free > 1) 955 i = (r / MALLOC_CHUNK_LISTS) & (bp->total - 1);
957 bp->rotor += r;
958 i = bp->rotor++ & (bp->total - 1);
959 956
960 /* start somewhere in a short */ 957 /* start somewhere in a short */
961 lp = &bp->bits[i / MALLOC_BITS]; 958 lp = &bp->bits[i / MALLOC_BITS];