Daniel Eran Dilger
Random header image... Refresh for more!

iPhone OS X Architecture: the Mach Kernel and RAM

iPhone OS X Architecture: the Mach Kernel and RAM
Daniel Eran Dilger
A number of people are working to crack open the iPhone in order to use it on alternative mobile networks or to install or modify software. What they are finding is more interesting to me because it reveals hints as to what latent features of the iPhone remain to be unlocked in software. Here’s a look at what’s been discovered about the core OS inside the iPhone, starting at the kernel.

En Español:
La arquitectura del OSX del iPhone: el kernel Mach y la RAM – planetamac
Traducción: Oscar Reixa

[Leopard, Vista and the iPhone OS X Architecture]
[iPhone OS X Architecture: Disk, Shell, and Password Security]
[iPhone OS X Architecture: the BSD Unix Userland]
[iPhone OS X Architecture: Cocoa Frameworks and Mobile Mac Apps]

The iPhone Kernel.
Yes it’s Mach. Remember how many so-called experts insisted that Apple was stuck with Mach, but would move to the Linux kernel in a heartbeat if only it could, and perhaps as soon as Mach maven Avie Tevanian left Apple?

I countered the initial rumors that Apple would move to the Linux kernel last year, and repeated the same thing before WWDC 07, when the meme evolved into an imminent migration to Sun’s Solaris kernel.

There’s nothing wrong with Mach. In reality, it fits Apple’s needs quite well. If Apple were desperate to jump to some other OS architecture, the iPhone would certainly be the place to ditch its existing kernel and run with something else, just as Microsoft created a new kernel for Windows CE rather than using the NT kernel from its Windows NT/2000/XP/Vista desktop products.

[More Predictions for WWDC 2007: Solaris, Google, Surround: Mac OS X with the Solaris Kernel]
[The Microkernel Myth: What is Mach?]
[The Linux Kernel Myth: Much ado about Mach]
[OS X vs. WinCE: How iPhone Differs from Windows Mobile]

Kernel Extensions.
The iPhone’s Mach kernel uses the same I/O Kit architecture as Mac OS X, allowing Apple to reuse a lot of the mature code that is already proven to work on the Mac. The I/O Kit in Mach uses kexts or kernel extensions to add low level hardware support.

Because they plug into the kernel, it is critical that they are as solid and mature as possible. When software crashes outside of the kernel, it can usually be restarted. When something crashes within the kernel, it results in a kernel panic and the system becomes unusable and has to be rebooted. That’s bad.

Apple recommends against adding kernel extensions to Mac OS X unless there is no other way to accomplish the task at hand. That’s why people complain when they find third party software installing kexts without good reason; it frequently results in stability problems.

Apple has followed its own advice by using only two sets of kexts in the iPhone. The first sets up USB input, specifically for a user human interface device, and more specifically the multitouch screen:

• IOUSBDeviceFamily
• IOHIDFamily
• AppleMultitouchSPI

The second pair of extensions relate to VPN or Virtual Private Networks. These extensions tie into the network stack to provide a way to securely tunnel encrypted traffic over a public network like the Internet.

• L2TP.ppp
• PPTP.ppp

[The iPhone Dev Wiki]

Comparing the iPhone Kernel to the Mac’s.
The iPhone’s kernel and kexts are not identical to the Mac. For example, desktop Macs have kexts for the iSight camera, audio and video hardware, power and thermal management, and serial interfaces. The iPhone has no kext equivalents for any of these, despite having the hardware. The iPhone’s PPP.kext is also missing.

It appears that support for all of the hardware in the iPhone is built into the iPhone’s kernel, rather than being implemented as a kext. On the Mac, different models have different hardware, so a modular set of plugin is required. There is currently no variety in the hardware in shipping iPhones.

Having the I/O Kit architecture in place on the iPhone demonstrates Apple plans to expand hardware support in the future, and won’t have to resort to bolting on support for an extension mechanism after the fact. Because Mach and I/O Kit were built from the start to accommodate a wide range of hardware, the iPhone was able to inherit this functionality and use it as is without returning to the drawing board to build a “mobile OS kernel.”

