Operating Systems and Computer Architecture
MacOS Research Paper
Let’s start with the basic facts about Macintosh operating system. MacOS was developed in 1984 by the Apple Inc. and was designed for use with its Macintosh series of personal computers, as well as the related system software. MacOS was written in most reliable languages of the time such as C?, ?C++?, ?and Objective-C? languages. Produce exclusive hardware and software for better incorporation of the OS and the hardware increase the fastest and smoothest way to handle and use of operating system by the end-users. Macintosh computers used the Motorola PowerPC Chip set with an advanced architecture enhanced for graphics and multimedia interface and usability. Since 2005 the Apple Mac line of computers are Intel-based, but the Mac OS is only licensed to run on an Apple Mac which is the first multitasking operating system. The preferred file system for Mac OS X is HFS, HFS+ (Extended Volume Hard Drive Format) a robust file system that includes support for file permissions, but it also supports other file systems.
The current Mac OS X is a UNIX based Operating System with the intuitive user interface called Aqua. The modern core UNIX based Operating System brings benefits such as protected memory and preemptive multitasking to Macintosh computing. The central characteristic of the Mac OS architecture is the layering of system software, with one layer having dependencies on, and interfaces with, the layer beneath it Mac OS has four distinct layers of system software with in order of dependency such us:
Application Environments which consists of the frameworks, libraries, and services necessary for the runtime execution of programs developed with those Application Programming Interface (API). Mac OS currently provides five execution environments such as, Carbon, Cocoa, Java, Classic, and BSD Commands.
Application Services includes the system services available to all application environments that have some impact on the graphical user interface. This system service includes Quartz, QuickDraw, and OpenGL as well as essential system managers.
Core Services incorporates those system services that have no effect on the graphical user interface. And this service includes Core Foundation, Open Transport, and certain core portions of Carbon.
And finally, Kernel Environment provides the foundation layer of Mac OS. Its primarily component is Mach, but it also includes networking procedure stacks and services, file systems, and device drivers. The notable advantage of kernel environment is that it offers facilities for developing device drivers (the I/O Kit) and loadable kernel extensions, including Network Kernel Extensions. Again, it can be implied more accurately in the diagram bellow.
INCLUDEPICTURE “http://developer.apple.com/documentation/MacOSX/Conceptual/SystemOverview/art/osxlayers.gif” * MERGEFORMATINET INCLUDEPICTURE “http://developer.apple.com/documentation/MacOSX/Conceptual/SystemOverview/art/osxlayers.gif” * MERGEFORMATINET
Looking more on the advantages of Mac Operating System is that Multitasking is the notable advantage, where Mac computers have hardware specifications designed for multitasking. And because Mac OS integrates multitasking feature also responds to built-in shortcut keys or track-pad and mouse gestures for easily switching between windows or apps that are running in the background. Nevertheless, Windows computes also have the ability to switch using shortcut keys, but again Mac OS has a richer feature that focusses on easy navigability. Mac OS allows multiple “desktops” or home screens, which allows a user to organize all the running apps based preferences that they like. Also, the previous versions of the Mac OS used cooperative multitasking. Cooperative multitasking allows the application to take control of the CPU, which often makes other applications that are running in the background to starve. With cooperative multitasking applications are supposed to share the CPU and it is the programmer’s responsibility to insert calls at suitable points in their code to allow for the application to be rescheduled in order solve the problem of starvation. Unix has a preemptive multitasking environment where the operating system decides what gets to use what portion of your overall resources. Mac OS also uses this type of preemptive multitasking environment, where each specific part of the memory is allocated to this specific application. Because of this, system performance is improved severely because whenever switching tasks the other process that is still running does not lose its memory allocation. Not only are resources allocated to a specific application in this environment but also processes can be preempted and swapped in or out of main memory. Preemptive multitasking makes well-organized and efficient use of the machines by keeping the CPU as busy as possible. Also, another big advantage of Mac ease of use, Mac OS was known for having the best industrial and interface designs of the machine, which also can be proven by intuitive nature of the GUI. The interfaces of the Mac OS, such as windows and menus represents an innovative continuation of the legendary Mac ease of use. Especially with interface Aqua, Mac OS provides the elegantly functional look using color, transparency, and animation to enhance the usability and reliability of the system and applications.
The kernel of the Mac OS X is composed of five mechanisms: Mach, BSD, Device Drivers and I/O Kit, Networking, and File Systems. The lowest level of the kernel, Mach, is the part of the operating system that provides implementations of tasks, threads, virtual addressing, memory management, and an inter-task communication. Mach mechanism also manages processor usage and the CPU scheduling, which implements memory protection as well. Mach also provides timing services, synchronization primitives, and infrastructure for the rest of the Macintosh operating system Mach supplies large portions of virtual address spaces for addressing. At initial access time, the virtual address may not correspond to a location in physical memory. Mach’s task is to connect each virtual address to its physical space in memory. This is done through demand paging. Data in an address space is made up of memory objects, which are further broken down into pages.
While interfacing a virtual deliver to an area in physical memory, Mach petitions the manager from a memory question for the substance of a page and returns the information back to the pager. Pagers provide the data of the pages in memory objects. Like Apple, developers said, “Paging of any kind, and disk thrashing, in particular, affects performance negatively because it forces the system to spend a lot of time reading and writing to disk. Reading a page in from the backing store takes a significant amount of time and is much slower than reading directly from RAM. If the system has to write a page to disk before it can read another page from disk, the performance impact is even worse.” And this is because when disk trashing occurs system tent to spend an inconsistent amount of time while handling page faults and reading and writing pages. Additionally, with the virtual memory system, there are two built-in pagers in Mac OS, default and the vnode pager. The default pager handles anonymous memory. Anonymous memory is the virtual memory that is non-persistent it exists only as long as the task exists. The vnode pager maps files into memory objects. This is done through an interface that Mach exports to memory objects to allow their contents to be contributed by user-mode tasks. This interface is called the External Memory Management Interface and this interface gives handles to virtual memory, called named memory entries. By having names attached to memory, the owner can map the entry or allow others to do so. Two different tasks may map a single entry; this results in a shared memory window between them. This allows flexibility in sharing memory.
Other methods for inhibiting address space are direct allocation and inheritance. Indirect allocation, the virtual memory object is anonymous and supported by the default pager. In order to optimize the performance of inherited copies, Mach uses copy-on-write, a delayed form of copying. And it is safely accomplished by protected sharing. Instead of directly copying the range of addresses, the two tasks share the memory being copied with read-only access. A portion is copied when either task modifies a part of the memory. Another type of sharing memory is through the fare of named regions. Named regions are forms of named memory entries, but are maintained by virtual map fragments rather than virtual memory objects. These fragments hold virtual mappings that can map to other virtual maps. This enables inheritance of groups of virtual memory objects, and inheritance of existing mapping relationships, therefore optimizing task setup.
However, it is important to note that one of the weaknesses of current Mac OS is the memory usage. And what can be said about the older versions of Mac OS to current is that they made a huge change in the system and its applications, especially Cocoa and Carbon, use up a lot more memory. Mac OS X tends to use up all available memory, and that is because of current Mac OS caches as much data as it can in memory so that it can possibly reuse that data without having to page it in. Therefore, the current Mac OS’s performance drops when all available memory is used because it has to start paging out, which decreases the performance by thrashing. This problem is much more predominant in the current Macintosh operating systems because applications are not limited to a specific amount of memory; they just take as much as they need, so free memory reduction happens fast.
The Process Manager is basically just schedules and keeps updated information on each process. This information on each process includes the current state, address, size, type, creator, and process serial number. The process serial number is the identifier for each process.
All processes must be either a foreground process or a background process. Which is that in foreground process is the one that the user is currently using. The foreground process is the active application, and only one process may be in the foreground at a time. The foreground process has first priority in accessing the CPU.
A background process is one that is not currently interacting with the user. There can be more than one background process. Applications may be background-only. These background-only applications are designed without a user interface. They do not display windows or a menu bar. Background processes may only access the CPU when the foreground process allows it.
A process may switch between foreground and background, such as when a user clicks on one of the background application’s windows. The foreground process’s context is switched to the background, and the background process is brought to the foreground. This is called a major switch. In a major switch, the Process Manager sends the foreground application a suspend event, which causes that application to suspend. This allows the user to switch to another application. That application is then on the resume or running state. Besides suspended and running, another state that the process may be in is sleeping. If no events are pending in the application’s event queue, and a value is specified in the sleep parameter by the programmer, the application can relinquish the CPU to other processes. Once time runs out, the application is then eligible to run again and is put in the event queue.
Optimized symmetric multiprocessing (SMP)
SMP is the tool for an operating system to schedule and integrate operations among more than one processor. Macintosh being based on UNIX, it is possible to either have SMP or master/slave setup for multiple processors. And it was first introduced in 1997 that Apple has offered an operating system that allows for multiprocessors. Mac OS is also permits the normal home PC user to run a single processor as well. Mac OS has always provided full SMP support for user applications as well as within the Mach subsystems. Mac OS includes optimized kernel resource locking at the level of individual interfaces and buffers, minimizing the chance of threads on different processors having to block for each other. This allows users to get maximum performance from multiprocessor systems. Sources from Kernel Environment support that SMP is made possible through the use of the latest revision of the Unix-based Mach kernel. This kernel puts together standard virtual memory semantics with the concept of memory objects to enable the operating systems to manage separate application environments concurrently while providing its user a complete feel. However, it is important to comment on the fact that SMP is not supported in the first release of Mac OS X. The newest version should have preemptive multitasking and protected virtual memory, which will allow for SMP to happen.
The Mac OS X kernel directly implements the threads for efficiently handling multithreaded applications on one or more processors. Each thread is individually scheduled and migrated by the kernel, without the overhead of user-level thread libraries, minimizing CPU and memory overhead. Mac OS includes full support for POSIX threads, including cancellation and synchronization.
Apple developers ensured us with the example that they provided, that in user-level real-time support, every single thread can specify its exact real-time requirements. And the example is, “A thread can request 30 out of every 200 cycles to ensure that the write buffer is always full for maximum-speed DVD burning. The kernel then monitors threads to ensure that they stay within their stated allotment, enabling the system to safely perform normal tasks during time-sensitive operations.” Meaning that kernel manages threads to perform their task with an appropriate portion in order for a thread to indicate its real-time requirements.
The kernel provides two mechanisms for synchronization primitives such as locks and semaphores. The current Mac OS uses traditional counting semaphores rather than binary semaphores. Mach semaphores obey Mesa semantics which is when a thread is awakened by a semaphore becoming available, it is not implemented immediately. Which may potentially lead to starvation in multiprocessing situations, when the system is under low overall load because other threads might be closing the semaphore before the “just-woken” thread gets a chance to run. Also, semaphores can be used in any place where mutexes can occur. This prevents their use in interrupt handlers or within the context of the scheduler and makes it strongly discouraged in the virtual machine system.
The current Mac OS and Mach, in general, has three basic types of locks, which are spinlocks, mutexes, and read-write locks. Each of these locks has different usage and different problems that arise when in use. There are also many other types of locks, such as spin-sleep locks, some of which may be useful to implement for performance comparison purposes, but the Macintosh operating system does not use it. So, in Mac OS until the lock is available, the thread begins to execute only when spinlocks start to spin in a tight loop that keeps inspecting the lock until the thread’s time quantum expires. While spinlock is in the process, the thread does not block while holding a spinlock, because that will cause deadlock. And preemption is disabled on a given processor while a spinlock is processing. One thing about spinlocks is that it is very wasteful of CPU time because entire time quantum for the first thread must be finished before the next thread can execute and releases the lock. Spinlocks should only be used in conditions where a mutex cannot be used, such as in a hardware exception handler or “low-level” interrupt handler.
Then in a Mutex, which is similar to a spinlock, except that instead of constantly polling, it places itself on a queue of threads waiting for the lock, then yields the remainder of its time quantum. It does not execute again until the thread holding the lock wakes it. However, mutexes are more efficient than spinlocks and not very effective in multiprocessing environments where the anticipated “lock-holding” time is relatively short. If the average time is relatively short but occasionally long, spin/sleep locks may be a better choice. Although the current Mac OS does not support spin/sleep locks in the kernel, they can be easily implemented on top of existing locking primitives. And since mutexes depend on blocking, they must be utilized in an environment where blocking is permitted. For this reason, mutexes cannot be used in the context of interrupt handlers. Interrupt handlers are not permitted to block because interrupts are disabled for the duration of an interrupt handler and along those lines. However, if an interrupt handler is closed, it would avoid the scheduler from receiving timer interrupts, which would prevent any other thread from executing, resulting in a deadlock. Lastly, Read-write lock which is also called the shared-exclusive lock is somewhat different from traditional locks, because in a way they are not always exclusive locks. A read-write lock is useful when shared data can be reasonably read concurrently by multiple threads except while a thread is modifying the data. Read-write locks can dramatically improve performance when the majority of operations on the shared data are in the form of reads since it allows concurrency while having a slight impact in the case of multiple writes.
Far fewer security issues exist for macOS in any case. Some Mac users get by just fine without any antivirus apps. This implies that Mac OS is less at risk of viruses and malware than Windows. It is additionally worth specifying that Windows requires more support than Mac OS from scheduling and running antivirus scans to updating drivers and patching applications. Windows is also rattled with clutter and bloatware issues, where Mac OS is more on the safe side. Because Internet security was a critical concern when designing the current Mac OS X, Apple advanced its strengths in user experience to maximize the security of the system, while minimizing the inconvenience to, or expertise required of, ordinary users. The greatest security technology in the world is useless if users don’t understand how to use it, or worse, actively bypass it in order to get their work done. Apple works with the open source and security research communities to continue innovating in this area, so the growing Mac OS customer base can continue enjoying its security advantage.
In order to understand security in Mac OS, it is important to understand that there are two security models at work. One of these is the kernel security model, which is based on users, groups, and very basic per-user and per-group rights, which are, in turn, coupled with access control lists for increased flexibility. The other security model which is called a “user-level”, which is based on keys, keychains, groups, users, password-based verifications, and a host of other details. Also, two basic yet important features that “user-level” security contains are Security Server and Keychain Manager. In which, the Security Server consists of a daemon and various access libraries for caching permission to do certain tasks, based upon various means of verification, including passwords and group membership. When a program requests permission to do something, the Security Server basically says “yes” or “no,” and caches that decision so that further requests from that user for similar actions within a single context do not need to verify more than once. And the Keychain Manager is a daemon that provides services related to the keychain, a central source for a user’s verification code or keys.
The National Institute of Standards and Technology defines a data structure as “an organization of information, usually in memory, for better algorithm efficiency, such as the queue, stack, linked list, heap, dictionary, or tree.” Meaning that data structures can include redundant information, such as the length of the list or number of nodes in a sub-tree, or other things like arrays, dictionaries, trees, bitmaps, and locks. These data structures are common to almost all operating systems, and play major roles in process, memory and file management. A set of programming interfaces called Carbon that is carried over from previous Macintosh Operating Systems has a strong influence over data structures. Carbon restricts direct access to data structures to maintain system integrity and to support access to services by using preemption. Carbon attempts to reduce wasted memory by using accessory functions to retrieve field data, instead of using pointers that can lose their references. Carbon also has methods to create and kill data structures.
Data structures are also central to Apple events; high-level events which trigger message passing between an application and itself, an application and another application on the same machine, or between the application and a remote machine. These events are the primary way that applications interact with the current Mac OS. The Apple event objects use a well-defined set of data structures to request services or provide information to one another, and while the user may implement new Apple events to utilize these structures. However, an operating system can result in errors sometimes. These events cover most basic functions like saving and closing documents but also can have tremendous database and scripting powers. The objects composed of data structures and these event methods are the basis for Object-Oriented Programming on the Mac. These Apple events and their primary data structures are controlled by the process manager, that controls access to shared resources and schedules processor usage. It governs the scheduling and execution of applications and uses the data structures to make these procedures more efficient.
The networking environment on Mac OS is highly configurable and extensible. Meaning that System Configuration framework provides APIs for determining and setting the current network configuration. And the network kernel extensions allow you to extend the core networking structure of the current Mac OS by adding features such as a firewall or virtual private network (NVP) and also without recompiling or relinking the kernel. The effect is immediate and does not require rebooting the system.
When it comes to the originality of a device’s network environment is that it can change at a moment’s notice. There are a number of simple yet overwhelming networking mistakes that can harmfully affect the applications performance and usability, such as executing synchronous networking code on your program’s main thread, failing to handle network changes gracefully, and so on. However, the pros of the networking on Mac OS is that it can accomplish the following networking tasks like performing HTTP/HTTPS requests to enable communications between the server and the client. Establishing a connection to a remote host, with or without encryption or authentication. Listening for incoming connections, sending and receiving data with connectionless protocols. And also, publishing, browsing and resolving network services with Bonjour.
To start off we should that the current Mac OS is a multithreaded environment. Mac OS uses processes and POSIX (Portable Operating System Interface) threads on top of Mach tasks and threads. A process is based on one Mach task and one or more Mach threads. Mach is an intellectual layer that handles scheduling among other things such as inter-process communication. Mac OS defines a thread as the point of control, where a task is there to provide resources for the threads it contains. This division allows for resource distribution and resemblance to be easily accomplished. A task is responsible for the resource management of its threads, which gives the threads very little operating cost. And the pros of Mach threads are that it supports concurrent applications that run on both uniprocessor and multiprocessor machines transparently while getting the benefit of additional processors when they exist. Threads can also migrate between priority levels for a number of reasons. However, this migration is within a given band. The scheduler treats threads marked as being real-time priority differently. A real-time thread tells the scheduler how much cycles it needs. It also tells the scheduler whether those cycles must be contiguous. A real-time thread can be penalized or broken down to normal thread priority. But, only penalizes it only when it exceeds its time quantum without blocking repeatedly. Threads that are heavily compute-bound are intentionally given lower priority to help reduce response time for interactive tasks so that high–priority compute-bound threads cannot control the system and prevent starvation. Starvation is a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU. However, even at a lower priority, the compute-bound threads will run regularly, since the higher–priority I/O-bound threads do only a short amount of processing, block on I/O again, and then allow the compute-bound threads to execute.
The kernel environment of Mac OS and Mach system provides the fundamental thread support. Mach upholds the register part of its threads and schedules them preemptively in relation to one another. In general, multitasking may be either cooperative or preemptive but Mac OS implements cooperative multitasking. In cooperative CPU scheduling the operating system requires that each task voluntarily give up control so that other tasks can execute, -intensive background events might take up so much for a processor’s time which would make more important activities in the foreground would become unresponsive. On the other hand, preemptive multitasking takes control to give execution time to the available tasks. The current Mac OS’s Mach supports preemptive multitasking in which it processes several different tasks at the same time. To have an effect on the structure of the address space, the thread must execute a unique process which will cause the kernel to perform operations on behalf of the thread, or to send a message to some agent on behalf of the thread. In general, these processes operate resources associated with the task containing the thread. Mach presents a flexible framework for thread scheduling policies. Mac OS supports both the multilevel feedback queue scheduling and round-robin scheduling algorithm. The multilevel feedback queue scheduling algorithm partitions the ready queue into several separate queues and allows a process to move between queues. In the multilevel feedback queue scheduling algorithm, each run queue has various priorities that are handled in different ways. A multilevel feedback queue scheduling thread’s priority is raised and reduced to balance its resource consumption against other threads. Round-robin threads execute for a certain time quantum and then quits the queue of threads of equal priority. Setting a round robin thread’s quantum to infinity efficiently makes the thread run-till-block within its priority. The Mach scheduler assigns priorities to incoming processes so the processes that have a higher priority are operated first and operate these mechanisms repeatedly. This means that threads are regularly moving up or down in priority based on their behavior and the conduct of other threads in the system. If multiple processes exist in the same queue, then that is when scheduler runs Round-Robin scheduling algorithm.
Deadlock prevention takes on a new look with the new Mac OS. Because Mac OS uses cooperative multitasking it allows any number of processes to be going on at one time but the OS decides which of these processes gets the processor power. If one program were to crash or hang up the processor the current Mac OS would, like UNIX, not crash but rather close out that process and clean up the memory. Some believe that this is a weaker solution to multitasking than preemptive multitasking that is seen in Windows NT, however, one good way about using cooperative multitasking is that it will not crash the system as often when one process experiences a problem.
Why Mac OS?
To the question why to choose Mac OS, is that operates efficiently without lagging but with high rated performances. However, on the other side PCs often have incompatibility and lagging issues as they are produced by different companies and may not have the right drivers for specific OS and model updates. The strengths of Mac OS are that due to its UNIX core, it is more secure and much less vulnerable to destructive virus attacks. Macintosh is exceptionally steady since every one of its parts is designed and manufactured by one company. Because of the well-designed GUI of Mac OS, it is very user-friendly. Macintosh operating system can run most other operating systems and can even run Windows XP side by side using Parallels Software or Boot Camp.
About Networking, Networking Overview, March 27, 2017
www.developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/Introduction/Introduction.html Accessed April 10, 2018
About the Virtual Memory System, Memory Usage Performance Guidelines, April 23, 2013
www.developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html Accessed April 10, 2018
Mac OS Operating System, Documentation of Operating Systems and Developers,
www.operating-system.org/betriebssystem/_english/bs-macos.htm Accessed April 10, 2018
Kernel Architecture Overview, Kernel Programming Guide, August 08, 2013
www.developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/Architecture/Architecture.html Accessed April 10, 2018
Synchronization Primitives, Kernel Programming Guide, August 08, 2013
www.developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.htm Accessed April 10, 2018
Tomomi Kotera, “Apple’s Macintosh OSX” Web. Published February 23, 2016, Accessed March 30, 2018
www.web.archive.org/web/20090530001035/http://images.apple.com/macosx/pdf/MacOSX_UNIX_TB_v2.pdf Accessed April 10, 2018
Drakos, Nikos (2001) “Advanced Synchronization in Mac OS X: Extending Unix to SMP and Real-Time” URL:
www.usenix.org/publications/library/proceedings/bsdcon02/full_papers/gerbarg/gerbarg_html/ Accessed April 10, 2018