Skip to content

lua-lsm: lazily allocate task and object dictionary state - #27

Open
chenzongyao200127 wants to merge 5 commits into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm-task-blob-lazy-state
Open

lua-lsm: lazily allocate task and object dictionary state#27
chenzongyao200127 wants to merge 5 commits into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm-task-blob-lazy-state

Conversation

@chenzongyao200127

@chenzongyao200127 chenzongyao200127 commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • allocate per-task Lua VM and kvcache state only on first use
  • leave zero-allocated object and shared dictionaries uninitialized until their first write
  • preserve safe teardown and uninitialized shared-dictionary formatting

Most tasks never use Lua VM or object property state. Once Lua hooks are
active, however, each task carries an embedded kvcache dictionary and a
separate teardown flag. This expands the task security blob and adds work
to task allocation and teardown.

Keep only the VM and dictionary pointers in the task blob and allocate each
state on first use. Untouched tasks can now skip Lua teardown entirely.

Publish ERR_PTR(-ESRCH) before reclaiming lazy state so reentrant hooks
cannot recreate task state while Lua finalizers run.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Most kernel objects never store Lua policy properties, especially when
no policy is loaded. Initializing every embedded dictionary during
object allocation therefore performs unnecessary lock and tree setup.

Leave zero-allocated object and shared dictionaries in the UNINIT state
until their first write. Keep reads and teardown safe for uninitialized
dictionaries, and report the default shared dictionary capacity before
initialization.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Shrink object security blobs to a pointer and allocate dictionaries on
first use.

Centralize object teardown and preserve ENOMEM for task and object lazy
allocation failures.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Group declarations by responsibility and order includes consistently.
Keep related types, state, and interfaces adjacent.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Valid task and object kvcache reads can now see no dictionary after
lazy allocation when the key has never been written.

lua_object_get() returned no Lua values in that case, while a read from
an initialized empty dictionary returns one nil. This changes
observable Lua return arity in tail-return and multiret contexts.

Push nil for the no-dictionary read path and keep the dictionary
unallocated.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
@chenzongyao200127
chenzongyao200127 force-pushed the lua-lsm-task-blob-lazy-state branch from eac3a77 to 7e3d971 Compare July 20, 2026 07:16
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