Among the things accounted for in Mach is sophisticated power management, which intelligently powers up planes of devices as the system goes into standby or to sleep. That helps explain why the first generation of the iPhone has remarkable battery life, commonly twice that of comparable smartphones.

[KernelCache Files List – The iPhone Dev Wiki]

System RAM and Flash RAM.
Another significant difference between the iPhone and other smartphones relates to system RAM and Flash RAM storage. The pundits haven’t said anything about this, because it is embarrassing to other manufacturers, and it is apparently politically incorrect to point out that the iPhone blazes a new trail in technology.

On the iPhone, there are no physical disk drives, only flash RAM disk images, which work like standard DMG files on the Mac desktop. A desktop DMG file contains an archived copy of the contents of a drive. When mounted by Mac OS X, it behaves just like a physical drive, although it is faster because it doesn’t involve any moving parts; it resides entirely in RAM.

The iPhone can be restored through iTunes just like an iPod. This copies a clean pair of DMG files to the unit. The phone then mounts and runs OS X from the disk image directly from Flash RAM. Other mobiles–including Palm OS, Symbian, and Windows Mobile–have a similar “run from Flash RAM” architecture.

Thanks for the Memoires: the paltry Flash on Mobiles

The main memory difference of the iPhone over existing mobiles is that most phones have 64 MB of RAM, 128 MB or less of Flash, and consume about 40 MB of their Flash with their OS and applications, leaving little storage for the user. They provide SD Flash RAM slots to add more space, but this is limited to 2 GB of expansion.

The iPhone has either 4096 MB (4 GB) or 8192 MB (8 GB) of Flash RAM installed. It consumes about 700 MB with OS X and its applications. It also contains 128 MB of system RAM used by the running applications. That’s twice the system RAM and 64 to 128 times the Flash RAM storage.

It’s also why the iPhone doesn’t need an SD card slot. It already has 2 – 4 times more Flash installed than users other phones can potentially add using SD Flash cards.

That helps explain why the iPhone can offer real Internet apps, and why Palm, Windows Mobile and Symbian are not going to catch up in functionality without entirely rewriting their mobile operating systems.

[Update: A number of readers asked about SDHD Cards, which offer more than 2 GB of Flash, but only work with new hardware specifically designed to support the SHDH standard. Earlier SD slot phones can’t use them. Only a few high end phones can use SDHD, and the N95 is one of them. Adding 8 GB to the N95 via SDHD is another ~ $250 over its $750 price tag, putting it at a very different price target than the iPhone.]

[Apple’s OS X: How Does it Fit on the iPhone?]

Where’s the Kernel?
One last thing that’s different about the kernel on the iPhone and the Mac: its location. On a Mac, the Mach kernel is loaded into RAM from the standard boot disk as the system starts up. Not only does it sit in plain sight, but the Mac’s kernel is also available as part of Apple’s Darwin open source project, so developers can peruse its code to better understand how it works.

The iPhone is running a related port of the Mac OS X kernel, but it is not open source. It’s also adapted to the ARM processor architecture, which requires modifications and optimizations for its unique peculiarities.

Take all the people on Earth who know a lot about Darwin and Apple’s Xnu Mach kernel, then isolate those who know much about ARM, and you have a group that could share a couple pizzas. That has implications for the iPhone’s security, as I note in the next article, which will look more at the iPhone’s core OS and security: iPhone OS X Architecture: Disk, Shell, and Password Security.

What do you think? I really like to hear from readers. Comment in the Forum or email me with your ideas.

Like reading RoughlyDrafted? Share articles with your friends, link from your blog, and subscribe to my podcast! Submit to Reddit or Slashdot, or consider making a small donation supporting this site. Thanks!

