Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cgroup quotas for calculating available_parallelism #92697

Merged
merged 3 commits into from
Mar 4, 2022

Commits on Mar 2, 2022

  1. Use cgroup quotas for calculating available_parallelism

    Manually tested via
    
    
    ```
    // spawn a new cgroup scope for the current user
    $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS
    
    
    // quota.rs
    #![feature(available_parallelism)]
    fn main() {
        println!("{:?}", std::thread::available_parallelism()); // prints Ok(3)
    }
    ```
    
    
    Caveats
    
    * cgroup v1 is ignored
    * funky mountpoints (containing spaces, newlines or control chars) for cgroupfs will not be handled correctly since that would require unescaping /proc/self/mountinfo
      The escaping behavior of procfs seems to be undocumented. systemd and docker default to `/sys/fs/cgroup` so it should be fine for most systems.
    * quota will be ignored when `sched_getaffinity` doesn't work
    * assumes procfs is mounted under `/proc` and cgroupfs mounted and readable somewhere in the directory tree
    the8472 committed Mar 2, 2022
    Configuration menu
    Copy the full SHA
    bac5523 View commit details
    Browse the repository at this point in the history
  2. hardcode /sys/fs/cgroup instead of doing a lookup via mountinfo

    this avoids parsing mountinfo which can be huge on some systems and
    something might be emulating cgroup fs for sandboxing reasons which means
    it wouldn't show up as mountpoint
    
    additionally the new implementation operates on a single pathbuffer, reducing allocations
    the8472 committed Mar 2, 2022
    Configuration menu
    Copy the full SHA
    af6d2ed View commit details
    Browse the repository at this point in the history
  3. update available_parallelism docs since cgroups and sched_getaffinity…

    … are now taken into account
    the8472 committed Mar 2, 2022
    Configuration menu
    Copy the full SHA
    e18abbf View commit details
    Browse the repository at this point in the history