Zsh kills Python process with plenty of available VM

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 (I can see this through get info) however, once about 40 or so swapfiles are created, for a total of about 40GB of virtual memory occupied (and thus still plenty of available space in VM), zsh kills the python process responsible for the RAM usage (notably, it does not kill another python process using only about 100 MB of RAM). What's going on here? All the documentation I was able to consult says macOS is designed to use all available storage on the startup disk (which must be the one I am using since I have only one disk and the available space aforementioned reflects this).


Then why zsh kills the process with so much available VM? Also, 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). One last note, I do not have administrator rights on this device, so I could not run dmesg to retrieve more precise information, but I doubt my employer put a cap on RAM usage on my profile, since this should not be possible on macOS and even if it were, I suppose it would show when I get info when I check the available space in VM.


Thanks for any insight you can share on this issue, is it a known bug or something? I could not find anything recent on it.

MacBook Pro 13″

Posted on Dec 6, 2025 6:47 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 6, 2025 1:50 PM

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'.

34 replies

Dec 9, 2025 8:19 AM in response to gggg87

gggg87 wrote:

I run the following python script in a the same conda environment to see if conda is at fault here>
...
this gets killed by zsh once about 9GB of VM are occupied. I think this is a pretty strong lead on conda being the problem

Conda is only relevant in terms of complicating your setup. You claimed to be trying to start the script without zsh, yet you are still getting messages via zsh. That suggests that your attempts to change your shell from zsh to something else are being thwarted by Conda.


The specific shell being used is irrelevant. If Conda is causing a problem, it might be because, in addition to running a different shell, Conda might also be running an entirely different version of the script than what you expect. This could simply be a bug that was fixed 4 months ago, but Conda is still running the old buggy version.


It is the operating system kernel that is killing the process. zsh is not involved other than being the messenger of bad news.

Dec 9, 2025 5:24 PM in response to gggg87

gggg87 wrote:

I think this is a pretty strong lead on conda being the problem here (or python itself perhaps?) but not gurobipy.

Neither conda nor python are responsible for the process being killed. It's using too much RAM and the kernel is killing it.


I don't know the details of how the memorystatus architecture works. It's a big issue on iOS because RAM is so limited. And since macOS is just a "flavour" of iOS, it exists there too, albeit with different parameters.


You might want to try asking your question in the Apple Developer forums. There are actual Apple developer support engineers who might know the details of how memorystatus works on macOS, possibly even how you could disable it or work around it. To be honest, they're usually surprisingly accommodating to people asking funky questions like this. I guess it's a nice break from all the scammers who are complaining about getting their apps rejected.


Dec 10, 2025 5:28 AM in response to Luis Sequeira1

I agree with you that the issue must lie in the conda environment. And thanks a lot for checking that other languages work better. So I will try with an environment created with venv instead, bypassing conda, just as in my Linux machine. conda makes installing gurobipy very straightforward with certain licenses, it also has a very nice IDE, that is why I was using it, but it is quite clear that the price to pay is not worth it in my case. The theory is that a conda environment should not interfere with how the OS works, and only the IDE curbs memory usage at 6GB, but from terminal it should work as if it is not even there. But it is clear that in practice things are different. Luckily a slightly more convoluted licensing can be used with gurobi and just python and I will try that now.


Regarding the shell, somehow I think changing the shell in the terminal settings does not really change the shell as an environment variable. While the terminal settings clearly show in the shell folder /bin/bash, if I echo $SHELL I get zsh, and every time I open a new terminal page I get a warning that the standard shell is zsh and how I can change back to that. So somewhere zsh is still the default and that's perhaps why kernel messages come through zsh still, even though the syntax I use to, say, open GUI applications etc, is the bash one (I hate having to go through the all zsh wrapping with open and -a etc to just do something as simple as "gedit file_name").


Regarding activity monitor, that never get stuck for me of course, since the job gets killed way before vm reaches critical values. It just shows high pressure (yellow, but never red, other than a thin red edge on top of the yellow area).


Finally, a question: you say your memory usage went up to 130GB, what was the total still available in the VM volume? Was it little (I would expect the OS leaves some extra space to spare for good functioning of an ssd, but I would expect that to be, say, no more than a quarter of the total capacity only)?

Dec 10, 2025 7:28 AM in response to gggg87

gggg87 wrote:

I agree with you that the issue must lie in the conda environment. And thanks a lot for checking that other languages work better. So I will try with an environment created with venv instead, bypassing conda, just as in my Linux machine. conda makes installing gurobipy very straightforward with certain licenses, it also has a very nice IDE, that is why I was using it, but it is quite clear that the price to pay is not worth it in my case. The theory is that a conda environment should not interfere with how the OS works, and only the IDE curbs memory usage at 6GB, but from terminal it should work as if it is not even there. But it is clear that in practice things are different. Luckily a slightly more convoluted licensing can be used with gurobi and just python and I will try that now.


The more you post about that app, the worse it appears; the closer to a research project or one-off or prototype.


Regarding the shell, somehow I think changing the shell in the terminal settings does not really change the shell as an environment variable. While the terminal settings clearly show in the shell folder /bin/bash, if I echo $SHELL I get zsh, and every time I open a new terminal page I get a warning that the standard shell is zsh and how I can change back to that. So somewhere zsh is still the default and that's perhaps why kernel messages come through zsh still, even though the syntax I use to, say, open GUI applications etc, is the bash one (I hate having to go through the all zsh wrapping with open and -a etc to just do something as simple as "gedit file_name").


This message?


The default interactive shell is now zsh.

To update your account to use zsh, please run chsh -s /bin/zsh.

For more details, please visit Use zsh as the default shell on your Mac - Apple Support.


The message is telling you your login shell is bash, not zsh, and that the bash shell is old and deprecated. The linked article has details in how to change the default, as well as how to suppress the deprecation warning ifmyou want to keep the very old version of bash as the default.


Finally, a question: you say your memory usage went up to 130GB, what was the total still available in the VM volume? Was it little (I would expect the OS leaves some extra space to spare for good functioning of an ssd, but I would expect that to be, say, no more than a quarter of the total capacity only)?


Usual free percentage recommendations is probably most of ten percent free on a smaller SSD, and five percent or so on a larger. Running close to the capacity is not the greatest idea with an SSD, too.

Zsh kills Python process with plenty of available VM

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.