Skip to main content
added 74 characters in body
Source Link

The answer is to first read /proc/self/cgroup, trim the starting 0:: and trailing \n, then append that path to /sys/fs/cgroup and append to that /memory.pressure. It'll look like this: /sys/fs/cgroup${cgroup path}/memory.pressure. Now you can open the file and write a trigger as per the docs.

Sample code here: https://github.com/SUPERCILEX/clipboard-history/blob/e91b80a482e019f1c3af5b3898678ee3aa8384c1/server/src/reactor.rs#L134-L166


Edit: code from my answer to a comment so the formatting works:

let stop = Arc::new(AtomicBool::new(false));

thread::spawn({
    let stop = stop.clone();
    move || {
        let time = Instant::now();
        let mut ll = LinkedList::new();
        loop {
            if stop.load(Ordering::Relaxed) {
                break;
            }

            ll.push_back([time.elapsed(); 10000]);
        }
    }
});

// --- In the poll fd for low mem

stop.store(true, Ordering::Relaxed);

The answer is to first read /proc/self/cgroup, trim the starting 0:: and trailing \n, then append that path to /sys/fs/cgroup and append to that /memory.pressure. It'll look like this: /sys/fs/cgroup${cgroup path}/memory.pressure. Now you can open the file and write a trigger as per the docs.

Sample code here: https://github.com/SUPERCILEX/clipboard-history/blob/e91b80a482e019f1c3af5b3898678ee3aa8384c1/server/src/reactor.rs#L134-L166

The answer is to first read /proc/self/cgroup, trim the starting 0:: and trailing \n, then append that path to /sys/fs/cgroup and append to that /memory.pressure. It'll look like this: /sys/fs/cgroup${cgroup path}/memory.pressure. Now you can open the file and write a trigger as per the docs.

Sample code here: https://github.com/SUPERCILEX/clipboard-history/blob/e91b80a482e019f1c3af5b3898678ee3aa8384c1/server/src/reactor.rs#L134-L166


Edit: code from my answer to a comment so the formatting works:

let stop = Arc::new(AtomicBool::new(false));

thread::spawn({
    let stop = stop.clone();
    move || {
        let time = Instant::now();
        let mut ll = LinkedList::new();
        loop {
            if stop.load(Ordering::Relaxed) {
                break;
            }

            ll.push_back([time.elapsed(); 10000]);
        }
    }
});

// --- In the poll fd for low mem

stop.store(true, Ordering::Relaxed);
Source Link

The answer is to first read /proc/self/cgroup, trim the starting 0:: and trailing \n, then append that path to /sys/fs/cgroup and append to that /memory.pressure. It'll look like this: /sys/fs/cgroup${cgroup path}/memory.pressure. Now you can open the file and write a trigger as per the docs.

Sample code here: https://github.com/SUPERCILEX/clipboard-history/blob/e91b80a482e019f1c3af5b3898678ee3aa8384c1/server/src/reactor.rs#L134-L166