> On Windows, Firefox gets a notification from the operating system (setup using CreateMemoryResourceNotification) indicating that the available physical memory is running low.
I've longed for such a mechanism in Linux, but I don't think it exists. This should at least be an OS-level signal IMO, though a D-Bus interface could also work. Integrating with one of the recent userspace OOM daemons could be a good idea.
This isn't the same thing as detecting how much memory is available because Linux overcommits by default. PSI will tell you when the kernel is swapping too much (depending on the thresholds you set) and from that you can infer the user is running low on memory.
Android's lowmemkiller had an explicit free memory threshold userspace could set to be notified. Starting with Android 11 however it's now using PSI too IIRC.
IIRC on Linux, it overcommits when allocating, so you can keep mallocing memory beyond capacity and it won't actually fail until you go to use that memory.
The GP is describing a signal that your application can react to, not a behavior of allocation failure.
Linux could use some improvement on both. The idea that you always have enough swap and can send everything not used there is wrong. Applications know better how they behave a low-memory than the kernel.
I've longed for such a mechanism in Linux, but I don't think it exists. This should at least be an OS-level signal IMO, though a D-Bus interface could also work. Integrating with one of the recent userspace OOM daemons could be a good idea.