Technorati Tags: , ,

  • Thomas Menguy


    Don’t get me wrong, I’m found of your rants, and a big iPhone lover…but as an embedded dev myself I can’t let you say:
    “It’s also why the iPhone doesn’t need an SD card slot. It already has 2 – 4 times more Flash installed than users other phones can potentially add using SD Flash cards.

    That helps explain why the iPhone can offer real Internet apps, and why Palm, Windows Mobile and Symbian are not going to catch up in functionality without entirely rewriting their mobile operating systems.”

    It is just plain wrong all the OS you are quoting have the same XIP (execute in place) capabilities you mention, and have no issue addressing all the flash you can throw at them (ok palm excepted, this one is really more like a Mac OS 9 sort of thing :-) ), they are all modern OSes with MMU support, processes, etc…

    Really if Nokia had the same gfx designers and ergonomists than apple (and this is obviously not the case), there IS NO TECHNICAL ISSUES to make an iphone from Symbian+S60 application layer.

    So while the iPhone is a marvellous piece of engineering, the edge it has, software wize, is not about OSX … but more about great software UI designers, and attention to details.

    Having more RAM is not a good sign: it just means that to do roughly the same thing as a Nokia phone, the software needs twice as RAM: normal it is derived from a PC based code base. And more RAM means higher prices more power consumption…and I would personally like a SD port on my iPhone for clean file handling :-)


  • http://www.roughlydrafted.com danieleran

    Thanks for the comment Thomas.

    There actually are significant problems with Symbian due to its unique lineage that make it difficult for developers to approach. Like all OS platforms, after ten years there’s simply cruft that needs to be chucked.

    When an OS becomes so tied to the past that its legacy can’t be jettisoned without losing most of what gave it any value, it is impeded from making further progress.

    So look at the classic Mac OS, which had unaddressed problems by the early 90s. NeXT gave it some short term bandaids, but then scraped off the portions that held up any value and added them to a new foundation. Carbon thus lost much of its legacy problems, and that bridge helped migrate development toward the more modern Cocoa tools. Thus Mac OS X is pretty clean.

    Microsoft is working to do a similar thing to push Win32 development towards .NET, although its working harder to preserve the past. That appears to be a mistake without a clear alternative solution.

    The Palm OS did the worst of all things: port its old cruft onto new ARM hardware (much like the old Mac OS was moved to PowerPC). That just delayed the problems, and Palm is now ancient garbage.

    WinCE never had a significant platform that anyone used for any purpose other than to express faith in Microsoft. It has little future.

    Symbian needs a reworking, but who is going to do it? There are three major camps, and multiple versions of each. At this point, its a lot like making major, decisive changes to Linux. Who would do that and why?

    Without a group with the same kind of clout as Apple has, there will rarely be any major advances to either Symbian or Linux, and when they occur, the community will shun change to keep things familiar. No Linux contributor would fix problems the way Apple did with launchd for example. There’s too much community deliberation that would water down any efforts to change longstanding problems.

    As for Mac OS X vs Symbian on a technical level, the iPhone might require more Flash for its OS X image, but it has a lot of free memory to use. Nokia’s phones might be more efficient in RAM use, but the fact that they have 1/64th the Flash makes that irrelevant.

    The iPhone doesn’t use its Flash primarily to run or store software, but to hold media. Nokia phones need SD cards in order to save photos, view photos, movies, video, music, etc. An 8GB SD card costs about as much as the iPhone itself. SD card slots are also a security issue.

    I had an SD card slot on my Treo for a couple years, and it did two things: inhale dirt and crap into my phone, and serve as a way to get very poor quality photos off because the sync software was so terrible that physical “sneakernet” was more efficient than using a network/USB connection. That’s not elegance.

  • Thomas Menguy

    Thx for the answer …but then again I disagree :-)

    For me it is not fair to compare the iPhone software platform, completely coupled with a dedicated hardware (and a BIG one, with a BIG CPU) to symbian or WinCE that are integrated in an enormous amount of different hardware (phones).
    Also Symbian is more comparable to a kernel (so to the Mach one) on top of it we found the S60 application suites and gfx, completely made by Nokia (UIQ is now sonyericsson and moto), so if Nokia had the muscle and the skills to do something…. they could.

    For WinCE: same thing winCE is a Kernel and winMobbile is the application suite on top of it. When you say:

    “WinCE never had a significant platform that anyone used for any purpose other than to express faith in Microsoft. It has little future.”

    I’m not sure: what we (in the company I’m working for, not at all related to Symbian/WinCE, etc) see today is that all the big Taiwanese ODM are moving to winMob, because they simply have no choice: they are not good at big software, and the only credible license is … MS! (yes nokia tried to license S60 to others but it failed and Linux vendor well…see below)

    For Linux: again it is only a kernel, on top of it multiple vendors are fighting, ( hum struggling :-) ) :
    -QT with Qtopia
    -Access ALP
    -Moto homebrew linux application stack
    -a lot of smaller players .. and
    -Google Android
    -Nokia Hildon (the one in the Nokia Tablet n770/n800/n810) (I have one and I’m fairly impressed, browsing is far more superior to my iPhone…but as a product it lacks A LOT of polish to make it mainstream)

    Linux stacks are just not ready for prime time, and for the biggest chunk of the market….and this is were the comparison is really biased:

    -iPhone is well …the iPhone, targeted to be expensive and to sell perhaps 10 millions phones a year (that would be already a big success, but many small ODM are doing that each year, ok with a very different generated revenue)
    -S60 is targetted to be in the 100$ BOM range … and be sold to hundreds of millions a year, on many many different models, WinMob has the same sort of objectives, but well they are not nokia.

    Plus don’t forget that we are only talking the “smartphone” segment, 10 to 20% of the phone market….the rest being done by very optimized in house software or application framework taylored for very low BOM.

    Anyway for sure it is difficult to develop for Symbian, but the underlying is pretty modern (object oriented kernel, security model, etc), but the higher levels need a bit of rework….that Nokia is doing right now (we will see that with the new UI they have just announced), but I’m pretty sure it won’t be as slick as the iphone for the end user.
    On the MS side…..NET on mobile is just crap, period.

    For MacOS X I just can’t say how clean it ease, I have no expertise with it but it is a 10 years system….so it has legacy, for sure.

    Again: “Nokia’s phones might be more efficient in RAM use, but the fact that they have 1/64th the Flash makes that irrelevant.” I don’t get this particular point, Flash and RAM are uncorrelated ….
    Plus you get your data wrong : check the spec of the nokia n95 8GB:
    – 8 GB internal memory (Flash)
    – 128 MB SDRAM memory
    – ARM 11 332 MHz processor

    => pretty similar to iPhone no? (except the CPU)

    Again don’t take me wrong, I’m an iPhone fan and my Palm Treo, my Nokia S60 6210 and my Samsung WinMob i600 are collecting dust now.
    But it is far from being perfect (especially the telephony part, the photos part is a joke ….and no, for now, 3rd party apps, it is a beta product…but what a beta!!!).

    It’s just that your enthusiasm, while great to read, just forget the completely different industry in which apple is entering, where great companies, like Nokia and SonyEricsson are able to do the whole software+hardware stuff (compared to the PC world where apple is alone with that ability), are creative and have fantastic supply chain, worldwide presence, etc (I know that nokia is not so big in the US, but it is the exception).

    For me we will see interesting stuff from Nokia and Apple in the futur even if apple, for now, is only fighting for the “high end entertainment phone” segment, compared to the pletora of existing market segments covered by Nokia (or SonyEricsson).

    I’m new to this apple world, and it’s great to have this kind of discussion


  • http://www.roughlydrafted.com danieleran

    I agree, it’s fun to look at things and try to figure out where they are going. Whenever somebody tells me things I don’t know, it helps clarify that, so thanks.

    I hear what you’re saying about Symbian and the mass market, but one could have said similar things about DOS PCs in the late 80s: that Macs were expensive graphical toys while cheaper DOS boxes would to all the “work.” That was possibly true in 1988, but rapidly changed. Today, everyone uses a Mac (or the Windows clone thereof).

    I think the same thing is happening with phones. Today, 8GB and a touch screen make for an expensive phone (but not that much more expensive). That will also go down, just like expensive graphics hardware that was the barrier to the GUI on PCs solved itself.

    Also, when you think about the cost of a service plan, which is $1000/year for voice/data, the difference between a $99 phone and a $399 phone is nothing. Why would you kill yourself to carry a POS phone while paying through the nose for service, rather than one that does cool stuff, when the price is only slightly more?

    Analysts all pretty much agree that the market is moving toward smartphones rapidly. What are Symbian partners going to do to get S60 from a basic phone platform into something like the Nokia Internet Tablet? If Symbian could pull that off, why is the N800 Linux based? Is seems like Nokia is stuck between the legacy of simple Symbian and the immaturity of Linux as a mobile OS.

    Apple has the marketing power/retail sales/profitability/expertise to deliver OS and UI advances at a regular clip, as it did with Mac OS X over the last ten years. Nokia hasn’t really done anything similar, and nobody has really done anything compatible in the PC space. Microsoft is struggling to keep Windows up to date, and Linux camps are fighting at cross purposes, both on the desktop and in the mobile space. Therefore, no progress.

    Will be interesting to see how things work out.

  • Thomas Menguy

    Yes , great to exchange …. and here is the next part :-):

    Something few preople and few self called analysts are not seing is the real benefit of the iPhone:
    => it tells to the phone industry that software matters!!! this is where the industry today can’t be compared with its PC counter part in the 80’s: the market is HUGE (more than 1billion phones a year!) with hundreds of actors (of ODM, OEM, etc)…but the software companies are really struggling to make money because historically the software was not important for a phone that …simply have to be a phone: dial a number and answer call (very different from the very nature of a PC even in the 80’s). Thanks to the iPhone (and google android) we see a growing interest for software technologies from all those actors…and they don’t know how to address that!

    Also seeing the phone industry with a US or EU bias is a big mistake: smartphone WON’T, in a foreseeable future take more than 20% of the global phone market (data directly from the chipset vendors) because even if in our countries, as you said, the total cost of ownership of a phone (phone price + service) can erode the device price factor, this is simply not true in india, africa, china when you can pay per call only few cents, and were having a Flashlight in a phone is much more important that music or email :-). Don’t forget that in those countries when you have poor infrastructures (road, landlines, etc), GSM is in many case the only reliable service.

    For the Nokia n800 experiment, I agree with you, for me it is really showing that they think symbian is not the platform of their future …or perhaps they try to see if the open source community can bring value to them … and the lack of software culture and expertise they have today.

    Difficult to predict future, but I won’t see apple taking 75% of the worldwide phone market:
    -It is so huge that to address it you need literally hundreds if not thousand of different models, for different people, etc: apple is simply not big enough and is very good at doing one or two declination of products in a range (this is already a big talent :-) )
    -they lack manufacturing and supply chain knowledge to make money from 20$ phones (only nokia is really able to do that today: for the first time their supply chain has been place on top of .. the automotive giant like toyota, volkswagen, etc)
    -they are very US centric/ US culture (not pun intended): with a strong “not invented here” and “we are doing the right device, we don’t have to listen”, this can be a strentgh but for such a big market with so many segments it simply doesn’t work …

    Anyway For sure apple is a great company with formidable assets, very good at making luxury and cutting edge devices and technologies….And I really hope the iPhone success will pave the way for next generation devices and services. On this last front I’m not sure of their strategy, will they provide “only” music/video? team up more tightly with big service providers like yahoo or google, banking, etc? Futur will tell even if as a service platform android seems stronger (but no device yet…and when they’ll arrive, certainly not as sexy…).

    Long live iPhone…and I’ll continue to have fun using it … till something better comes out! (for the first time of my life I’ll wait for a mac keynote, 15th of january :-) )

  • Pingback: iPhone 2.0 SDK: The No Multitasking Myth — RoughlyDrafted Magazine()

  • Pingback: Does iPhone have Mac’s kernel? « Its Not Tough To Be Different.()

  • Pingback: Apple buying up available flash RAM supplies for next iPhone — RoughlyDrafted Magazine()