Skip to content

Add bounded-time pool reset for static pools#21

Merged
jserv merged 1 commit intomasterfrom
pool-reset
Feb 9, 2026
Merged

Add bounded-time pool reset for static pools#21
jserv merged 1 commit intomasterfrom
pool-reset

Conversation

@jserv
Copy link
Copy Markdown
Collaborator

@jserv jserv commented Feb 9, 2026

Arena-style workloads (allocate many, discard all) currently require per-object tlsf_free() calls. tlsf_pool_reset() clears the FL/SL bitmaps, resets bin pointers to the sentinel, and reconstructs a single free block plus sentinel -- the same layout tlsf_pool_init() produces. Pools extended via tlsf_append_pool() retain their full expanded capacity across resets.

This also adds check_sentinel() after sentinel construction in tlsf_pool_init() for debug-mode invariant enforcement.


Summary by cubic

Add a bounded-time bulk reset for static TLSF pools to support arena-style “allocate many, discard all” workloads. Also adds a debug sentinel check during pool initialization.

  • New Features

    • New tlsf_pool_reset(tlsf_t*): clears FL/SL bitmaps and bins, then rebuilds a single free block + sentinel with fixed, predictable cost.
    • Works only on static pools created with tlsf_pool_init; no-op for NULL/dynamic pools. Preserves expanded capacity from tlsf_append_pool across resets.
    • Adds check_sentinel() in tlsf_pool_init for debug-mode invariant checks.
  • Migration

    • After tlsf_pool_reset, all previously returned pointers are invalid. Do not pass them to tlsf_free or tlsf_realloc.
    • Use tlsf_pool_reset to implement arena-style “discard all” phases; no other changes required.

Written for commit 3bfefcc. Summary will update on new commits.

Arena-style workloads (allocate many, discard all) currently require
per-object tlsf_free() calls.  tlsf_pool_reset() clears the FL/SL
bitmaps, resets bin pointers to the sentinel, and reconstructs a
single free block plus sentinel -- the same layout tlsf_pool_init()
produces.  Pools extended via tlsf_append_pool() retain their full
expanded capacity across resets.

This also adds check_sentinel() after sentinel construction in
tlsf_pool_init() for debug-mode invariant enforcement.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 9, 2026

WCET Results (x86-64)

TLSF WCET Analysis
==================
Timer:      cycles
Cache:      hot
Pool:       4194304 bytes (4.0 MB)
Iterations: 5000 (warmup: 500)
Sizes:      16 64 256 1024 4096 bytes

--- malloc_worst (small alloc from single huge block) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         73         98         98        123        171      32462      104.4      457.8
      64         98         98         98        123        123        147       98.8        4.4
     256         73         98         98        122        196        392       94.9       10.8
    1024         73         98        122        123        123        221       99.5        9.9
    4096         98         98        122        123        123        245      101.7        9.1

--- malloc_best (exact bin hit, no split) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         49         73         74         74         74         74       69.4        9.1
      64         49         73         74         74         74        147       70.8        7.8
     256         49         73         74         74         74         74       69.3        9.2
    1024         49         73         74         74         74        147       66.8       11.1
    4096         49         73         74         74         74      16562       72.6      233.4

--- free_worst (sandwiched between two free blocks) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         49         74         98         98         98        245       75.7       10.6
      64         49         74         98         98        147        245       76.7       10.8
     256         49         74         98         98        220        270       78.7       12.0
    1024         49         74         98         98         98        171       75.0       10.0
    4096         49         73         74         98        147        221       72.5        8.4

--- free_best (no merge (used neighbors)) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         49         73         74         74        123        245       63.5       12.8
      64         49         49         74         74        122        245       61.1       12.7
     256         49         73         74         74        122      18816       65.6      265.5
    1024         49         73         74         74        123        417       63.3       13.6
    4096         49         73         74         74        147      17738       65.6      250.3

--- worst/best ratio (p99) ---
    size     malloc       free
      16      1.26x      1.32x
      64      1.66x      1.32x
     256      1.65x      1.32x
    1024      1.66x      1.32x
    4096      1.66x      1.32x

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 9, 2026

WCET Results (arm64)

TLSF WCET Analysis
==================
Timer:      ticks
Cache:      hot
Pool:       4194304 bytes (4.0 MB)
Iterations: 5000 (warmup: 500)
Sizes:      16 64 256 1024 4096 bytes

--- malloc_worst (small alloc from single huge block) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         24         32         32         32         40         40       30.9        2.9
      64         24         32         32         32         40         40       30.9        2.9
     256         24         32         32         32         40         48       30.7        3.1
    1024         24         32         32         32         40         48       30.7        3.1
    4096         16         32         32         32         40         40       30.7        3.1

--- malloc_best (exact bin hit, no split) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         32         32         32         40       25.1        2.8
      64          8         24         32         32         32         32       25.2        2.9
     256          8         24         32         32         32         40       24.9        2.6
    1024         16         24         32         32         32         40       24.8        2.5
    4096         16         24         32         32         32         40       24.8        2.6

--- free_worst (sandwiched between two free blocks) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         32         32         32         40       25.7        3.3
      64         16         24         32         32         32       2568       26.2       36.1
     256         16         24         32         32         32         32       25.5        3.2
    1024         16         24         32         32         32       2576       26.1       36.2
    4096         16         24         32         32         32         40       25.9        3.4

--- free_best (no merge (used neighbors)) ---
    size        min        p50        p90        p99      p99.9        max       mean     stddev
      16         16         24         24         24         24         32       20.4        4.0
      64         16         24         24         24         24         32       20.6        4.0
     256         16         24         24         24         24         32       20.6        4.0
    1024         16         24         24         24         24         24       20.6        4.0
    4096          8         24         24         24         24       7400       22.0      104.4

--- worst/best ratio (p99) ---
    size     malloc       free
      16      1.00x      1.33x
      64      1.00x      1.33x
     256      1.00x      1.33x
    1024      1.00x      1.33x
    4096      1.00x      1.33x

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@jserv jserv merged commit 3dd5f6c into master Feb 9, 2026
14 checks passed
@jserv jserv deleted the pool-reset branch February 9, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant