Skip to content

Commit 2058d49

Browse files
authored
Merge pull request DeusData#2202 from DeusData/feat/memory-core
feat(mem): a central allocation core, the memory migrated onto it, and results spilled to disk under budget
2 parents 339b3f4 + d70b794 commit 2058d49

61 files changed

Lines changed: 5745 additions & 807 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile.cbm‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ FOUNDATION_SRCS = \
248248
src/foundation/compat_fs.c \
249249
src/foundation/compat_regex.c \
250250
src/foundation/mem.c \
251+
src/foundation/mem_core.c \
251252
src/foundation/diagnostics.c \
252253
src/foundation/profile.c \
253254
src/foundation/dump_verify.c \
@@ -275,6 +276,8 @@ EXTRACTION_SRCS = \
275276
$(CBM_DIR)/extract_k8s.c \
276277
$(CBM_DIR)/extract_dbt.c \
277278
$(CBM_DIR)/helpers.c \
279+
$(CBM_DIR)/result_compact.c \
280+
$(CBM_DIR)/result_spill.c \
278281
$(CBM_DIR)/lang_specs.c \
279282
$(CBM_DIR)/macro_table.c \
280283
$(CBM_DIR)/iris_export_xml.c \
@@ -1188,8 +1191,17 @@ lint-no-suppress:
11881191
lint: lint-tidy lint-cppcheck lint-format lint-no-suppress
11891192
@echo "=== All linters passed ==="
11901193

1194+
# Memory-core linter: memory is allocated through src/foundation/mem_core.h,
1195+
# not through raw malloc/calloc/realloc/free/strdup. A checked-in baseline
1196+
# (scripts/memory-core-baseline.txt) records each file's raw-site count and the
1197+
# gate goes red the moment any file grows. Files only ever go down; lower the
1198+
# baseline line in the same change that migrates the file.
1199+
lint-memory-core:
1200+
@echo "=== memory-core linter ==="
1201+
@python3 scripts/lint-memory-core.py
1202+
11911203
# CI linters (no clang-tidy — platform-dependent, enforced locally via pre-commit)
1192-
lint-ci: lint-cppcheck lint-format lint-no-suppress
1204+
lint-ci: lint-cppcheck lint-format lint-no-suppress lint-memory-core
11931205
@echo "=== CI linters passed ==="
11941206

11951207
# ── Local memory-diagnostic lanes (not PR-CI gates by decision: the diag

‎internal/cbm/arena.h‎

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,7 @@
1-
#ifndef CBM_ARENA_H
2-
#define CBM_ARENA_H
3-
4-
#include <stddef.h>
5-
6-
// CBMArena is a simple bump allocator that allocates from fixed-size blocks.
7-
// All memory is freed at once via cbm_arena_destroy(). Individual frees are not
8-
// supported — this is by design for per-file extraction where all data has the
9-
// same lifetime.
10-
#define CBM_ARENA_MAX_BLOCKS 256
11-
#define CBM_ARENA_DEFAULT_BLOCK_SIZE (64 * 1024) // 64KB initial
12-
13-
typedef struct {
14-
char *blocks[CBM_ARENA_MAX_BLOCKS];
15-
size_t block_sizes[CBM_ARENA_MAX_BLOCKS]; // per-block sizes (for stats)
16-
int nblocks;
17-
size_t block_size;
18-
size_t used; // bytes used in current block
19-
size_t total_alloc; // cumulative bytes allocated (for stats)
20-
} CBMArena;
21-
22-
// Initialize an arena with the default block size.
23-
void cbm_arena_init(CBMArena *a);
24-
25-
// Allocate n bytes from the arena. Returns NULL on OOM or block exhaustion.
26-
// All returned pointers are 8-byte aligned.
27-
void *cbm_arena_alloc(CBMArena *a, size_t n);
28-
29-
// Duplicate a string into arena memory. Returns arena-owned copy.
30-
char *cbm_arena_strdup(CBMArena *a, const char *s);
31-
32-
// Duplicate a string of known length into arena memory. NUL-terminates.
33-
char *cbm_arena_strndup(CBMArena *a, const char *s, size_t len);
34-
35-
// sprintf into arena memory. Returns arena-owned string.
36-
char *cbm_arena_sprintf(CBMArena *a, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
37-
38-
// Free all blocks. Arena is invalid after this call.
39-
void cbm_arena_destroy(CBMArena *a);
40-
41-
#endif // CBM_ARENA_H
1+
/* The arena lives in src/foundation/arena.h. This file used to be a stale
2+
* copy with the same include guard and a shorter API; whichever header a
3+
* translation unit included first won, silently. One definition now. */
4+
#ifndef CBM_INTERNAL_ARENA_SHIM_H
5+
#define CBM_INTERNAL_ARENA_SHIM_H
6+
#include "../../src/foundation/arena.h" /* relative: the lsp_all unit has no -Isrc */
7+
#endif /* CBM_INTERNAL_ARENA_SHIM_H */

0 commit comments

Comments
 (0)