Memory Management in Operating Systems
Memory management in multiple operating systems An operating system is responsible for assigning memory to processes so that processes can be executed. Broadly, this responsibility is defined as memory management, and operating systems handle memory management differently. Any operating system must do two things in order to handle memory effectively. First, an operating system must be able to allocate and free physical memory. Second, an operating system must have techniques in place to keep track of the location of programs in physical memory.
Examples of the ways different operating systems handle memory management can be seen by evaluating the Linux and the Windows 7 operating systems. In order to keep track of the locations of programs in physical memory, the Linux operating system employs virtual memory techniques. “The Linux virtual memory system is responsible for maintaining the address space visible to each process. It creates pages of virtual memory on demand and manages loading those pages from disk and swapping them back out to disk as required. ” (Silberschatz, 2009, p. 823) It is evident that Linux uses a paging strategy with its virtual memory technique.
When the Linux operating system attempts to execute a program, the operating system will not directly access the program from physical memory. Instead, it will access a table of virtual memory addresses that keeps track of physical memory locations. This virtual memory address will then reference the physical memory location of a program so that it can be placed for execution in the CPU. The allocation of physical memory varies depending on the architecture of a computer, but with the Linux operating system, “the primary physical-memory manager in the Linux kernel is the page allocator. (Silberschatz, 2009, p. 820)
The page allocator carries the responsibility of dynamically freeing and allocating all physical memory. The page allocator is a primary tool of all memory subsystems used in the Linux operating system. Of these subsystems, “the most important are the virtual memory system…, the kmalloc() variable-length allocator; the slab allocator, used for allocating memory for kernel data structures; and the page cache, used for caching pages belong to files. ” (Silberschatz, 2009, p. 821)
In Windows, “the memory manager implements virtual memory, provides a core set of services such as memory mapped files, copy-on-write memory, large memory support, and underlying support for the cache manager. ” (Microsoft, 2012) Windows employs virtual memory techniques in a similar way to the Linux operating system. It also uses a process of file mapping in order to keep track of the location of files in physical memory. Virtual memory addresses are tracked in memory and have pointers that reference the physical location of a process on disk.
In order to allocate and free memory, Windows uses a variety of different methods instead of a one-size fits all page allocator like Linux. Each method has different advantages and disadvantages and utilizes different memory management subsystems, the details of which are discussed in Microsoft documentation. These advantages and disadvantages are important for developers. The methods are CoTaskMemAlloc(), GlobalAlloc(), HeapAlloc(), LocalAlloc(), malloc(), new(), and VirtualAlloc().
There are a myriad of memory management techniques, and Windows and Linux, two major operating systems, employ techniques that share similarities but also have differences. According to Abraham Silberschatz (2009), “the memory-management algorithms [used by operating systems] vary from a primitive bare-machine approach to paging and segmentation strategies.