Mercurial > hg > nginx
comparison src/core/ngx_slab.c @ 7050:8c5e3cc21332
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.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 04 Jul 2017 18:32:30 +0300 |
parents | 94f30939545a |
children | 69f9ee0342db |
comparison
equal
deleted
inserted
replaced
7049:94f30939545a | 7050:8c5e3cc21332 |
---|---|
337 if (n == 0) { | 337 if (n == 0) { |
338 n = 1; | 338 n = 1; |
339 } | 339 } |
340 | 340 |
341 /* "n" elements for bitmap, plus one requested */ | 341 /* "n" elements for bitmap, plus one requested */ |
342 bitmap[0] = ((uintptr_t) 2 << n) - 1; | 342 |
343 for (i = 0; i < (n + 1) / (8 * sizeof(uintptr_t)); i++) { | |
344 bitmap[i] = NGX_SLAB_BUSY; | |
345 } | |
346 | |
347 m = ((uintptr_t) 1 << ((n + 1) % (8 * sizeof(uintptr_t)))) - 1; | |
348 bitmap[i] = m; | |
343 | 349 |
344 map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t)); | 350 map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t)); |
345 | 351 |
346 for (i = 1; i < map; i++) { | 352 for (i = i + 1; i < map; i++) { |
347 bitmap[i] = 0; | 353 bitmap[i] = 0; |
348 } | 354 } |
349 | 355 |
350 page->slab = shift; | 356 page->slab = shift; |
351 page->next = &slots[slot]; | 357 page->next = &slots[slot]; |
504 | 510 |
505 if (n == 0) { | 511 if (n == 0) { |
506 n = 1; | 512 n = 1; |
507 } | 513 } |
508 | 514 |
509 if (bitmap[0] & ~(((uintptr_t) 1 << n) - 1)) { | 515 i = n / (8 * sizeof(uintptr_t)); |
516 m = ((uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)))) - 1; | |
517 | |
518 if (bitmap[i] & ~m) { | |
510 goto done; | 519 goto done; |
511 } | 520 } |
512 | 521 |
513 map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t)); | 522 map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t)); |
514 | 523 |
515 for (i = 1; i < map; i++) { | 524 for (i = i + 1; i < map; i++) { |
516 if (bitmap[i]) { | 525 if (bitmap[i]) { |
517 goto done; | 526 goto done; |
518 } | 527 } |
519 } | 528 } |
520 | 529 |