Skip to content

tor-memquota: Memory tracking differs greatly from reported system memory usage at low amounts

This is a known/expected limitation, but I think it's worth making a tracking issue for anyways.

The tor-memquota system is designed to track how much memory is used by streams/circuits/channels, and destroy some once they in total use a certain amount of memory. At large scales where max is set to GiBs, the "memory used by streams/circuits/channels" is probably close enough to "memory used by the arti process" that they can be thought of as interchangeable.

For low memory limits, the gap widens and they can't really be thought of as interchangeable. For example if a user sets max to 50 MiB (which sets a low_water of ~35 MiB), arti uses around 100 MiB of memory (according to podman stats, which I believe comes from the cgroup memory.stat) before the reclamation begins. If a user sets system.memory.max="50 MiB" in their config file, they might expect arti to not use more than 50 MiB of memory. And on mobile devices, it might be nice to have more accurate memory tracking. For example orbot on iOS uses a MaxMemInQueues of 10 MB.

Maybe we could track other large structures in memory, such as descriptor-related structures (or do we use file-backed maps for these?). We wouldn't want to reclaim them, but it might be useful to include them in the tracking. There will of course be other things we can't track, or don't want to track as it would make the code too messy.