Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Operating Systems Software Businesses Apple

Get To Know Mach, the Kernel of Mac OS X 413

An anonymous reader writes "Linux is a kernel, not an operating system. So what is Mac OS X's kernel? The Mach microkernel. The debate around Monolithic (Linux) and Micro (Mach) kernels continues, and there is a great chapter online about the Mach system from the very good book 'Operating System Concepts'. Which design is better? I report, you decide." Warning: link is to a PDF.
This discussion has been archived. No new comments can be posted.

Get To Know Mach, the Kernel of Mac OS X

Comments Filter:
  • MirrorDot (Score:4, Informative)

    by cirisme ( 781889 ) on Monday May 16, 2005 @10:42AM (#12543348) Homepage
    Huge PDF on Slashdot. This can't end well. Mirror [mirrordot.org]
  • by DoctoRoR ( 865873 ) * on Monday May 16, 2005 @10:44AM (#12543368) Homepage
    This appendix on Mach is from the newest edition of the classic "Operating System Concepts," Seventh Edition by Silberschatz, Galvin, and Gagne (Wiley). ISBN: 0-471-69466-5. Published December 2004.

    There are also free online chapters for FreeBSD and Nachos.

    Link to Wiley's purchase page (given that we are /. them): http://www.wiley.com/WileyCDA/WileyTitle/productCd -0471694665.html [wiley.com]
  • mach inject (Score:5, Informative)

    by Kaamoss ( 872616 ) on Monday May 16, 2005 @10:46AM (#12543397) Homepage
    I thought the article was more than relativly informative. Personally I love my mac and I think it's about time people stop fighting over which OS is better, use the right tool for the job, be that Linux, mac, windows, whatever. Anyways, figured I'd throw in a link to some other cool stuff about mach. http://rentzsch.com/papers/overridingMacOSX [rentzsch.com] The page deals with code injection and function overriding within MAC OS X. I think something like it was on here not too long ago but it's also pretty interesting stuff, I'd suggest the read.
  • Re:Monolithic (Score:5, Informative)

    by mmkkbb ( 816035 ) on Monday May 16, 2005 @10:47AM (#12543405) Homepage Journal
    Monolithic translates to no modules, correct?

    I can't believe people are modding you up for this.

    The Linux kernel is monolithic. Linux modules do not run in user-mode. They are loaded into the kernel proper.

    mkLinux was an Apple-sponsored effort to run Linux on Mach. The Linux kernel was modified to run in user-mode; it basically became an executable. In fact, you could run multiple instances of the same kernel (or different kernels) simultaneously.
  • Re:Monolithic (Score:5, Informative)

    by wangmaster ( 760932 ) on Monday May 16, 2005 @10:48AM (#12543416)
    That is monolithic as well, but not using the term in the same way. Monolithic essentially means made from a single piece. This CAN refer to modules as well, as the kernel modules aren't built into the kernel binary, but in the case of monolithic vs. microkernel, it doesn't refer to how the kernel is built. Rather it refers to the execution of the operating system kernel. A modular Linux kernel loads as a single executable that then loads modules into it's process space as needed to do things. This is essentially a monolithic kernel. The OS runs as a single process. Microkernel's have the OS split as seperate processes, mostly outside the core microkernel (which has the job of facilitating message passing between all these processes, and lowlevel process management). The Microkernel may or may not do I/O, sometimes seperate processes do. Hope that helps.
  • by TheViffer ( 128272 ) on Monday May 16, 2005 @10:48AM (#12543420)
    Linux is a kernel, not an operating system.

    Google's definition of Linux [google.com]

    I think you have more of a chance to start a discussion on that statement then you do in regards to which kernel is "better".
  • Re:Monolithic (Score:2, Informative)

    by Anonymous Coward on Monday May 16, 2005 @10:49AM (#12543437)
    > Maybe I'm mixing terms here, but I was under the impression
    > that linux is NOT monolithic - its quite modular. Monolithic
    > translates to no modules, correct?

    No: Both the modules and the rest of the kernel run in the same address space, so Linux is monolithic.

    A microkernel approach puts some (most, for second-generation microkernels like L4) traditional kernel features into user space, where they cannot hurt the kernel directly, by overwriting memory.

  • Xnu, not mach (Score:5, Informative)

    by oudzeeman ( 684485 ) on Monday May 16, 2005 @10:50AM (#12543445)
    Apple's kernel is called XNU (Xun's not Unix). It is based on Mach with a BSD compatibility layer included at the kernel level (as are various other subsytems usually implemented at a server level in true microkernels), not as a 'mach server'. It does not use Mach as a microkernel. Xnu is a essentially a monolithic kernel. The Mach code takes care of inter-process communication, virtual memory, preemptive multi-tasking, etc. The BSD codebase of XNU handles user ids, file permissions, TCP/IP stack, sockets, filesystems

    stop spreading the myth that Xnu is a microkernel

  • Re:Monolithic (Score:5, Informative)

    by gowen ( 141411 ) <gwowen@gmail.com> on Monday May 16, 2005 @10:52AM (#12543461) Homepage Journal
    Well nope. You can insert newly compiled modules into a previously compiled kernel to get new features (that's how the many proprietory video drivers work, for example.) But those are
    a) running in kernel space, not user space
    b) communicated with by predefined hooks, rather than a generic message passing interfacing.

    That's why linux modules, which are superficially like elements of a microkernel, are not really like them at all.
  • by mindaktiviti ( 630001 ) on Monday May 16, 2005 @10:52AM (#12543466)
    Firefox has an extension for PDF Downloading which gives you the option to download a pdf link, in case opening pdfs in browsers bothers anyone.

    PDF Download [mozilla.org]
  • Re:Monolithic (Score:4, Informative)

    by william_w_bush ( 817571 ) on Monday May 16, 2005 @10:54AM (#12543487)
    monolithic in this case also means interface-monolithic.
    basically all the interfaces are defined as symbols to the linker, and all interfaces are defined c-native.

    the micro-kernels are meant to use message passing and more abstracted interfaces, as well as separate address spaces to ensure a bad module does not take down the entire kernel. Think of it like the modules run as only semi-privileged applications, handling their hardware and then giving control back to the micro-kernel which does as little as possible to arbitrate control and schedule between the subsystems and user-mode applications. Drivers are no longer fully privileged, and the entire user-space can be considered a subsystem of the kernel.

    it's different, and kinda hard to design for, but i can't wait for hurd to release a linux compat layer.
  • mach vs posix (Score:5, Informative)

    by dyfet ( 154716 ) on Monday May 16, 2005 @10:56AM (#12543512) Homepage
    Mach was never originally engineering for posix compliance, and yet the two main operating systems built from it, osx (and darwin), and hurd, each have tried hard to tame and make mach behave posix compliant. This has sometimes produced interesting compatibility issues, especially in the contenous issue of posix threading, and has resulted in compatability layers which weigh down the system further.

    Given this compatibility effort, mach is not a fair comparison, either in hurd or osx, for comparing the merits and performance between that of monolithic and microkernel achitectures because so much extra stuff was added to a design never intended for posix. Something like QNX4 and later, designed both as a microkernel and for posix, or perhaps a pure mach system running applications designed specifically for mach, might be a more fare basis to compare the value of microkernel vs monolithic architectures.

    Mach on hurd is easier to grasp and test since many of the lower level mach kernel services are still represented and usable there. Apple seems to be trying to eliminate visibility of as many of the lower level mach services from application developers as possible. Yet, there are still many things that can only be done in the mach kernel on osx or darwin (such as threads that can be cancelled on socket operations or sleeps). If one wanted a bsd/posix compliant environment, I think Apple would have been far better off starting from PPC/xBSD or Linux kernels, rather than trying to rope and rebuild mach to fit into something it was never originally designed for.

  • Re:Monolithic (Score:4, Informative)

    by mrm677 ( 456727 ) on Monday May 16, 2005 @10:57AM (#12543522)
    Linux modules all run in the same address space. Module functionality is invoked with a function call. A microkernel typically uses a message-passing approach and modules are isolated from one another. A small context switch must occur when invoking something in a microkernel module. Hence the overhead of a microkernel is much greater than a monolithic kernel. However many argue that the overheads are worth the organization and safety advantages that the microkernel gives you-- especially nowadays where for typical appliations, the OS accounts for a tiny fraction of overall runtime.

  • Re:Monolithic (Score:5, Informative)

    by bfields ( 66644 ) on Monday May 16, 2005 @10:58AM (#12543541) Homepage
    Maybe I'm mixing terms here, but I was under the impression that linux is NOT monolithic - its quite modular. Monolithic translates to no modules, correct?

    No, you're mixing terms.

    • We say something has a modular design if it's divided into pieces that communicate with each other through small well-defined API's.
    • Linux's kernel modules are bits of kernel code that can be loaded into the kernel at runtime. Usually these modules are also examples of modularity, but they don't have to be. Modules have full access to the kernel's memory, so can do anything the kernel can.
    • In a microkernel drivers, filesystems, etc., all live in a completely separate address space from the kernel, so if, for example, a driver goes bonkers and starts writing to random pieces of memory, the kernel is protected. This forces the design to be somewhat "modular", but again isn't quite the same thing.

    So, the linux kernel supports kernel modules, and its design is to some degree "modular" (as any project that size would have to be), but noone would claim it to be a microkernel.

    --Bruce Fields

  • by kilpatjr ( 65285 ) on Monday May 16, 2005 @11:03AM (#12543590)
    What? no, that's not right.
    It uses the FreeBSD userland utilities, but not the kernel. You can't just compile them together. I mean, it's possible to take parts related to one, like the XYZ bootloader and use it to start the ZYX kernel, you can't just plug in modules or code. The ABIs and APIs are different.
    In this case, MacOS doesn't even do that. They just use a lot of the user utilities and such.
  • by iggymanz ( 596061 ) on Monday May 16, 2005 @11:07AM (#12543621)
    QNX is a real time operating system - its message passing only has good performance when there's not too many different types of messages to pass. The desktop versions of QNX work if you are only doing a couple things, like browsing and doing email. But if you try to do the things that a Linux distro could easily do, like burning a CD while writing to USB device and compiling a new kernel and running a dozen windows, it'll choke up: it's NOT suitable for a general purpose desktop.
  • by Halo1 ( 136547 ) on Monday May 16, 2005 @11:10AM (#12543643)
    The modular design of microkernels makes for easier design & debugging, and with some designs the freedom to make user space services that can only be in privileged space in monolithic designs, but does one want to pay the overhead for all that message passing?

    No, which is why Apple's XNU runs in one address space for the most part (I don't even know whether there are parts which don't), and most message passing has been reduced to plain function calls. They still have the design advantages of something which is conceptually built from different subsystems with clean interfaces though.

  • Mono = one (Score:3, Informative)

    by jd ( 1658 ) <imipak@yahoGINSBERGo.com minus poet> on Monday May 16, 2005 @11:13AM (#12543665) Homepage Journal
    I'm going to ignore for a moment that "lith" means stone. A "monolithic" kernel means a kernel in one piece. As such, a modular design that clips together into a single unit may or may not be counted, depending on your choice of definition.


    Personally, I wouldn't consider a modular kernel to be monolithic, because it can take many forms. It may have a signle form at any given time, but over any period of time, it may vary that form. If we are going to give the Linux kernel a "technical" description, then "polymorphic" would seem to be more accurate.


    However, if we now use "polymorphic" to mean "modular", then there is absolutely no point in having the extra term. We're adding vocabulary without adding any information. So, is it possible to have a kernel with many forms that is NOT modular? Arguably no, because it is only by being able to add/remove kernel code that the kernel becomes polymorphic.


    What about the usage of "monolithic" for anything that is a single layer of code, as opposed to a microkernel which is multi-layered with lots of communication between layers? I'm not convinced this is a useful definition. It attempts to identify kernel types by a specific implementation detail, rather than by the design. It would be as useful as trying to classify cats by eye-colour. The relationship isn't necessarily as rigid as all that.

  • Re:Monolithic (Score:1, Informative)

    by Anonymous Coward on Monday May 16, 2005 @11:14AM (#12543673)
    I can't believe people are modding you up for this. The Linux kernel is monolithic. Linux modules do not run in user-mode. They are loaded into the kernel proper. mkLinux was an Apple-sponsored effort to run Linux on Mach. The Linux kernel was modified to run in user-mode; it basically became an executable. In fact, you could run multiple instances of the same kernel (or different kernels) simultaneously.

    This is all true, but it's also true that xnu (the os x kernel) is monolithic as well. They've taken mach and the bsd kernel and put them both in the kernel proper. It's not like freebsd is running as some userland process (a la lites) in a typical microkernel fashion.

  • by Halo1 ( 136547 ) on Monday May 16, 2005 @11:15AM (#12543681)
    The BSD and Mach personalities run together in one and the same (kernel) address space. The BSD layer does not consists of merely some user space libraries. See e.g. this graphic [apple.com].
  • by dumbnose ( 190140 ) on Monday May 16, 2005 @11:20AM (#12543728)
    I don't know where you get your information, but it is incorrect. When you develop kernel drivers for Mac OS X, you program to both the Mach and FreeBSD APIs. It does not just use FreeBSD utilities.
  • Mach Sucks (Score:4, Informative)

    by Unknown Lamer ( 78415 ) <clinton@nOSpAm.unknownlamer.org> on Monday May 16, 2005 @11:21AM (#12543740) Homepage Journal

    Mach is painfully slow. It's an old microkernel and it uses async IPC (to allow for passing messages over the network). This is slow because you have to do a ton of context switches and copy the message between address spaces.

    L4 [l4ka.org], on the other hand, uses sync IPC. It has a bunch of neat optimizations, but the main reason why it's faster than Mach is that it doesn't have to copy messages. You send an IPC and it goes into the part of your VM space that L4 sets aside for IPC and then L4 does a quick context switch to the target task, it processes the IPC, and then you get your data back. (Simplifyed a ton).

    So, microkernels rock. Mach sucks.

  • by Anonymous Coward on Monday May 16, 2005 @11:21AM (#12543756)
    'Calls the shots' might be an exagerration. The mach and bsd layers interact in a peer type way. For some things, mach primitives are used, for other things bsd primitives are used. In some cases, the bsd layer interacts with the mach layer fairly directly.

    One example is the unified buffer cache, which ties directly into the mach vm layer. Mach is certainly used for more than bootstrapping the bsd subsystem.

  • OS X's kernel, "xnu", is /based/ on Mach 3.0 and obviously shares a few concepts with Mach, but is neither a pure Microkernel, nor are all its components from Mach.

    Amit Singh has a well-written page about XNU: http://www.kernelthread.com/mac/osx/arch_xnu.html
  • NOT A MICROKERNEL (Score:5, Informative)

    by Leimy ( 6717 ) on Monday May 16, 2005 @11:23AM (#12543775)
    Mac OS X does not use Mach like a microkernel at all. I wish people'd get this through their thick skulls.

    It uses Mach and BSD in THE SAME ADDRESS SPACE. As such, it's basically as monolithic as it gets. It just happens to incoporate Mach in the kernel space and uses it for threads and IPC.

    Anyone who takes 10 minutes to look at the Darwin documentation would know this.

    I wish /. would actually edit for content.
  • Re:mach vs posix (Score:3, Informative)

    by Dink Paisy ( 823325 ) on Monday May 16, 2005 @11:23AM (#12543777) Homepage
    Technically, that may be correct (Mach developed without aim for POSIX compliance), but considering the title of the original Mach paper was, "Mach: A New Kernel Foundation for UNIX Devlopment," it's a silly statement. Mach was made explicitly for implementing UNIX-like operating systems.

    The level of Mach-iness of OS X is another good question, though. From what I gather, OS X looks more like a monolithic BSD kernel ported to a Mach/PPC architecture (where instead of targeting the PPC architecture, OS X's BSD kernel targets the higher level Mach abstractions), rather than a microkernel operating system of the type one would normally expect to find running on top of Mach.

  • by PCMeister ( 837482 ) on Monday May 16, 2005 @11:24AM (#12543780)
    Here's another way... No extension needed:

    * Tools -> Options

    * Downloads -> Plug-ins

    * Uncheck PDF Extension -> Click Ok

    * Click [Ok] again to Exit Options Menu

    * Find a link to a PDF and click on it

    * A dialog box will pop-up asking what to do with it

    * Verify that Open With reads "Acrobat Reader" (or "AcroExch" in the newer versions of Acrobat Reader)

    * Check "Do this automatically..." -> Click OK

    PDF files will now spawn Acrobat Reader out side of Firefox. This is also helpful on older PC's that slow down to a crawl when opening PDF's within the browser.
  • by Anonymous Coward on Monday May 16, 2005 @11:25AM (#12543798)
    The kernel that Apple uses in OS X is called XNU.

    It uses code FROM Mach, but it is not Mach and it is not a Microkernel. NT (NT 4.0, NT 5.0 (win2k), NT 5.1 (WinXP) does not use a Microkerenl either.

    The only OS that I know of that actually uses a Microkernel is GNU/Hurd.

    The OS X kernel, called XNU, is a mixture of *BSD kernel code and Mach kernel code.

    Yes, yes, there was a ancient debate between Linus and that other guy about Micro- vs Macro-kernels, and guess what, Linus was right.

    Apple does NOT use a microkernel. It does not use Mach. It is BASED on Mach. It would be considured a kludge compared to Linux or FreeBSD, but it works out fine.

    Similar to how Mustangs are based on Ford Falcons and Granadas from the late 70's and early 80's. Those cars were as much as a failure as Mach, however the Mustang is flashy and many people desire it. So go figure.
  • by Phong ( 38038 ) on Monday May 16, 2005 @11:35AM (#12543895)
    I always thought that Linux was indeed only a kernel for the GNU OS

    That is a true statement for the GNU project, but not for all of Linuxdom. Linux (the OS) was not started by the GNU folks. It was started as a separate project and incorporated items from the FSF (and BSD, etc.) into its release. From the beginning the whole OS has always been called "Linux" (search Google Groups for "linux 0.11 author:torvalds" and click on the "Linux information sheet" for an example of this).

    Yes, RMS prefers to call the OS GNU/Linux, but that's because he's seeing things from the perspective of the GNU project incorporating the Linux kernel into their work. The rest of Linuxdom see Linux as the name of both the OS and the kernel, and qualify the name using the phrase "the Linux kernel" as an easy way to differentiate between the two.

    So, the opening statement in the OS X story is false: Linux is an OS, and is used as such by folks every day. This is the reality of the situation, and it is, at best, wishful thinking on the part of folks who claim it is not to say otherwise.

  • Actually, the grandparent IS correct. I spent the last week studying the Mach and OS X designs, and I found the following things:

    1. Mach is not a complete kernel. It requires someone to implement the areas which the Mach group were not researching. This has traditionally been done by compiling against BSD 4.3.

    2. Mac OS X updated to the FreeBSD kernel instead of BSD 4.3 to gain a more modern kernel design with better hardware support.

    3. OS 9 "Classic" is not a microkernel server, but rather a technology that Apple calls "Blue Box". Blue Box is a hardware virtualizer like VMWare that is capable of communicating directly with the OS X desktop. Using this communication, the OS 9 desktop is made to disappear, making the application appear to run on the OS X desktop.

    4. The combination of Mach and FreeBSD is called "XNU" by Apple. The complete os is called Darwin, and the commercial variety with the Next and Mac APIs is called "Mac OS X".

    More Info:
    Mach Kernel [cmu.edu]
    Wikipedia: Mach [wikipedia.org]
    Wikipedia: XNU [wikipedia.org]
    Blue Box info [kernelthread.com]
  • by Anonymous Coward on Monday May 16, 2005 @11:47AM (#12544015)
    Just because it runs on Mach doesn't mean that MacOS X is a microkernel architecture.

    Just as an example, on the new MacMini hardware, sound level control is done in kernelspace (since HW doesn't support that anymore)! Whereas the LinuxPPC developers refuse to do things like this in kernelspace.

    Actually in Linux many things are pushed out to userspace (think udev), making it much more microkernel-like than MacOSX.

    (Not that Apple-Fanboys would understand anything of that)
  • Re:Monolithic (Score:5, Informative)

    by Alien Being ( 18488 ) on Monday May 16, 2005 @11:53AM (#12544073)
    "I can't believe people are modding you up for this."

    I can. Maybe you're too young to remember when the term monolithic was commonly used to describe a kernel which, instead of using loadable modules, was linked as a single binary image. This was, and is, a valid use of the word. Here's an example [linuxjournal.com].

    The first time I heard someone say that Solaris is monolithic, I thought that they were saying that, like SysVR3, it didn't support loadable modules. I didn't realize that, with the development of microkernels, the term "monolithic kernel" had started to be used in a different context.

  • by Phong ( 38038 ) on Monday May 16, 2005 @11:54AM (#12544088)
    > I agree that way back when, Linux was the name of the kernel, period

    Not so. Here a posting from Linux Torvalds about Linux -- from the beginning the term was used as both the name for the kernel and the whole OS:

    LINUX INFORMATION SHEET
    (last updated 13 Dec 1991)

    1. WHAT IS LINUX 0.11
    LINUX 0.11 is a freely distributable UNIX clone. It implements a
    subset of System V and POSIX functionality. LINUX has been written
    from scratch, and therefore does not contain any AT&T or MINIX
    code--not in the kernel, the compiler, the utilities, or the libraries.
    For this reason it can be made available with the complete source code
    via anonymous FTP. LINUX runs only on 386/486 AT-bus machines; porting
    to non-Intel architectures is likely to be difficult, as the kernel
    makes extensive use of 386 memory management and task primitives.

    [...]

    2. LINUX features
    - System call compatible with a subset of System V and POSIX
    - Full multiprogramming (multiple programs can run at once)
    - Memory paging with copy-on-write
    - Demand loading of executables
    - Page sharing of executables
    - ANSI compliant C compiler (gcc)
    - A complete set of compiler writing tools
    (bison as yacc-replacement, flex as lex replacement)
    - The GNU 'Bourne again' shell (bash)
    - Micro emacs
    - most utilities you need for development
    (cat, cp, kermit, ls, make, etc.)
    - Over 200 library procedures (atoi, fork, malloc, read, stdio, etc.)
    - Currently 4 national keyboards: Finnish/US/German/French
    - Full source code (in C) for the OS is freely distributable
    - [...]
  • by Some Random Username ( 873177 ) on Monday May 16, 2005 @11:55AM (#12544096) Journal
    First of all, having modules or not has no effect on being monolithic. The entire kernel is a single process that simply executes code, wether its compiled into the kernel, or loaded into the kernel as a module makes no difference here. Microkernels actually have seperate processes for different parts of the kernel, and they cannot execute code from each other, they must communicate back and forth using some sort of message passing system.

    And second, no BSD based kernel forces you to use modules. Have you actually tried any BSD? Modules are entirely optional, just like linux. In fact, openbsd's kernel only has support for modules, but nothing is actually compiled as a module, and using modules is unsupported.
  • by Maury Markowitz ( 452832 ) on Monday May 16, 2005 @11:56AM (#12544106) Homepage
    > QNX uses shared memory to pass messages

    So does Mach, and it's slow. I've never seen real-world measures to suggest that QnX is fast. All we know is that the performance of the OS itself is good, and that's a VERY DIFFERENT measure.

    The slow performance is due to a number of problems:

    1) not all MMU's are really suited to this task. Many are slower to set up than just copying the memory around. Sun found this to be at around 5k, below that, it was faster to just copy memory physically.

    2) MMUs/VM are based on pages, 2 or 4k typically. Thus passing in a single 32-bit int parameter causes big page hits. You can tune this out, but it's still annoying.

    3) Each copy takes TWO context switches - one to switch into the kernel to copy the memory across ports, another back out to the called program. This means that even the simplest "system calls" are twice as slow as under a monokernel, AT BEST.

    4) Additionally the data has to be examined to see if it contains ports being passed around, and if so, they have to be translated because the port codes are private to a program (and thus different in the other one).

    5) Using mapped memory ignores all the hardware specific solutions to these problems, many of which are built into modern processors.

    It's exactly the sort of one-size-fits-all solution that you'd expect from a research project. One that doesn't work in the real world. One that should have been replaced, and was in L4, Spring, etc.

    For instance, Spring included three different IPC systems, each tuned to certain types of data, each used in different ways on different CPUs. The "fast-path" used a half-switch into the kernel by mapping off registers, allowing IPC to degenerate into register passing largely identical to a procedure call. As long as the message fit within the limitations -- 8 registers, no port identifiers, etc. -- it was faster than a traditional Unix trap. These limitations seem serious, but were in fact used for 80% of calls and 60% of returns (you often say "getDiskSector(integer value)" which could fit into the fast-path, and get back 2k of data which wouldn't).

    Maury
  • Re:Monolithic (Score:2, Informative)

    by Anonymous Coward on Monday May 16, 2005 @12:03PM (#12544169)

    The problem with a fully MicroKernel is that its very slow because of all the context switching that has to go on between userland/and kernel land to do what is essentially kernel functionality. Apple solved this by making XNU not act as a microkernel for things such as the BSD layer.
    The result is a Kernel that is less prone to panics. In Linux a bad KLM would certainly panic the kernel because it runs in the same address space as the kernel. In OS X a bad Kext would just die like anyother user space program.



    In xnu, KExt's are not userland processes. They are kernel extensions, just like on most other *nixes. I don't know where people get these patently false notions.

    From the documentation...


    Kernel Extension Overview
    As discussed in the chapter "Kernel Architecture Overview", Mac OS X provides a kernel extension mechanism as a means of allowing dynamic loading of code into the kernel, without the need to recompile or relink. Because these kernel extensions (KEXTs) provide both modularity and dynamic loadability, they are a natural choice for any relatively self-contained service that requires access to internal kernel interfaces.

    Because KEXTs run in supervisor mode in the kernel's address space, they are also harder to write and debug than user-level modules, and must conform to strict guidelines. Further, kernel resources are wired (permanently resident in memory) and are thus more costly to use than resources in a user-space task of equivalent functionality.

    In addition, although memory protection keeps applications from crashing the system, no such safeguards are in place inside the kernel. A badly behaved kernel extension in Mac OS X can cause as much trouble as a badly behaved application or extension could in Mac OS 9.

    Bugs in KEXTs can have far more severe consequences than bugs in user-level code. For example, a memory access error in a user application can, at worst, cause that application to crash. In contrast, a memory access error in a KEXT causes a kernel panic, crashing the operating system.



  • by emil ( 695 ) on Monday May 16, 2005 @12:09PM (#12544216)

    While many devices are not supported, and the performance is not good, HURD/Mach is feature complete (and most of Debian runs on it, IIRC).

    Because the performance was bad, the new HURD effort focuses on reimplementing on L4. Perhaps with a faster microkernel, Apple could have avoided the kludge of an in-kernel BSD peer.

    If I am reading correctly, Mach is responsible for IPC in the Apple kernel. It would be interesting to see benchmarks of SYSV system calls to semaphores, queues, and shared memory (and perhaps even basic signal handling) under Linux and the Apple kernel on the same hardware if those are entirely handled by Mach.

  • by Some Random Username ( 873177 ) on Monday May 16, 2005 @12:09PM (#12544224) Journal
    Context switches are not rediculously slow on all architectures, so "a ton of context switches" isn't that big a deal unless you are using a poorly designed architecture that hasn't been improved, ever.
  • Just FYI, the other guy is Andrew Tannenbaum, who wrote Minix [cs.vu.nl]

    As for winning or losing, you can see for yourself on Google Groups [google.ca] that it was not about winning, it was a discussion on the merits of both.
  • by ikewillis ( 586793 ) on Monday May 16, 2005 @01:00PM (#12544699) Homepage
    XNU, the kernel of OS X, is a hybrid of Mach and select BSD code, which leans substantially more towards a monolithic kernel design. What Mach typically handled in a microkernel manner with servers, namely things like the VFS, networking, etc. have all been completely removed in XNU. Where once there were Mach servers there is now the FreeBSD Unified Buffer Cache, to which Apple has attached various FreeBSD subsystems like the FreeBSD VFS and network stack.

    XNU is essentially a monolithic kernel, much like Linux. The real differences, in my opinion, lie in the IOKit object oriented driver API, whereas Linux has no real driver API and drivers have complete access to all kernel functions as drivers are simply kernel modules.

  • by Maury Markowitz ( 452832 ) on Monday May 16, 2005 @01:10PM (#12544819) Homepage
    My point was limited to the time for the switching itself. Perhaps I should have been more clear on this.

    The "at best" is assuming that the forgoing issues don't cause things like cache faults. Passing parameters in registers won't. Thus the performance really can be MUCH worse than twice even in the case of minimal calls.

    But even in that case the real-world performance of Mach is, in fact, much worse that twice as slow. I believe it was Chan that did all the big measurement runs, and - going on memory here - BSD on a 50MHz 486DX took 21 usec per syscall, and Mach 3 on the same machine took 114. I may have the number for BSD wrong, that might be the L4 number, BSD might be 9 usec.

    The other case is, in fact, even worse. This is the case where the system is constructed of a number of cleanly separated servers running as Mach tasks. In this case a system call may spawn off a series of calls, consider a page fault in the VM for instance. In this case you might end up with a chain of 5 IPC's causing traps. And each one of them is 5-15 times as slow. This is real-world noticable, even for I/O.

    One of the papers I have on L4 shows theoretical peak and sustained network throughput for IP on Mach, L4 and BSD. Mach had about 1/10th the performance IIRC. So that "best case" is pretty rare.

    Maury
  • Re:Monolithic (Score:3, Informative)

    by EvilTwinSkippy ( 112490 ) <yoda AT etoyoc DOT com> on Monday May 16, 2005 @01:17PM (#12544889) Homepage Journal
    By all definitions Linux is monolithic.

    You can't download the binary of a driver, tell the kernel to load it, and expect it to work unless the person who compiled just so happened to have the exact same version info, and by some miracle the same compile options.

    Yes, distros like RedHat and SuSE do have binary drivers for download, BUT ONLY if you stay with the stock kernel.

    Just because you can "load modules" doesn't mean you are suddenly a microkernel. God it's like monolithic has become a swear word, it's a perfectly valid design.

  • by ltwally ( 313043 ) on Monday May 16, 2005 @01:35PM (#12545056) Homepage Journal
    Just because linux gives you the options of going modular or monolithic whereas most BSD based kernels do not (you will use modules, period)
    It's a good thing you've already been modded to zero...

    To clear up any confusion: No *BSD uses a microkernel. (The only part of OS-X that is *BSD is the userland, which is derived from FreeBSD). The *BSD's are basically in the same classification as Linux/Solaris/HP-UX or any other UNIX or *NIX clone. Which means: all the *BSD's are monolithic in nature, with some modular abilities added on in recent years. Like Linux, the *BSD's can load a kernel-module upon request (either during boot, or upon superuser-request). These modules can also be compiled into the kernel itself (which is sometimes a good idea, as it saves a small amount of memory and improves performance).

    Anyhoo, back to the original topic: The MACH microkernel. Apple's implementation is excellent these days, but it definitely went through its struggles (which is one reason why we continue to see major speed improvements with new versions of OSX, even on older hardware). Creating a monolithic kernel is difficult enough, but to create a micro like MACH, and do it properly... that takes serious skills. Mad props, Apple engineers.
  • by Anonymous Coward on Monday May 16, 2005 @01:51PM (#12545252)
    Actually, early versions of Linux had their own C library, explicitly written for Linux.

    It wasn't until glibc 2.0 came out in the late 1990s that people started switching to GNU Libc. If you look at the glibc webpage, [gnu.org] it is copyright 1996 - 2004... What do you think Linux used before 1996?

    So, to be a little bit technical, Linux used to be not just a kernel, but a kernel, C library, and boot loader. Since then 2 of those have been replaced by externally developed tools.

    As an aside, there are a few more userland programs that might be considered part of "linux", including: module-init-tools, iptables, hotplugd, udev, etc. These are not GNU tools, and were explicitly written to extend the Linux kernel.
  • by Anonymous Coward on Monday May 16, 2005 @02:23PM (#12545641)
    Mac people know what a kernel is , but they know its illegal for them to change it , modify it or resale it, so they work on other things if they do the previous they will get sued into oblivion.

    Actually, the Mac kernel is completely contained in Darwin and is therefore open source [apple.com]. You are more than welcome to download it, compile it (even on x86), modify it, etc. without any risk of getting sued. No, you can't resale it and the license is more restrictive than other OS licenses, but most of what you said is simply false and absurd.
  • by Animats ( 122034 ) on Monday May 16, 2005 @02:27PM (#12545694) Homepage
    XNU is based on Mach 3.0, not Mach 2.5

    Actually, Apple's kernel is a collection of parts from BSD, Mach, and IOKit. [freebsd.org] It's a monolithic kernel like Mach 2.5, not a microkernel like Mach 3.0, although some parts from the Mach 3.0 code base were supposedly used.

    IOkit is written in the "embedded subset" of C++, an idea from 1999 that never caught on. Drivers are loadable kernel modules, as with Linux, but the structure is quite different.

    Any driver can crash the kernel. It's not a microkernel at all.

  • Check out this recent video discussing Microsofts "Singularity" research project works in this way.
    <URL:http://channel9.msdn.com/ShowPost.aspx? PostID =68302>

Top Ten Things Overheard At The ANSI C Draft Committee Meetings: (5) All right, who's the wiseguy who stuck this trigraph stuff in here?

Working...