100%(1)1 out of 1 people found this document helpful
This preview shows page 47 - 49 out of 177 pages.
One of the principal advantages of virtual memory is that each process has its ownvirtual address space, which is mapped to physical memory by the operating system.In this chapter we will discuss the process address space and how Linux manages it.The kernel treats the userspace portion of the address space very differently tothe kernel portion. For example, allocations for the kernel are satisfied immediately1and are visible globally no matter what process is on the CPU. With a process, spaceis simply reserved in the linear address space by pointing a page table entry to aread-only globally visible page filled with zeros. On writing, a page fault is triggeredwhich results in a new page being allocated, filled with zeros2, placed in the pagetable entry and marked writable.The userspace portion is not trusted or presumed to be constant.After eachcontext switch, the userspace portion of the linear address space can potentiallychange except when alazy Translation Lookaside Buffer (TLB)switch is used asdiscussed later in Section 5.3. As a result of this, the kernel must be prepared tocatch all exception and addressing errors raised from userspace. This is discussed inSection 5.5.This chapter begins with how the linear address space is broken up and whatthe purpose of each section is. We then cover the structures maintained to describeeach process, how they are allocated, initialised and then destroyed. Next, we willcover how individual regions within the process space are created and all the variousfunctions associated with them. That will bring us to exception handling related tothe process address space, page faulting and the various cases that occur to satisfya page fault. Finally, we will cover how the kernel safely copies information to andfrom userspace.1vmalloc()is partially an exception as a minor page fault may occur to update the processpage tables, but the page will still be allocated immediately upon request.2It is filled with zeros so that the new page will appear exactly the same as the global zero filledpage to userspace47
5.1. Linear Address Space485.1Linear Address SpaceFrom a user perspective, the address space is a flat linear address space but pre-dictably, the kernel’s perspective is very different. The linear address space is splitinto two parts, the userspace part which potentially changes with each full contextswitch and the kernel address space which remains constant. The location of thesplit is determined by the value ofPAGE_OFFSETwhich is at0xC0000000on the x86.This means that 3GiB is available for the process to use while the remaining 1GiBis always mapped by the kernel.The linear virtual address space as the kernel sees it is illustrated in Figure 5.1.