[nginx] Slab: fixed small allocations on systems with large pagesize.
Ruslan Ermilov
ru at nginx.com
Tue Jul 4 15:37:09 UTC 2017
details: http://hg.nginx.org/nginx/rev/8c5e3cc21332
branches:
changeset: 7050:8c5e3cc21332
user: Ruslan Ermilov <ru at nginx.com>
date: Tue Jul 04 18:32:30 2017 +0300
description:
Slab: fixed small allocations on systems with large pagesize.
Notably, on ppc64 with 64k pagesize, slab 0 (of size 8) requires
128 64-bit elements for bitmasks. The code bogusly assumed that
one uintptr_t is enough for bitmasks plus at least one free slot.
diffstat:
src/core/ngx_slab.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diffs (42 lines):
diff -r 94f30939545a -r 8c5e3cc21332 src/core/ngx_slab.c
--- a/src/core/ngx_slab.c Tue Jul 04 18:32:28 2017 +0300
+++ b/src/core/ngx_slab.c Tue Jul 04 18:32:30 2017 +0300
@@ -339,11 +339,17 @@ ngx_slab_alloc_locked(ngx_slab_pool_t *p
}
/* "n" elements for bitmap, plus one requested */
- bitmap[0] = ((uintptr_t) 2 << n) - 1;
+
+ for (i = 0; i < (n + 1) / (8 * sizeof(uintptr_t)); i++) {
+ bitmap[i] = NGX_SLAB_BUSY;
+ }
+
+ m = ((uintptr_t) 1 << ((n + 1) % (8 * sizeof(uintptr_t)))) - 1;
+ bitmap[i] = m;
map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t));
- for (i = 1; i < map; i++) {
+ for (i = i + 1; i < map; i++) {
bitmap[i] = 0;
}
@@ -506,13 +512,16 @@ ngx_slab_free_locked(ngx_slab_pool_t *po
n = 1;
}
- if (bitmap[0] & ~(((uintptr_t) 1 << n) - 1)) {
+ i = n / (8 * sizeof(uintptr_t));
+ m = ((uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)))) - 1;
+
+ if (bitmap[i] & ~m) {
goto done;
}
map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t));
- for (i = 1; i < map; i++) {
+ for (i = i + 1; i < map; i++) {
if (bitmap[i]) {
goto done;
}
More information about the nginx-devel
mailing list