I was trying the bpftrace tool to see who was allocating pages on my Linux homelab server, and the answer surprised me (my own silly Neovim configuration).

Who is allocating pages? Link to heading

The kernel has a tracepoint, kmem:mm_page_alloc, that fires every time the page allocator hands out pages. Its order argument is the size of the allocation as a power of two: order 0 is a single 4 KiB page, order 9 is 29 pages = 2 MiB (the size of a transparent huge page on x86-64).

This one-liner counts allocations by process name (comm) and order. The END block runs when I hit Ctrl-C and prints the top 10 entries:

❯ sudo bpftrace -e '
tracepoint:kmem:mm_page_alloc { @[comm, args->order] = count(); }
END { print(@, 10); clear(@); }'
Attaching 2 probes...
^C

@[kworker/u8:2, 0]: 116
@[nvim, 0]: 180
@[jj, 9]: 199
@[ctrl-c, 0]: 342
@[df, 0]: 458
@[watch, 0]: 576
@[prometheus-node, 0]: 579
@[sh, 0]: 1961
@[tput, 0]: 2751
@[jj, 0]: 41279

jj is way out in front: tens of thousands of single pages plus a couple of hundred 2 MiB huge pages. Counts are hard to compare across orders, so convert to bytes instead with 4096 << order:

❯ sudo bpftrace -e '
tracepoint:kmem:mm_page_alloc { @bytes[comm] = sum(4096 << args->order); }
END { print(@bytes, 10); clear(@bytes); }'
Attaching 2 probes...
^C

@bytes[grafana]: 299008
@bytes[kworker/u8:3]: 315392
@bytes[nvim]: 466944
@bytes[ctrl-c]: 507904
@bytes[df]: 819200
@bytes[watch]: 1110016
@bytes[sh]: 3727360
@bytes[smbclient]: 3756032
@bytes[tput]: 5009408
@bytes[jj]: 265117696
ProcessAllocated
jj265 MB
tput5.0 MB
smbclient3.8 MB
sh3.7 MB
watch1.1 MB
df0.8 MB
ctrl-c0.5 MB
nvim0.5 MB
kworker/u8:30.3 MB
grafana0.3 MB

This is memory churn, not usage. We are just counting page allocations.

I wasn’t running some huge ridiculous jj command so I suspected that my Neovim processes (inside idle tmux sessions) was the culprit.

Who is calling jj? Link to heading

The sys_enter_execve tracepoint fires whenever a process tries to execute a program, so printing the caller’s name and the target path shows who starts what:

❯ sudo bpftrace -e 'tracepoint:syscalls:sys_enter_execve { printf("%s -> %s\n", comm, str(args->filename)); }'
Attaching 1 probe...
nvim -> /bin/sh
sh -> /home/carlo/opt/jj/jj
jj -> /home/carlo/.local/share/nvim/mason/bin/tput
jj -> /home/carlo/.elan/bin/tput
jj -> /home/carlo/bin/tput
jj -> /home/carlo/.local/bin/tput
jj -> /home/carlo/opt/clojure/clojure-tools/tput
jj -> /home/carlo/opt/jj/tput
jj -> /home/carlo/opt/node/node-v25.2.1-linux-x64/bin/tput
jj -> /home/carlo/go/bin/tput
jj -> /home/carlo/.duckdb/cli/latest/tput
jj -> /home/carlo/opt/nvim/nvim-linux-x86_64/bin/tput
jj -> /home/carlo/.elan/bin/tput
jj -> /home/carlo/bin/tput
jj -> /home/carlo/.local/bin/tput
jj -> /home/carlo/opt/clojure/clojure-tools/tput
jj -> /home/carlo/opt/jj/tput
jj -> /home/carlo/opt/node/node-v25.2.1-linux-x64/bin/tput
jj -> /home/carlo/go/bin/tput
jj -> /home/carlo/.duckdb/cli/latest/tput
jj -> /home/carlo/opt/nvim/nvim-linux-x86_64/bin/tput
jj -> /usr/local/bin/tput
jj -> /usr/bin/tput
jj -> /home/carlo/.local/share/nvim/mason/bin/tput
jj -> /home/carlo/.elan/bin/tput
jj -> /home/carlo/bin/tput
jj -> /home/carlo/.local/bin/tput
jj -> /home/carlo/opt/clojure/clojure-tools/tput
jj -> /home/carlo/opt/jj/tput
jj -> /home/carlo/opt/node/node-v25.2.1-linux-x64/bin/tput
jj -> /home/carlo/go/bin/tput
jj -> /home/carlo/.duckdb/cli/latest/tput
jj -> /home/carlo/opt/nvim/nvim-linux-x86_64/bin/tput
jj -> /home/carlo/.elan/bin/tput
jj -> /home/carlo/bin/tput
jj -> /home/carlo/.local/bin/tput
jj -> /home/carlo/opt/clojure/clojure-tools/tput
jj -> /home/carlo/opt/jj/tput
jj -> /home/carlo/opt/node/node-v25.2.1-linux-x64/bin/tput
jj -> /home/carlo/go/bin/tput
jj -> /home/carlo/.duckdb/cli/latest/tput
jj -> /home/carlo/opt/nvim/nvim-linux-x86_64/bin/tput
jj -> /usr/local/bin/tput
jj -> /usr/bin/tput

(lots more output)

The chain is nvim → sh → jj → tput, over and over.

There’s a bonus facepalm in there. To run tput, jj’s child walks $PATH and calls execve on each directory in turn until one works. (It’s still called jj in this output because a process only gets its new name once an execve succeeds.) Nearly every directory appears twice, so each tput costs 21 execve calls, of which 20 fail before /usr/bin/tput succeeds. My shell startup files are adding the same directories to $PATH more than once.

My statusline Link to heading

lualine is the plugin that draws my Neovim statusline, and I’d added a custom component to show the jj change ID of the working copy:

      local function jujutsu_status()
        local handle = io.popen('jj log -r @ -T "change_id.short()" --no-graph 2>/dev/null')
        if handle then
          local result = handle:read("*a")
          handle:close()
          if result and result ~= "" then
            return "jj: " .. result:gsub("\n", "")
          end
        end
        return ""
      end

lualine re-evaluates components every time it redraws, and by default it also refreshes the statusline on a timer every second. So every open Neovim was running sh -c 'jj log ...' (that’s what io.popen does) about once a second, forever, even while sitting idle in a tmux pane I wasn’t looking at. And because io.popen is synchronous, the editor blocks until jj finishes.

On top of that, by default each jj command first snapshots the working copy, which means scanning the tree for changes, before it does what you asked. That’s a lot of work just to print the same 8 characters.

A nicer version Link to heading

The fix: run jj asynchronously with vim.system (Neovim 0.10+), only when something has happened that could change the answer (entering a buffer, saving, regaining focus, changing directory), never more than one at a time, and cache the result. The statusline component just returns the cached string.

I also pass --ignore-working-copy so jj skips the snapshot. The change ID of @ stays the same when the working copy is snapshotted (only the commit ID changes), so skipping the snapshot doesn’t make the display stale.

      local jj_status = ""
      local jj_running = false
      local jj_pending = false

      local function refresh_jj_status()
        if vim.fn.executable("jj") == 0 then return end
        -- BufEnter fires in bursts (Telescope previews etc.): coalesce them into
        -- at most one follow-up run instead of piling up processes.
        if jj_running then
          jj_pending = true
          return
        end
        jj_running = true
        vim.system(
          { "jj", "log", "-r", "@", "-T", "change_id.short()", "--no-graph", "--ignore-working-copy" },
          { text = true },
          function(out)
            local id = out.code == 0 and vim.trim(out.stdout or "") or ""
            local new_status = id ~= "" and ("jj: " .. id) or ""
            vim.schedule(function()
              jj_running = false
              if new_status ~= jj_status then
                jj_status = new_status
                vim.cmd.redrawstatus()
              end
              if jj_pending then
                jj_pending = false
                refresh_jj_status()
              end
            end)
          end
        )
      end

      vim.api.nvim_create_autocmd({ "VimEnter", "BufEnter", "BufWritePost", "FocusGained", "DirChanged" }, {
        group = vim.api.nvim_create_augroup("JujutsuStatus", { clear = true }),
        callback = refresh_jj_status,
      })
      refresh_jj_status() -- lualine may load after VimEnter has already fired

      local function jujutsu_status()
        return jj_status
      end

Before and after Link to heading

For a clean comparison I closed everything except a single Neovim, left it idle, and traced every execve whose path contains jj for 30 seconds. curtask->real_parent->comm is the name of the parent process, so each key is (parent, caller, program).

Before:

❯ sudo bpftrace -e '
tracepoint:syscalls:sys_enter_execve /strcontains(str(args->filename, 64), "jj")/ {
  @[curtask->real_parent->comm, comm, str(args->filename, 64)] = count();
}
interval:s:30 { exit(); }'
Attaching 2 probes...


@[sh, sh, /home/carlo/opt/jj/jj]: 30
@[jj, jj, /home/carlo/opt/jj/tput]: 60

30 runs of jj in 30 seconds: exactly lualine’s one-second refresh. The 60 tput lines are an artifact of the filter: /home/carlo/opt/jj/tput contains jj, and that directory is in my $PATH twice, so each tput lookup matches twice.

After, nothing shows up at all:

❯ sudo bpftrace -e '
tracepoint:syscalls:sys_enter_execve /strcontains(str(args->filename, 64), "jj")/ {
  @[curtask->real_parent->comm, comm, str(args->filename, 64)] = count();
}
interval:s:30 { exit(); }'
Attaching 2 probes...

That’s an idle editor. jj still runs when I switch buffers, save, and so on, but that’s a handful of runs while I’m actually working instead of one a second per Neovim, around the clock.

Loading comments…

Comment form pending Cloudflare verification...