The Linux kernel has a bad habit of letting RAM fill up with data that needs to get written back to disk; the jargon term for this is “dirty pages.” Once RAM is full of dirty pages, if something tries to allocate a lot of RAM all at once (e.g. this happens when a large program starts up) the kernel will have to do a whole bunch of disk writing all at once before it can satisfy the memory allocation request. I think this is the #1 actual root cause of Linux-based systems grinding to a halt with the disks going flat out.
Try the settings here and tell us whether that helps: Avoid Linux locking up in low memory situations using earlyoom - #19 by zwol.
(see also Initiating writeback earlier [LWN.net] )