Commit graph

1712 commits

Author SHA1 Message Date
Carl Shapiro
68a3f40663 Separate out the configuration code from initialization 2026-03-10 16:04:56 -07:00
Carl Shapiro
1652fec1b4 Handle tcache init failures gracefully
tsd_tcache_data_init() returns true on failure but its callers ignore
this return value, leaving the per-thread tcache in an uninitialized
state after a failure.

This change disables the tcache on an initialization failure and logs
an error message.  If opt_abort is true, it will also abort.

New unit tests have been added to test tcache initialization failures.
2026-03-10 16:04:56 -07:00
Carl Shapiro
bfc2f89896 Move bin inline functions from arena_inlines_b.h to bin_inlines.h
This is a continuation of my previous clean-up change, now focusing on
the inline functions defined in header files.
2026-03-10 16:04:56 -07:00
Carl Shapiro
f07cc1a59e Move bin functions from arena.c to bin.c
This is a clean-up change that gives the bin functions implemented in
the area code a prefix of bin_ and moves them into the bin code.

To further decouple the bin code from the arena code, bin functions
that had taken an arena_t to check arena_is_auto now take an is_auto
parameter instead.
2026-03-10 16:04:56 -07:00
Slobodan Predolac
fbcec8b245 Remove prof_threshold built-in event. It is trivial to implement it as user event if needed 2026-02-25 09:06:29 -08:00
Slobodan Predolac
82c8f18b3d Revert "Experimental configuration option for fast path prefetch from cache_bin"
This reverts commit f9fae9f1f8.
2026-02-06 15:30:27 -08:00
Slobodan Predolac
2cc2339d82 [SEC] Make SEC owned by hpa_shard, simplify the code, add stats, lock per bin 2025-12-19 12:51:26 -05:00
Slobodan Predolac
c8b6f9e223 [EASY] Extract hpa_central component from hpa source file 2025-12-02 13:20:18 -08:00
Slobodan Predolac
0507f6dacc [EASY] Encapsulate better, do not pass hpa_shard when hooks are enough, move shard independent actions to hpa_utils 2025-12-02 13:20:18 -08:00
Slobodan Predolac
76d6771770 Add experimental_enforce_hugify 2025-11-21 11:30:16 -08:00
Shirui Cheng
b8ad7eba63 move fill/flush pointer array out of tcache.c 2025-11-02 13:46:00 -08:00
Slobodan Predolac
477573ce36 When extracting from central, hugify_eager is different than start_as_huge 2025-10-15 20:27:35 -04:00
guangli-dai
cef95f5d5c Refactor init_system_thp_mode and print it in malloc stats. 2025-10-13 16:56:12 -07:00
Slobodan Predolac
a8742091f3 [EASY] Spelling in the comments 2025-10-07 14:52:13 -07:00
Slobodan Predolac
97d610044c [HPA] Add ability to start page as huge and more flexibility for purging 2025-10-06 10:59:43 -04:00
Slobodan Predolac
8ce81ac2f7 Revert "Do not dehugify when purging"
This reverts commit 16c5abd1cd.
2025-10-06 10:59:43 -04:00
Slobodan Predolac
101513b526 Remove pidfd_open call handling and rely on PIDFD_SELF 2025-08-27 12:44:45 -04:00
Slobodan Predolac
458db0ea28 [EASY][BUGFIX] Spelling and format 2025-08-23 21:47:21 -07:00
lexprfuncall
f4b86c4cca Define malloc_{write,read}_fd as non-inline global functions
The static inline definition made more sense when these functions just
dispatched to a syscall wrapper.  Since they acquired a retry loop, a
non-inline definition makes more sense.
2025-08-23 11:42:23 -04:00
lexprfuncall
405661052f Handle interruptions and retries of read(2) and write(2) 2025-08-23 11:42:23 -04:00
Shirui Cheng
f7232fc1de Revert PR #2608: Manually revert commits 70c94d..f9c0b5
Closes: #2707
2025-08-22 21:55:24 -07:00
Slobodan Predolac
c4844e9613 Experimental configuration option for fast path prefetch from cache_bin 2025-08-15 16:06:08 -07:00
lexprfuncall
e98a99db06 Do not dehugify when purging
Giving the advice MADV_DONTNEED to a range of virtual memory backed by
a transparent huge page already causes that range of virtual memory to
become backed by regular pages.
2025-08-13 18:31:50 -07:00
Slobodan Predolac
2c655f83fc [process_madvise] Make init lazy so that python tests pass. Reset the pidfd on fork 2025-07-29 15:47:53 -07:00
Slobodan Predolac
320e83681a Add experimental support for usdt systemtap probes 2025-06-26 13:16:04 -07:00
guangli-dai
f1bba4a87c Reformat the codebase with the clang-format 18. 2025-06-20 14:35:15 -07:00
Shirui Cheng
0a6215c171 Update the default value for opt_experimental_tcache_gc and opt_calloc_madvise_threshold 2025-06-17 13:25:20 -07:00
Slobodan Predolac
390e70c840 [thread_event] Add support for user events in thread events when stats are enabled 2025-06-11 15:37:03 -07:00
Slobodan Predolac
b2a35a905f [thread_event] Remove macros from thread_event and replace with dynamic event objects 2025-06-11 15:37:03 -07:00
Jason Evans
27d7960cf9 Revert "Extend purging algorithm with peak demand tracking"
This reverts commit ad108d50f1.
2025-06-02 10:44:37 -07:00
guangli-dai
edaab8b3ad Turn clang-format off for codes with multi-line commands in macros 2025-05-28 19:22:21 -07:00
guangli-dai
fd60645260 Add one more check to double free validation. 2025-05-28 19:21:49 -07:00
Xin Yang
5e460bfea2 Refactor: use the cache_bin_sz_t typedef instead of direct uint16_t
any future changes to the underlying data type for bin sizes
(such as upgrading from `uint16_t` to `uint32_t`) can be achieved
by modifying only the `cache_bin_sz_t` definition.

