jemalloc/src
gnzlbg 08260a6b94 Add experimental API: smallocx_return_t smallocx(size, flags)
---

Motivation:

This new experimental memory-allocaction API returns a pointer to
the allocation as well as the usable size of the allocated memory
region.

The `s` in `smallocx` stands for `sized`-`mallocx`, attempting to
convey that this API returns the size of the allocated memory region.

It should allow C++ P0901r0 [0] and Rust Alloc::alloc_excess to make
use of it.

The main purpose of these APIs is to improve telemetry. It is more accurate
to register `smallocx(size, flags)` than `smallocx(nallocx(size), flags)`,
for example. The latter will always line up perfectly with the existing
size classes, causing a loss of telemetry information about the internal
fragmentation induced by potentially poor size-classes choices.

Instrumenting `nallocx` does not help much since user code can cache its
result and use it repeatedly.

---

Implementation:

The implementation adds a new `usize` option to `static_opts_s` and an `usize`
variable to `dynamic_opts_s`. These are then used to cache the result of
`sz_index2size` and similar functions in the code paths in which they are
unconditionally invoked. In the code-paths in which these functions are not
unconditionally invoked, `smallocx` calls, as opposed to `mallocx`, these
functions explicitly.

---

[0]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0901r0.html
2018-10-17 07:12:28 -07:00
..
arena.c Add stats for the size of extent_avail heap 2018-08-02 10:16:06 -07:00
background_thread.c Clean compilation -Wextra 2018-07-09 21:40:42 -07:00
base.c SC: Remove global data. 2018-07-23 13:37:08 -07:00
bin.c Hide size class computation behind a layer of indirection. 2018-07-12 20:53:06 -07:00
bitmap.c Revert "Remove BITMAP_USE_TREE." 2017-04-18 19:01:04 -07:00
ckh.c SC: Make some key size classes static. 2018-07-12 20:53:06 -07:00
ctl.c Add stats for the size of extent_avail heap 2018-08-02 10:16:06 -07:00
div.c Add the div module, which allows fast division by dynamic values. 2017-12-21 14:25:43 -08:00
extent.c Add stats for the size of extent_avail heap 2018-08-02 10:16:06 -07:00
extent_dss.c Hide size class computation behind a layer of indirection. 2018-07-12 20:53:06 -07:00
extent_mmap.c Header refactoring: unify and de-catchall extent_mmap module. 2017-05-31 13:08:45 -07:00
hash.c Header refactoring: Split up jemalloc_internal.h 2017-04-11 11:52:30 -07:00
hook.c Move tsd link and in_hook after tcache. 2018-06-27 13:39:02 -07:00
jemalloc.c Add experimental API: smallocx_return_t smallocx(size, flags) 2018-10-17 07:12:28 -07:00
jemalloc_cpp.cpp Split out cold code path in newImpl 2017-07-24 13:37:02 -07:00
large.c Add logging for sampled allocations 2018-08-01 13:27:11 -07:00
log.c Logging: allow logging with empty varargs. 2017-07-22 09:38:19 -07:00
malloc_io.c Fix type warning on Windows. 2018-04-09 16:50:30 -07:00
mutex.c Clean compilation -Wextra 2018-07-09 21:40:42 -07:00
mutex_pool.c Header refactoring: unify and de-catchall mutex_pool. 2017-05-31 13:08:45 -07:00
nstime.c Add background thread related stats. 2017-05-23 12:26:20 -07:00
pages.c check return value of malloc_read_fd 2018-10-11 17:25:20 -07:00
prng.c Header refactoring: Split up jemalloc_internal.h 2017-04-11 11:52:30 -07:00
prof.c restrict bytes_until_sample to int64_t. This allows optimal asm 2018-10-15 08:24:12 -07:00
rtree.c Clean compilation -Wextra 2018-07-09 21:40:42 -07:00
sc.c add a check for SC_LARGE_MAXCLASS 2018-10-15 08:24:12 -07:00
stats.c Add stats for the size of extent_avail heap 2018-08-02 10:16:06 -07:00
sz.c SC: Remove global data. 2018-07-23 13:37:08 -07:00
tcache.c SC: Make some key size classes static. 2018-07-12 20:53:06 -07:00
test_hooks.c Rename hooks module to test_hooks. 2018-05-18 11:43:03 -07:00
ticker.c Header refactoring: Split up jemalloc_internal.h 2017-04-11 11:52:30 -07:00
tsd.c remove malloc_init() off the fastpath 2018-10-15 10:11:08 -07:00
witness.c Header refactoring: unify and de-catchall witness code. 2017-05-24 15:27:30 -07:00
zone.c Fix deadlock in multithreaded fork in OS X. 2017-07-10 18:17:12 -07:00