MCPcopy Create free account
hub / github.com/Niko1221/Strata / scan_levels

Function scan_levels

engine/src/core/conversation_memory.cpp:205–232  ·  view source on GitHub ↗

`dirs` runs from the top visible group down to the process's own. False when a file that is there cannot be used.

Source from the content-addressed store, hash-verified

203
204// `dirs` runs from the top visible group down to the process's own. False when a file that is there cannot be used.
205bool scan_levels(const std::vector<fs::path>& dirs, const char* const* limit_names, size_t n_limits,
206 const char* current_name, bool v1, CgroupScan& out) {
207 for (size_t i = 0; i < dirs.size(); ++i) {
208 const Value current = read_value(dirs[i] / current_name);
209 std::vector<Value> limits;
210 for (size_t k = 0; k < n_limits; ++k) limits.push_back(read_value(dirs[i] / limit_names[k]));
211 bool unusable = current.kind == Value::bad || current.kind == Value::max;
212 bool finite_limit = false;
213 for (const Value& v : limits) {
214 unusable = unusable || v.kind == Value::bad;
215 finite_limit = finite_limit || v.kind == Value::number;
216 }
217 if (unusable) return false;
218 if (current.kind == Value::absent) {
219 if (finite_limit) return false; // a limit with no usage beside it: the room cannot be told
220 continue; // no memory controller at this level (e.g. the host's root group)
221 }
222 out.any_files = true;
223 const CacheCredit credit = reclaimable_cache(dirs[i], current.n, v1);
224 if (i == 0) { out.root_current = current.n; out.root_credit = credit.inactive; }
225 for (const Value& v : limits) {
226 if (v.kind != Value::number) continue;
227 if (v1 && v.n >= (1ull << 62)) continue; // v1's "unlimited" is a number near 2^63
228 out.limits.push_back({v.n, current.n, credit});
229 }
230 }
231 return true;
232}
233
234// "/a/b/c" -> root, root/a, root/a/b, root/a/b/c, cut at the first one that is not a directory here: a container
235// without its own cgroup namespace sees its group's host path in /proc/self/cgroup, but only its own subtree under

Callers 1

scan_cgroupsFunction · 0.85

Calls 4

reclaimable_cacheFunction · 0.85
push_backMethod · 0.80
read_valueFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected