File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
library/std/src/sys/pal/unix Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -440,13 +440,24 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
440
440
}
441
441
}
442
442
}
443
+
444
+ let mut ulimit = u64 :: MAX ;
445
+ #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
446
+ {
447
+ let mut r: libc:: rlimit = unsafe { mem:: zeroed( ) } ;
448
+ unsafe {
449
+ if libc:: getrlimit( libc:: RLIMIT_NPROC , & mut r) == 0 {
450
+ ulimit = r. rlim_max
451
+ }
452
+ }
453
+ }
443
454
match unsafe { libc:: sysconf( libc:: _SC_NPROCESSORS_ONLN) } {
444
455
-1 => Err ( io:: Error :: last_os_error( ) ) ,
445
456
0 => Err ( io:: Error :: UNKNOWN_THREAD_COUNT ) ,
446
457
cpus => {
447
458
let count = cpus as usize ;
448
459
// Cover the unusual situation where we were able to get the quota but not the affinity mask
449
- let count = count. min( quota) ;
460
+ let count = count. min( quota. min ( ulimit . try_into ( ) . unwrap_or ( usize :: MAX ) ) ) ;
450
461
Ok ( unsafe { NonZero :: new_unchecked( count) } )
451
462
}
452
463
}
You can’t perform that action at this time.
0 commit comments