MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sz_sa2u

Function sz_sa2u

deps/jemalloc/include/jemalloc/internal/sz.h:262–316  ·  view source on GitHub ↗

* Compute usable size that would result from allocating an object with the * specified size and alignment. */

Source from the content-addressed store, hash-verified

260 * specified size and alignment.
261 */
262JEMALLOC_ALWAYS_INLINE size_t
263sz_sa2u(size_t size, size_t alignment) {
264 size_t usize;
265
266 assert(alignment != 0 && ((alignment - 1) & alignment) == 0);
267
268 /* Try for a small size class. */
269 if (size <= SC_SMALL_MAXCLASS && alignment < PAGE) {
270 /*
271 * Round size up to the nearest multiple of alignment.
272 *
273 * This done, we can take advantage of the fact that for each
274 * small size class, every object is aligned at the smallest
275 * power of two that is non-zero in the base two representation
276 * of the size. For example:
277 *
278 * Size | Base 2 | Minimum alignment
279 * -----+----------+------------------
280 * 96 | 1100000 | 32
281 * 144 | 10100000 | 32
282 * 192 | 11000000 | 64
283 */
284 usize = sz_s2u(ALIGNMENT_CEILING(size, alignment));
285 if (usize < SC_LARGE_MINCLASS) {
286 return usize;
287 }
288 }
289
290 /* Large size class. Beware of overflow. */
291
292 if (unlikely(alignment > SC_LARGE_MAXCLASS)) {
293 return 0;
294 }
295
296 /* Make sure result is a large size class. */
297 if (size <= SC_LARGE_MINCLASS) {
298 usize = SC_LARGE_MINCLASS;
299 } else {
300 usize = sz_s2u(size);
301 if (usize < size) {
302 /* size_t overflow. */
303 return 0;
304 }
305 }
306
307 /*
308 * Calculate the multi-page mapping that large_palloc() would need in
309 * order to guarantee the alignment.
310 */
311 if (usize + sz_large_pad + PAGE_CEILING(alignment) - PAGE < usize) {
312 /* size_t overflow. */
313 return 0;
314 }
315 return usize;
316}
317
318#endif /* JEMALLOC_INTERNAL_SIZE_H */

Callers 14

ipallocztmFunction · 0.70
iralloct_realignFunction · 0.70
large_pallocFunction · 0.50
ckh_growFunction · 0.50
ckh_shrinkFunction · 0.50
ckh_newFunction · 0.50
imalloc_sampleFunction · 0.50
imalloc_bodyFunction · 0.50
jemalloc.cFile · 0.50
ixallocx_profFunction · 0.50
inallocxFunction · 0.50
tsd_tcache_data_initFunction · 0.50

Calls 1

sz_s2uFunction · 0.70

Tested by

no test coverage detected