Skip to content

Support ebpf program live update #15

Open

Description

@congwang-mk
No description provided.

Activity

  1. Kenan-Kamel commented on May 25, 2026

    @Kenan-Kamel

    Hey @congwang-mk
    Thanks a lot for your great work on KScript. I can work on this feature incrementally and slowly over the summer. Do you have any suggestions or a good starting point? As I "promised" during AgenticOS'26, to contribute to the project.

    -Kenan (University of Illinois Chicago)

  2. congwang-mk commented on May 26, 2026

    @congwang-mk
    ContributorAuthor

    Hi @Kenan-Kamel — thanks again, great to hear from you after AgenticOS'26.

    Quick reframe on the design before you dig in. There are really two pieces here:

    1. A CLI workflow for the lifecycle:

    kernelscript deploy app.ks --name foo     # initial install, pins to /sys/fs/bpf/foo/
    kernelscript update foo app_v2.ks         # swap the running instance
    

    The pin tree under /sys/fs/bpf/<name>/ is the canonical record of a running instance — no daemon needed.

    2. Language support for map migrations — and this is the part I think is most interesting. Program code can be swapped atomically with bpf_link__update_program, but if the new .ks changes a map's key/value shape, that map has to be recreated, and the old contents need to be migrated explicitly. Rather than handle this with a CLI flag, I'd like the language itself to express it — something like:

    @migrate(flows)
    fn migrate_flows(old: hash<u32, OldStats>, new: hash<u32, NewStats>) {
        for (k, v) in old {
            new[k] = NewStats { count: v.count, bytes: 0 }
        }
    }
    

    The compiler refuses to compile a new version if a map's shape changed and no @migrate exists. The CLI then invokes the handler between loading the new program and atomically attaching it. Old map schema can be recovered from BTF on the bpffs pin, so the user doesn't have to ship the old .ks.

    Suggested phasing for incremental summer work:

    1. kernelscript deploy + pinning (single-program XDP). Smallest useful unit.
    2. kernelscript update for the transparent case — same map shapes, program-only swap.
    3. @migrate syntax + type checker enforcement (pure compiler work).
    4. Wire migrations into the update flow — codegen + CLI invocation.

    Each phase is independently shippable. Before code, I'd love a short design note from you in this issue covering: (a) exact CLI surface and pin layout, (b) @migrate syntax and what counts as a "breaking" map change, (c) error/rollback behavior when a migration fails partway. That lets us iterate cheaply.

    Happy to sync if useful — otherwise this thread works.

  3. Kenan-Kamel commented on May 27, 2026

    @Kenan-Kamel

    Thanks @congwang-mk,
    I will dive deeper into the code for a few weeks and post/create a design note before I start writing code for each phase, as you suggested. The plan is clear and straightforward; it lists any possible additions in the design notes.

    -Kenan

  4. congwang-mk commented on May 27, 2026

    @congwang-mk
    ContributorAuthor

    Thanks @congwang-mk, I will dive deeper into the code for a few weeks and post/create a design note before I start writing code for each phase, as you suggested. The plan is clear and straightforward; it lists any possible additions in the design notes.

    -Kenan

    Please feel free to suggest better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions