Page 276 - DCAP403_Operating System
P. 276
Unit 13: Case Study: Linux
The processor specific page fault handling code must locate the vm_area_struct data structure Notes
that describes the area of virtual memory that contains the faulting virtual address. It does this
by searching the vm_area_struct data structures for this process until it finds the one containing
the faulting virtual address. This is very time critical code and a processes vm_area_struct data
structures are so arranged as to make this search take as little time as possible.
Having carried out the appropriate processor specific actions and found that the faulting virtual
address is for a valid area of virtual memory, the page fault processing becomes generic and
applicable to all processors that Linux runs on.
The generic page fault handling code looks for the page table entry for the faulting virtual address.
If the page table entry it finds is for a swapped out page, Linux must swap the page back into
physical memory. The format of the page table entry for a swapped out page is processor specifi c
but all processors mark these pages as invalid and put the information necessary to locate the
page within the swap file into the page table entry. Linux needs this information in order to bring
the page back into physical memory.
At this point, Linux knows the faulting virtual address and has a page table entry containing
information about where this page has been swapped to. The vm_area_struct data structure may
contain a pointer to a routine which will swap any page of the area of virtual memory that it
describes back into physical memory. This is its swapin operation. If there is a swapin operation
for this area of virtual memory then Linux will use it. This is, in fact, how swapped out System
V shared memory pages are handled as it requires special handling because the format of a
swapped out System V shared page is a little different from that of an ordinary swapped out
page. There may not be a swapin operation, in which case Linux will assume that this is an
ordinary page that does not need to be specially handled.
It allocates a free physical page and reads the swapped out page back from the swap fi le.
Information telling it where in the swap file (and which swap file) is taken from the the invalid
page table entry.
If the access that caused the page fault was not a write access then the page is left in the swap
cache and its page table entry is not marked as writable. If the page is subsequently written
to, another page fault will occur and, at that point, the page is marked as dirty and its entry is
removed from the swap cache. If the page is not written to and it needs to be swapped out again,
Linux can avoid the write of the page to its swap file because the page is already in the swap
fi le.
If the access that caused the page to be brought in from the swap file was a write operation,
this page is removed from the swap cache and its page table entry is marked as both dirty and
writable.
13.6 File Systems
The first thing that most new users shifting from Windows will find confusing is navigating
the Linux filesystem. The Linux filesystem does things a lot more differently than the Windows
filesystem. This article explains the differences and takes you through the layout of the Linux
fi lesystem.
For starters, there is only a single hierarchal directory structure. Everything starts from the root
directory, represented by ‘/’, and then expands into sub-directories. Where DOS/Windows had
various partitions and then directories under those partitions, Linux places all the partitions
under the root directory by ‘mounting’ them under specific directories. Closest to root under
Windows would be c:.
Under Windows, the various partitions are detected at boot and assigned a drive letter. Under
Linux, unless you mount a partition or a device, the system does not know of the existence of that
partition or device. This might not seem to be the easiest way to provide access to your partitions
or devices but it offers great fl exibility.
LOVELY PROFESSIONAL UNIVERSITY 269