class << self
Definitions
def quota(cgroup_root: DEFAULT_CGROUP_ROOT, cgroup_path: DEFAULT_CGROUP_PATH)
Read the effective processor quota for the current cgroup.
Signature
-
parameter
cgroup_rootString The root of the cgroup v2 filesystem.
-
parameter
cgroup_pathString The process cgroup membership file.
-
returns
Float | Nil The smallest finite quota in the cgroup hierarchy, if available.
Implementation
def quota(cgroup_root: DEFAULT_CGROUP_ROOT, cgroup_path: DEFAULT_CGROUP_PATH)
unless relative_path = current_path(cgroup_path)
return nil
end
root = File.expand_path(cgroup_root)
directory = File.expand_path(relative_path.delete_prefix("/"), root)
return nil unless directory == root || directory.start_with?("#{root}/")
quota = nil
loop do
if current = read_quota(directory)
quota = [quota, current].compact.min
end
break if directory == root
directory = File.dirname(directory)
end
return quota
rescue Errno::EACCES, Errno::EINVAL, Errno::ENOENT, Errno::ENOTDIR, ArgumentError
return nil
end