Signed-off-by: Xin Yang <yangxin.dev@bytedance.com>
2025-05-22 10:43:33 -07:00
Xin Yang
9169e9272a Fix: Adjust CACHE_BIN_NFLUSH_BATCH_MAX size to prevent assert failures
The maximum allowed value for `nflush_batch` is
`CACHE_BIN_NFLUSH_BATCH_MAX`. However, `tcache_bin_flush_impl_small`
could potentially declare an array of `emap_batch_lookup_result_t`
of size `CACHE_BIN_NFLUSH_BATCH_MAX + 1`. leads to a `VARIABLE_ARRAY`
assertion failure, observed when `tcache_nslots_small_max` is
configured to 2048. This patch ensures the array size does not exceed
the allowed maximum.

Signed-off-by: Xin Yang <yangxin.dev@bytedance.com>
2025-05-22 10:27:09 -07:00
guangli-dai
37bf846cc3 Fixes to prevent static analysis warnings. 2025-05-06 14:47:35 -07:00
guangli-dai
8347f1045a Renaming limit_usize_gap to disable_large_size_classes 2025-05-06 14:47:35 -07:00
Guangli Dai
01e9ecbeb2 Remove build-time configuration 'config_limit_usize_gap' 2025-05-06 14:47:35 -07:00
Slobodan Predolac
852da1be15 Add experimental option force using SYS_process_madvise 2025-04-28 18:45:30 -07:00
Slobodan Predolac
1956a54a43 [process_madvise] Use process_madvise across multiple huge_pages 2025-04-25 19:19:03 -07:00
Slobodan Predolac
0dfb4a5a1a Add output argument to hpa_purge_begin to count dirty ranges 2025-04-25 19:19:03 -07:00
Slobodan Predolac
cfa90dfd80 Refactor hpa purging to prepare for vectorized call across multiple pages 2025-04-25 19:19:03 -07:00
guangli-dai
c20a63a765 Silence the uninitialized warning from clang. 2025-04-16 10:38:10 -07:00
Slobodan Predolac
f19f49ef3e if process_madvise is supported, call it when purging hpa 2025-04-04 13:57:42 -07:00
Kaspar M. Rohrer
80e9001af3 Move `extern "C" specifications for C++ to where they are needed
This should fix errors when compiling C++ code with modules enabled on clang.
2025-03-31 10:41:51 -07:00
Shirui Cheng
3688dfb5c3 fix assertion error in huge_arena_auto_thp_switch() when b0 is deleted in unit test 2025-03-20 12:45:23 -07:00
Shirui Cheng
e1a77ec558 Support THP with Huge Arena in PAC 2025-03-17 16:06:43 -07:00
Guangli Dai
773b5809f9 Fix frame pointer based unwinder to handle changing stack range 2025-03-13 17:15:42 -07:00
Dmitry Ilvokhin
ad108d50f1 Extend purging algorithm with peak demand tracking
Implementation inspired by idea described in "Beyond malloc efficiency
to fleet efficiency: a hugepage-aware memory allocator" paper [1].

Primary idea is to track maximum number (peak) of active pages in use
with sliding window and then use this number to decide how many dirty
pages we would like to keep.

We are trying to estimate maximum amount of active memory we'll need in
the near future. We do so by projecting future active memory demand
(based on peak active memory usage we observed in the past within
sliding window) and adding slack on top of it (an overhead is reasonable
to have in exchange of higher hugepages coverage). When peak demand
tracking is off, projection of future active memory is active memory we
are having right now.

Estimation is essentially the same as `nactive_max * (1 + dirty_mult)`.

Peak demand purging algorithm controlled by two config options. Option
`hpa_peak_demand_window_ms` controls duration of sliding window we track
maximum active memory usage in and option `hpa_dirty_mult` controls
amount of slack we are allowed to have as a percent from maximum active
memory usage. By default `hpa_peak_demand_window_ms == 0` now and we
have same behaviour (ratio based purging) that we had before this
commit.

[1]: https://storage.googleapis.com/gweb-research2023-media/pubtools/6170.pdf
2025-03-13 10:12:22 -07:00
Qi Wang
22440a0207 Implement process_madvise support.
Add opt.process_madvise_max_batch which determines if process_madvise is enabled
(non-zero) and the max # of regions in each batch.  Added another limiting
factor which is the space to reserve on stack, which results in the max batch of
128.
2025-03-07 15:32:32 -08:00
Guangli Dai
6035d4a8d3 Cache extra extents in the dirty pool from ecache_alloc_grow 2025-03-06 15:08:13 -08:00