Skip to content

Commit 59a3a59

Browse files
authored
perf: filter unrelated process groups before reading resident memory (#50)
Preserve complete group membership, refused-query fallback, immediate observation, polling cadence and whole-unit termination. GCC and LLVM conformance/surface/independence pass; frozen Linux same-host controls preserve the original workload and gates.
1 parent 81cab91 commit 59a3a59

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ for Linux, written on the kernel's own system-call interface.
88
openkal = "0.23.0"
99

1010
[target.'cfg(os = "linux")'.dependencies]
11-
openkal-linux = "0.24.1"
11+
openkal-linux = "0.24.2"
1212
```
1313

1414
## Why it does not use a C library
@@ -227,7 +227,9 @@ and later) instead of polling.
227227

228228
A unit is a process group, and its use is the sum over the entries of /proc
229229
whose group is the unit's --- every program in it, including those its members
230-
started; one read per program on the machine, made only when a caller asks.
230+
started. Every visible program's group is queried; resident memory is read for
231+
matching programs. If the group query is refused, the same /proc record supplies
232+
both membership and memory. Nothing is retained between observations.
231233
`KAL_PROCESS_PROP_JOB_USAGE` is claimed.
232234

233235
**A limit on a unit is supervised.** `kal_process_job_limit` starts, with the

‎mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-linux"
4-
version = "0.24.1"
4+
version = "0.24.2"
55
description = "The reference implementation of openkal for Linux, written on the kernel's own system-call interface so that it can be placed beneath a C library as well as above one."
66
license = "Apache-2.0"
77

‎src/process.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,12 @@ kal_u32 members_of(okl_long unit, okl_u64& memory) {
17671767
if (name[0] < '1' || name[0] > '9') continue;
17681768
okl_long pid = 0;
17691769
for (const char* c = name; *c; ++c) pid = pid * 10 + (*c - '0');
1770+
// Most visible programs belong to other units. Ask for the group
1771+
// before opening a record whose memory will then be discarded.
1772+
// A denied or unavailable query keeps the record-reading path;
1773+
// even a positive query is checked again in that same RSS record.
1774+
const okl_long group = okl::sys(okl::nr_getpgid, pid);
1775+
if (!okl::failed(group) && group != unit) continue;
17701776
char b[1024];
17711777
const okl_long len = read_stat(pid, b);
17721778
if (len <= 0) continue;

‎src/sys.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ enum : okl_long {
115115
// openkal 0.13: whether a node may be started
116116
nr_fchmodat = 268,
117117
// openkal 0.11: the directory a started program runs in, and the unit it joins
118-
nr_fchdir = 81, nr_setpgid = 109, nr_rt_sigaction = 13,
118+
nr_fchdir = 81, nr_setpgid = 109, nr_getpgid = 121, nr_rt_sigaction = 13,
119119
// openkal.net and openkal.datagram
120120
nr_socket = 41, nr_connect = 42, nr_accept = 43, nr_sendto = 44,
121121
nr_recvfrom = 45, nr_shutdown = 48, nr_bind = 49, nr_listen = 50,
@@ -223,7 +223,7 @@ enum : okl_long {
223223
// openkal 0.13: whether a node may be started
224224
nr_fchmodat = 53,
225225
// openkal 0.11: the directory a started program runs in, and the unit it joins
226-
nr_fchdir = 50, nr_setpgid = 154, nr_rt_sigaction = 134,
226+
nr_fchdir = 50, nr_setpgid = 154, nr_getpgid = 155, nr_rt_sigaction = 134,
227227
// openkal.net and openkal.datagram
228228
nr_socket = 198, nr_connect = 203, nr_accept = 202, nr_sendto = 206,
229229
nr_recvfrom = 207, nr_shutdown = 210, nr_bind = 200, nr_listen = 201,

0 commit comments

Comments
 (0)