Skip to content

Index watchers by the kernel file descriptor - #21

Open
alexey-milovidov wants to merge 1 commit into
ClickHouse/v1.53.0from
fd-randomization
Open

alexey-milovidov wants to merge 1 commit into
ClickHouse/v1.53.0from
fd-randomization

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

With the musl of ClickHouse, the file descriptors visible to the program are a pseudorandom 31-bit encoding of the kernel descriptor and its generation, so loop->watchers[fd] would need an array of gigabytes (RabbitMQ and NATS use libuv).

  • The table of watchers is indexed by the kernel descriptor (uv__kernel_fd, identity without USE_MUSL).
  • A watcher whose descriptor is already closed is found by a search, so no stale pointer stays in the table.
  • An epoll event whose descriptor does not match the watcher (closed and reused) is disarmed like an event of a stopped watcher.
  • io_uring submission entries get kernel descriptors, and the result of openat through io_uring is converted back.

Related: ClickHouse/musl#22

🤖 Generated with Claude Code

With the musl of ClickHouse, the file descriptors visible to the program are a
pseudorandom 31-bit encoding of the kernel descriptor and its generation (see
`contrib/musl/src/internal/fdmap.h` in ClickHouse), so `loop->watchers[fd]` would
need an array of gigabytes. The table is now indexed by the kernel descriptor,
which is small. A watcher whose descriptor is already closed is found by a search,
and an epoll event of a descriptor that does not match the watcher (closed and
reused) is disarmed like an event of a stopped watcher.

The kernel reads the descriptors of io_uring submission entries directly, so they
are translated too, and the result of an `openat` through io_uring is converted
back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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