Skip to content

Add configurable RLIMIT_MEMLOCK checks before torrent startup #175

Open

Description

@4m1z

Background

I'm splitting the MEMLOCK work out of #172 so #151 can focus on RLIMIT_NOFILE.

#150 fixed the setup panic reported in #149. This follow-up covers the requested startup headroom check for ring memory.

Proposed changes

  • Validate queue and buffer-ring sizes, then estimate their storage with checked arithmetic.
  • Warn when the estimated budget exceeds RLIMIT_MEMLOCK; allow startup rejection through memlock_strict = true.
  • Make headroom configurable through memlock_headroom_percent, defaulting to 100% extra.
  • Preserve OS errors from setup and registration, with recovery guidance that respects the hard limit.

On my machine, ring setup succeeded with MEMLOCK set to zero. I'm proposing advisory checks by default because kernel accounting varies. Actual allocation failures would still stop startup.

Testing

Cover policy boundaries, invalid sizes, overflow, and existing TOML compatibility. Use strace to test setup and registration failures without exhausting memory. Genuine kernel-enforced MEMLOCK exhaustion hasn't been reproduced locally.

Would you prefer advisory checks by default, or should an insufficient estimate stop startup?

Activity

  1. 4m1z commented on Nov 21, 2026

    @4m1z
    ContributorAuthor

    PR for this issue: #176

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions