Skip to content

Implement Layer 1: slab cache allow/deny list filtering#3

Merged
sdimitro merged 3 commits into
developfrom
claude/slab-cache-filtering-diMyI
Feb 8, 2026
Merged

Implement Layer 1: slab cache allow/deny list filtering#3
sdimitro merged 3 commits into
developfrom
claude/slab-cache-filtering-diMyI

Conversation

@sdimitro

@sdimitro sdimitro commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Add per-cache slab filtering so operators can specify an allowlist or
denylist of kmem_cache names instead of the all-or-nothing filter_slab=1.

New module parameters:
slab_action=allow|deny — list interpretation (default: allow)
slab_cache_list=X,Y,Z — comma-separated cache names (load-time only)

Priority hierarchy:

  1. filter_slab=1 overrides everything (runtime kill switch)
  2. slab_cache_list + slab_action when list is non-empty
  3. Default: allow all slab pages

Implementation accesses the slab_cache pointer via a minimal two-word
struct overlay on struct page (stable since Linux 5.17), then uses the
exported kmem_cache_name() to compare against the parsed list. NULL
checks on both the cache pointer and name handle races conservatively.

Performance: zero overhead when list is inactive. ~100ns/slab-page when
active (pointer deref + linear strcmp over typically 10-30 entries),
roughly 1-3% of per-page read cost.

https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof

Add per-cache slab filtering so operators can specify an allowlist or
denylist of kmem_cache names instead of the all-or-nothing filter_slab=1.

New module parameters:
  slab_action=allow|deny  — list interpretation (default: allow)
  slab_cache_list=X,Y,Z   — comma-separated cache names (load-time only)

Priority hierarchy:
  1. filter_slab=1 overrides everything (runtime kill switch)
  2. slab_cache_list + slab_action when list is non-empty
  3. Default: allow all slab pages

Implementation accesses the slab_cache pointer via a minimal two-word
struct overlay on struct page (stable since Linux 5.17), then uses the
exported kmem_cache_name() to compare against the parsed list. NULL
checks on both the cache pointer and name handle races conservatively.

Performance: zero overhead when list is inactive. ~100ns/slab-page when
active (pointer deref + linear strcmp over typically 10-30 entries),
roughly 1-3% of per-page read cost.

https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
kmem_cache_name() is EXPORT_SYMBOL_GPL in mm/slab_common.c but its
declaration lives in mm/slab.h (kernel-internal header). Modules
cannot include that header, so provide our own forward declaration.

https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
kmem_cache_name() is declared in the internal mm/slab.h header, so
modpost cannot resolve it for out-of-tree modules even though the
symbol is exported.

Replace with a self-discovering probe: at init time, create a
temporary kmem_cache with a known name, scan the struct for a
pointer to that name string, record the byte offset, and destroy
the probe.  At runtime, read the name at the discovered offset.

This is config-independent, version-independent, and gracefully
disables the slab list feature if the probe fails.

Also fix non-ASCII em-dashes and a declaration-after-statement that
checkpatch flags.

https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
@sdimitro sdimitro merged commit 95f083c into develop Feb 8, 2026
10 checks passed
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.

2 participants