Try to ensure a certain percentage of free disk space, based on usage pattern, just like we're already ensuring a certain percentage of free memory space (based on usage).
The program already tries to obey the "false ceiling" set in the filesystem for regular users (who typically get to see a smaller disk size than root, so a disk can sometimes be e.g. "105% full") but it is a fixed percentage. We may want to adapt that to actual usage patterns of disk space, so the program can see that disk is filling up and swap files should be released if possible.
There is no definite answer I guess, but if the disk fills up in a situation where lots of swap space is in use may be a case of data being saved before a program can be closed. Almost certainly the safe thing to do is to give persistent data (i.e. the filesystem) priority over volatile data (i.e. virtual memory) when disk space allotment comes to a head.
This ticket is based on a suggestion by Bart Samwel, who didn't have time to enter a request here. Thanks Bart!