Accelerating the Performance of Rosetta in Linux VMs on Apple Silicon

(developer.apple.com)

119 points | by transpute 3 hours ago ago

36 comments

  • commandersaki an hour 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 an hour 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 37 minutes 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 35 minutes 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.

      • pjmlp an hour ago

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

    • cassepipe 22 minutes ago

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

    • therealmarv an hour ago

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

      • commandersaki 43 minutes 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 an hour 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 40 minutes 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.

  • physicsguy 2 hours 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 2 hours ago

      Rosetta has AVX2 support as of this year.

      • physicsguy an hour ago

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

    • galad87 2 hours 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.

  • saagarjha 3 hours ago

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

  • gttalbot 2 hours ago

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

    • pixelesque 2 hours 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 2 hours ago
      • londons_explore 21 minutes 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...

      • mschuster91 16 minutes 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.

  • therealmarv an hour 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).

  • adrianmoisey 2 hours ago

    Anyone know if tools like Docker or colima use this?

    • saagarjha 2 hours 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 2 hours ago

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

      • adrianmoisey 2 hours ago

        That uses rosetta, but does it use this feature?

        • lloeki 2 hours 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
          • rcarmo an hour ago

            Well, at least the Colima developers can consider making that patch standard in their build process.

          • adrianmoisey an hour ago

            Thanks for the clarity! I hope they add it.

      • delduca 2 hours ago

        How about OrbStack?