Accelerating the Performance of Rosetta in Linux VMs on Apple Silicon

(developer.apple.com)

136 points | by transpute 10 months ago ago

49 comments

  • commandersaki 10 months ago

    Rosetta 2 for Linux is my favourite feature of Mac at the moment. I've been working on a project for many years that had a hard dependency on a library that only compiled on amd64 architecture. So for the longest time I was dual wielding a Mac and Framework laptop. I really hated switching between the two and moreso using Linux on my Framework; just felt like a bleh experience. When Rosetta 2 for Linux came around, I immediately started using it and was fully productive developing on our Intel only projects. I don't see any perceivable speed loss, t hough we had to adjust some sleeps for a few concurrency/threading tests to accommodate Rosetta.

    Apple really did not have to make Rosetta 2 available for Linux. If they hadn't, it wouldn't even register a blip on the users / market share of Macs/MacOS. But it's just one of those hidden gems of the OS, and going by this article they haven't stopped improving on it.

    • arghwhat 10 months ago

      > Apple really did not have to make Rosetta 2 available for Linux.

      The kinda did - offering good Linux dev environments is now a fairly big feature for both of the major Desktop OS's nowadays.

      • commandersaki 10 months ago

        Most Linux dev environments do not need to be tied down to Intel. In fact it is more performant and efficient if you're working on ARM native on Linux. It was already a good Linux dev env before Rosetta 2 was on the scene, they just enabled more use cases with Rosetta 2.

        • iforgotmysocks 10 months ago

          I also do not see much need for Rosetta support for Linux as arm64 Linux works fine for most of my use cases. However it is definitely better to have Rosetta support than not having it.

        • arghwhat 10 months ago

          This unfortunately only holds when working purely on open source. Shipped binaries for aarch64 are still not super common for proprietary things within the enterprise space.

      • 10 months ago
        [deleted]
      • pjmlp 10 months ago

        And the only way Desktop Linux will actually grow beyond the usual 1%.

        • ChocolateGod 10 months ago

          I don't think it counts as Desktop Linux if its running in a CLI-only VM targeted at developers on a different host OS.

          • pjmlp 10 months ago

            It may not count, but that is what you will get in most shopping malls as "Desktop Linux" for common folks.

            Even if you add Chromebooks as third option, Crostini runs in a VM just like WSL 2, and still has quite a few integration issues to this day.

            Netbooks could have been it, but first they were torpedoed with Microsoft's clever move to make Windows XP licenses free for those OEMs, followed by the introduction and wide adoptions of tablets.

            OEMs like Tuxedo or System 76 will remain a niche compared to how many people end up running GNU/Linux on desktop VMs.

            Before WSL I had long moved away from dual boot into VMWare Workstation.

          • cassianoleal 10 months ago

            It works on GUI VMs as well. UTM makes it very easy to use.

            I agree it still doesn't help much with the desktop Linux bit though. :D

          • the8472 10 months ago

            WSL runs GUIs too. And so did things like vmware and virtualbox for many years before it.

        • arghwhat 10 months ago

          Which, to be fair, is something like tens of millions of Linux desktops. Several orders of magnitude less than the other types of Linux-powered computers out there though.

          No one cares what the relative numbers are. As long as there is enough absolute users to justify the effort.

          • pjmlp 10 months ago

            Yeah, but those other ones don't run GNU/Linux for normies, which was the whole premise of The Year of Linux Desktop meme started on the last century.

        • anonzzzies 10 months ago
    • therealmarv 10 months ago

      May you explain how you use it practically? How do you get it working in your choice of Linux?

      • commandersaki 10 months ago

        I do it all via docker. I execute `docker --platform linux/amd64 <run|build>` and it uses Rosetta 2 for Linux in the VM (colima sets the rest up automatically).

    • wslh 10 months ago

      Curious about your setup, especially regarding GUI support: are you running Rosetta in the GUI VM? I haven't tried Rosetta yet myself, and I'm considering options for a stable Linux VM (not frequently creating and removing VMs). I'd appreciate any insight!

      Also, reading through this thread has given me an "aha" moment about the under-the-radar innovations Apple is building. Many people criticize Apple without understanding these aspects, and I’m not an Apple fanboy. I had similar realizations with Microsoft’s .NET, which I still believe is incredible underrated.

      Lastly, how does running the Linux VM impact battery management efficiency?

      • commandersaki 10 months ago

        I only run Rosetta 2 for Linux via `docker --platform linux/amd64 <run|build>` which triggers the rosetta helper in the underlying docker VM to do the right thing. I use colima for a docker VM which sets up Rosetta 2 automatically.

        I don't know anything about GUI use; I don't run Linux for GUI stuff.

        Linux VM affects battery proportional to how much you use it. For example when I build our projects that take 12 minutes running across all cores, I'm using the laptop at 100%. When I'm not using docker, the VM is idle, and therefore doesn't really impact battery whatsoever.

    • cassepipe 10 months ago

      May I ask what felt wrong with Linux on the Framework ?

  • physicsguy 10 months ago

    Biggest issue I run into now with Rosetta + Linux VMs/Docker is not having support for translating the AVX vector extensions, since they're becoming more and more common in compiled binaries. For more popular things there's typically an ARM image but that's by no means guaranteed, and compiling your own to support ARM can be quite involved.

    • saagarjha 10 months ago

      Rosetta has AVX2 support as of this year.

      • physicsguy 10 months ago

        Ha! Well that’s my employer keeping us on 14 for now then to blame for that one.

    • galad87 10 months ago

      The latest version of Rosetta on macOS 15 can translate up to AVX2. However I don't know if the capability is enabled by default or exposed in the Linux VMs.

      • gainsurier 10 months ago

        I just tried it, and it did not work. AVX2 f is still not support in Rosetta on macOS 15 for Linux VMs.

  • saagarjha 10 months ago

    (This also works on baremetal Linux, though Apple of course does not support that usecase.)

  • therealmarv 10 months ago

    Patching the Linux Kernel... one of the things I don't want to do ever as a normal user (even if I'm a developer).

  • gttalbot 10 months ago

    Is Apple going to upstream this so it's part of Linux?

    • pixelesque 10 months ago

      Apple submitted a patch, and then Hector Martin of Asahi Linux also submitted an alternative:

      https://lore.kernel.org/lkml/20240411132853.GA26481@willie-t...

      but it was rejected due to concerns of fragmentation and it being non-standard...

    • saagarjha 10 months ago
      • mschuster91 10 months ago

        Finally. Some long time ago I filed a ticket for UTM and QEMU if TSO (and Rosetta) could be used for VMs because x86 VMs on ARM CPUs are dog slow at the moment, but back then this wasn't on the horizon. Good to see Apple themselves are working on it.

      • londons_explore 10 months ago

        > This program will hang indefinitely if TSO is in use, and will crash almost immediately if it is not in use.

        So now we just need to solve the halting problem, and we'll have our answer...

        • saagarjha 10 months ago

          Unfortunately there’s not really a better way to detect memory models except by trying to observe reorderings :(

  • adrianmoisey 10 months ago

    Anyone know if tools like Docker or colima use this?

    • saagarjha 10 months ago

      I don't think anyone is using this, given that the register it touches was not really officially documented until now. Maybe the OrbStack people were crazy enough to try?

    • speedgoose 10 months ago

      For colima, you can add --vm-type=vz --vz-rosetta to the start command. It's qemu by default.

      • adrianmoisey 10 months ago

        That uses rosetta, but does it use this feature?

        • lloeki 10 months ago

          AFAICT no because it needs a kernel patch which is not applied in the base Linux system colima is using:

              $ colima ssh
              $ dpkg -l |grep linux-image
              ii  linux-image-6.8.0-31-generic   6.8.0-31.31                       arm64        Signed kernel image generic
              hi  linux-image-virtual            6.8.0-31.31                       arm64        Virtual Linux kernel image
      • delduca 10 months ago

        How about OrbStack?

        • 10 months ago
          [deleted]
  • 10 months ago
    [deleted]