File tree Expand file tree Collapse file tree 1 file changed +35
-8
lines changed
backend/windmill-common/src Expand file tree Collapse file tree 1 file changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -512,16 +512,43 @@ pub fn get_vcpus() -> Option<i64> {
512512 }
513513}
514514
515+ fn get_memory_from_meminfo ( ) -> Option < i64 > {
516+ let memory_info = parse_file :: < String > ( "/proc/meminfo" ) ?;
517+ if memory_info. contains ( "MemTotal" ) {
518+ let memory_total = memory_info
519+ . split ( "MemTotal:" )
520+ . nth ( 1 ) ?
521+ . split ( "kB" )
522+ . next ( ) ?
523+ . trim ( )
524+ . parse :: < i64 > ( )
525+ . ok ( ) ?;
526+ return Some ( memory_total * 1024 ) ;
527+ }
528+ None
529+ }
530+
515531pub fn get_memory ( ) -> Option < i64 > {
516- if Path :: new ( "/sys/fs/cgroup/memory/memory.limit_in_bytes" ) . exists ( ) {
517- // cgroup v1
518- parse_file ( "/sys/fs/cgroup/memory/memory.limit_in_bytes" )
519- } else {
520- // cgroup v2
521- let cgroup_path = get_cgroupv2_path ( ) ?;
522- let memory_max_path = format ! ( "{cgroup_path}/memory.max" ) ;
532+ let memory_limit: Option < i64 > =
533+ if Path :: new ( "/sys/fs/cgroup/memory/memory.limit_in_bytes" ) . exists ( ) {
534+ // cgroup v1
535+ parse_file ( "/sys/fs/cgroup/memory/memory.limit_in_bytes" )
536+ } else {
537+ // cgroup v2
538+ let cgroup_path = get_cgroupv2_path ( ) ?;
539+ let memory_max_path = format ! ( "{cgroup_path}/memory.max" ) ;
540+
541+ parse_file ( & memory_max_path)
542+ } ;
523543
524- parse_file ( & memory_max_path)
544+ // if memory_max is super high, read machine total memory (meminfo)
545+ if memory_limit
546+ . as_ref ( )
547+ . is_some_and ( |x| x > & ( 1024 * 1024 * 1024 * 1024 * 1024 ) )
548+ {
549+ get_memory_from_meminfo ( )
550+ } else {
551+ memory_limit
525552 }
526553}
527554
You can’t perform that action at this time.
0 commit comments