How fast is a macOS VM, and how small could it be?

(eclecticlight.co)

105 points | by moosia 4 hours ago

11 comments

  • fouc 3 hours ago
    >Starting with 4 virtual cores and 8 GB vRAM, where the VM ran perfectly briskly with around 5 GB of memory used, I stepped down to 3 cores and 6 GB, to discover that memory usage fell to 3.9 GB and everything worked well. With just 2 cores and 4 GB of memory only 3.1 GB of that was used, and the VM continued to handle those lightweight tasks normally.

    Good reminder that there's a certain amount of memory tied up with each core (probably mainly page cache and concurrency handling etc).

    • adrian_b 18 minutes ago
      As a general rule, also the amount of physical memory installed in a computer should be proportional with the number of hardware threads provided by its CPU.

      Besides the fact that the operating system may allocate some memory for each thread, when you launch a multi-threaded application that is able to use all available threads, for instance the compilation of a big software project, it frequently will allocate some working memory in an amount proportional with the amount of working threads.

      I have encountered many multi-threaded applications that need up to 2 GB per thread to work well.

      This corresponds to having 64 GB for a desktop CPU with 32 threads, like Ryzen 9 9950X.

      For the compilation example, I have seen software projects, like Chrome/Chromium and its derivatives, where if you do not have enough memory, proportional to the number of hardware threads, e.g. when you have only 32 GB for a 16 core/32 thread CPU, you must reduce the number of concurrent compilations, e.g. with an appropriate parameter to "make -j", leaving some threads and cores idle, because otherwise you may encounter out-of-memory errors.

    • fulafel 38 minutes ago
      I'd bet for the null hypothesis: the memory behaviour changes would hold if the core count was kept constant and only the VM's memory size was adjusted.
      • brookst 34 minutes ago
        Agreed. This is the OS adapting to available memory.

        Similarly if you started with 4GB and there was 900MB available for user apps, I expect you could launch apps that consume 1500MB just fine; the OS is leaving enough to launch anything, and making use of unused memory for cache/etc.

    • wutwutwat 29 minutes ago
      There is some overhead per-core, you're right, but imo this reduction in usage is likely from how the kernel allocates available memory, which is being reduced as well. The kernel will keep read caches around longer with more memory, it'll prefer to compress memory instead of swap to disk if it has more, it'll purge/cleanup reclaimable memory less often with more memory, etc. It even scales its internal buffer sizes and vnode tables depending on total memory.

      All good things imo, it dynamically makes the most of what is available, at the expense of making it harder to see a true baseline of hard min requirement to operate.

      Fun things to check, `vm_stat`

      $ vm_stat Mach Virtual Memory Statistics: (page size of 4096 bytes)

      Pages free: 230295.

      Pages active: 1206857.

      Pages inactive: 1206361.

      Pages speculative: 31863.

      Pages throttled: 0.

      Pages wired down: 470093.

      Pages purgeable: 18894.

      "Translation faults": 21635255.

      Pages copy-on-write: 1590349.

      Pages zero filled: 11093310.

      Pages reactivated: 15580.

      Pages purged: 50928.

      File-backed pages: 689378.

      Anonymous pages: 1755703.

      Pages stored in compressor: 0.

      Pages occupied by compressor: 0.

      Decompressions: 0.

      Compressions: 0.

      Pageins: 832529.

      Pageouts: 225.

      Swapins: 0.

      Swapouts: 0.

      edit: no code fence markdown support or am I doing something wrong?

  • Havoc 1 hour ago
    Got a M5 air recently - my first dive into MacOS land so trying to figure this out too.

    Seems essentially impossible to get:

    * pytorch

    * GPU acceleration

    * VM/container like isolation

    The virtio-gpu layer gets closest but seems to only pass through graphics GPU not compute GPU so no pytorch

    • plufz 1 hour ago
      I need this too, and looked quite a lot on it a year ago. I haven’t had time to check out the recent developments with Docker Model Runner (vllm-metal) or podman libkrun. Did neither of those work for you?
      • Havoc 41 minutes ago
        vllm-metal isn't GPU access but rather a openai compatible end point which I can already do via lm studio endpoint over network

        >podman libkrun

        Haven't tried it but research suggests its really shaky still. podman libkrun exposes vulkan while torch expects mps on macs. Sounds like one can force vulkan but that's apparently slow and beta-ish?

    • emmelaich 40 minutes ago
      I got torch to run in a Cirruslabs Tart instance.
  • nasretdinov 2 hours ago
    Honestly macOS probably can go much lower than that if you turn off some stuff that's not strictly necessary for a VM. The first iPhones only had 128 MiB of RAM and they ran a trimmed down version of macOS Tiger I believe. It's just that RAM has been quite abundant so far, so there was no real reason to try to trim it down, but it's definitely possible, and probably not that hard either, we just need to start trying again :)
  • dhruv3006 1 hour ago
  • nottorp 3 hours ago
    > Starting with 4 virtual cores and 8 GB vRAM, where the VM ran perfectly briskly with around 5 GB of memory used

    But... if you start applications inside your VM it will want the full 8 Gb you've allocated not the 5 Gb it uses at startup?

    • stingraycharles 3 hours ago
      I don’t assume that macOS virtualization is advanced enough to support memory ballooning, or is that not what you’re referring to?

      Edit: I stand corrected!

      • pyth0 3 hours ago
        I don't assume anything either, but a single Google search is enough to dispel that [1]

        [1] https://developer.apple.com/documentation/virtualization/vzv...

      • sgt 2 hours ago
        macOS is generally pretty amazing at efficient memory usage and VM (virtual memory subsystem) handling. So even a 8GB machine can run pretty impressive workloads without having the user think the machine is underpowered.
        • p_ing 1 hour ago
          Not really. Larger page sizes mean more potential for wasted memory and it has had a long standing memory leak in some core component to where even Calculator can cause an OOM event.
          • jdiff 47 minutes ago
            GP is pretty accurate in my experience. Up until last year I was still running an Intel MacBook Pro with 8GB of RAM and successfully multitasked with Blender, Illustrator, Unity, VS Code, and Firefox quite often. The math doesn't make sense, but all stayed responsive even with frequent hops between them. The only OOM events I ran into were memory leaks from Firefox, I believe from an extension.
            • p_ing 41 minutes ago
              There's nothing particularly interesting about that. Linux distro-of-your-choice can run the equivalents fine, as can Windows.

              Browse /r/macos if you dare to wade into the uninformed cesspool; it's full of OOTB apps causing OOMs (among 3rd party apps) with the past at least two major versions of macOS.

      • nottorp 3 hours ago
        What will that help with if the host and guest combined need > physical ram?
        • jdub 2 hours ago
          If guest memory can be reclaimed, it doesn't need to be paged to disk once you hit RAM contention. It's mostly saving accounting overhead, but it'll have some effect on latency, which you're more likely to perceive under contention.
  • mgaunard 2 hours ago
    My only experience with VMs on macOS is colima+docker, and it's relatively painful and inefficient (but usable).
    • woadwarrior01 22 minutes ago
      Try Apple's container CLI. I moved a project of mine from colima+docker to it relatively easily, a couple of weekends ago.

      https://github.com/apple/container

    • embedding-shape 2 hours ago
      Recently got a Mac Mini for local CI purposes (together with Forgejo Actions), took a broad look at the ecosystem and decided to just roll with "build on host" instead. Setting up signing/notarization just looked like an insurmountably task together with isolating it from the host, even with agents. At least the macOS builds are really fast now and the signing/notarization just ~200 lines of Bash...
      • latexr 2 hours ago
        > the signing/notarization just ~200 lines of Bash

        200 lines?! That’s two orders of magnitude too many. What exactly are you doing that you need so such code for signing and notarisation?

      • yohannparis 2 hours ago
        Could you share your recipe please ? I’m interested
  • collabs 1 hour ago
    I was hoping to see the bare macOS with all the applications removed as much as possible, no graphical user interface, just the bare minimum to boot, login as a user, and write hello world dot txt with a text editor. Or maybe some command line apps? Or is it no longer macOS at that point?
    • jitl 1 minute ago
      You can boot regular macOS directly to a root terminal in “Single User Mode”. This was easier on Intel macs of yore but is also possible on M1+

      Below content from https://eclecticlight.co/2020/11/28/startup-modes-for-m1-mac...

      Launch 1 True Recovery, open Terminal, then run “bputil -a” (without the quotes) to downgrade system security and allow for more boot arguments. You might need to restart after this step.

      Then, run [nvram boot-args=”-s”] (without the square brackets). Restart to launch Single User Mode.

      Once in Single User Mode, run these commands (in the following order) to mount the root volume group:

      1. mount -P 1

      2. /usr/libexec/init_data_protection

      3. mount -P 2

      Future restarts will always launch Single User Mode first. To stop launching Single User Mode, run [nvram boot-args=“”] (without the square brackets).

      To restore your system to full security, run “bputil -f” (without the quotes). If you choose to run that command in macOS, prefix “sudo” to the beginning.

    • hmry 1 hour ago
      "I'd just like to interject for a moment. What you're referring to as macOS, is in fact, macOS/Darwin, or as I've recently taken to calling it, macOS plus Darwin."

      "What you're referring to as Darwin, is in fact, Darwin/XNU."

      "What you're referring to as XNU, is in fact, BSD/Mach."

      I seem to remember it being possible to run macOS-less Darwin several years ago, not sure if that's still possible or if Apple has modified it so much at this point that it's useless without at least some macOS components.

  • dieulot 3 hours ago
    I'm wondering if the Xcode simulator (without Xcode running) performs as well, my 2020 Intel MacBook Air has been incapable of running Safari in iOS smoothly for nearly all its life.
  • aykutseker 2 minutes ago
    [dead]
  • shawryadev 1 hour ago
    [dead]
  • vk6flab 2 hours ago
    [dead]