gggg87 wrote:
On a MacBook Pro, 16GB of RAM, 500 GB SSD, OS Sequoia 15.7.1, M3 chip, I am running some python3 code that requires lots of RAM and sure enough, once physical memory is exhausted, swapfiles of about 1GB each start being created, which I can see in /System/Volumes/VM. This folder has about 470 GB of available space at the start of the process
Really? Are you sure about that? That computer would have to be practically empty. Note that when macOS tells you about "available" storage, it's talking about many different things, and only one of them is truly "free" storage.
I changed the shell from zsh to bash, not sure whether this makes a difference (though it is still zsh that kills the process, not bash).
It's not zsh that's killing the process. It's the kernel. Although this statement does have me concerned.
on macOS I run it in a tmux session from which I activate a conda environment
Perhaps you should have led with that. This alone would easily explain my concerns above. First of all, macOS doesn't come with Python, so there's that. Once the world "conda" enters the chat, all bets are off.
I have no way to even open /var/log/system.log due to lack of permissions (in the console I can only see log reports
Logging on macOS is a nightmare. It does require root to see the logs. You'll never find them looking at /var/log/system.log or any file. You can get a live stream using Console or use the "log" command line tool, after learning the predicate language, of course.
I was able to reproduce some version of this. I can run a Python script that just starts allocating memory. Once it hits 87 GB, it gets killed. When my Python script crashed, it reported the following in Console:
default 16:08:49.519563-0500 kernel memorystatus: killing largest compressed process Python [39054] 86002 MB
My app was definitely using only compressed RAM. I wasn't getting any swap usage.
But the executioner here is the iOS "memorystatus" architecture.
And no, that's not a typo. You're just using a really big iPhone. 😄
So where to go from here? You can research "memorystatus" if you want. I don't know if there's a solution.
Keep in mind that there's a fundamental problem here. You don't have that much RAM. Assuming there isn't some huge bug or memory leak in the script, then it's simply trying to use VM as a data store. That's really not a good idea. Even if it works, it would be really slow. Sure that will work for Linux, because you can turn everything off and tweak it in any number of ways. That's not allowed for iPhones.
The most likely problem is simply a buggy Python script. You've already said that similar code runs for weeks with no problem. How is this code different?
Do you need to run this on a Mac? I've seen cases of needing to run one specific script that absolutely must have crazy amounts of RAM. An easy solution is an AWS EC2 instance with crazy amounts of RAM. Running it for an hour or two might cost you $12.
At the other extreme, I've seen people convinced that they were doing Really Important Work and their scripts really needed crazy amounts of RAM. Rather than test for $12, they bought 5 Linux servers with 1 TB RAM @ $20,000 each. As you can imagine, it was really awkward when I fixed the bug. 😄 Did I mention the bug was related to a conda-style environment? 😄 Just sayin'.