Monday, August 25, 2008

SEB 070012 - Tutorial 4

Virtual Memory: Windows VS Linux

Virtual Memory

Windows

Linux
Implement of virtual memory

How each one handles page faults, page sizes

How it reconciles thrashing issues.

All processes running under 32 bit Windows gets virtual memory addresses ( virtual address space) going from 0 to 4 GB, no matter how much RAM is actually installed on the computer. 2 GB of this virtual address space are designated for each process’ private use and the other 2 GB are shared between all processes and the operating system.

requires elevated privileges, cooperation from the application making the large allocation (usually setting a flag to ask the operating system for huge pages), or manual administrator configuration; operating systems commonly, sometimes by design, cannot page them out to disk. Windows Server 2003 (SP1 and newer), Windows Vista and Windows Server 2008 support huge pages under the name of large pages, but Windows XP does not.

When the memory in use by all the existing processes exceeds the amount of RAM available, the operating system will move pages (4 KB pieces) of one or more virtual address spaces to the computer’s hard disk

Windows uses structured exception handling to report page fault-based invalid accesses as access violation exceptions. If the program that received the error does not handle it, then Windows typically performs some sort of default action, typically involving the termination of the running process that caused the error condition, and a notification to the user that the program has malfunctioned.

To prevent thrashing, Windows provide a process with as many frames as it needs. Windows will also increase the amount of RAM in the system to eliminate the cause of trashing. Besides, it also reduce the amount of RAM needed by reconfiguring the applications, removing unneeded system services, or running fewer applications at a time.

Virtual memory divides the virtual address space into equal-sized pieces called virtual pages. Virtual pages have a fixed size that is an integer power of 2. Linux can be configured to use a size of 4, 8, 16, or 64 kb to maximize the performance. Linux kernel creates and maintains page table and also employs the CPU memory management unit (MMU) to translate the virtual address of a process into physical address in order to store the data. Linux has supported huge pages on several architectures since the 2.6 series.

Linux could create appropriate page-table entries whenever a range of virtual memory is allocated. However, this is wasteful because most programs allocate much more virtual memory than they ever use at any given time. So Linux uses a method called demand paging. With this, the virtual address space starts out empty.

Page fault is intercepted by the Linux kernel and causes the page fault handler to be activated. Linux uses signals, such as SIGSEGV, to report these error conditions to programs. Because Linux uses demand paging and page-fault-based optimizations such as copy-on-write, page faults occur during the normal course of operation and do not necessarily indicate an error. Thus, when the page fault handler is invoked, it first needs to determine whether the page fault is caused by an access to a valid page. If not, the page fault handler simply sends a segmentation violation signal to the faulting process and returns. Otherwise, it takes one of several possible actions:

-If the page is being accessed for the first time, the handler allocates a new page frame and initializes it, e.g., by reading its content from disk. Page faults caused by first-time accesses are called demand_page_faults.

-If the page has been paged out to swap space, the handler reads it back from disk into a newly allocated page frame.

-If the page fault occurred because of a page-fault-based optimization (such as copy-on-write), the handler takes the appropriate recovery action (such as performing the delayed page copy).

Linux picks a page frame that backs a virtual page that has not been accessed recently, writes it out to a special area on the disk called the swap space, and then reuses the page frame to back the new virtual page. Then marked the page swapped out as not present. Linux can support multiple swap space areas, each of which can be either an entire disk partition or a specially formatted file on an existing file system. With this swapping method, thrashing is reconciled.



References:
http://www.informit.com/articles/article.aspx?p=29961
http://en.wikipedia.org/wiki/Virtual_memory
http://en.wikipedia.org/wiki/Page_fault
http://support.microsoft.com/kb/555223
http://en.wikipedia.org/wiki/Page_size#Page_size_trade-off


Tuesday, August 5, 2008

SEB070012 - Tutorial 3

Core Functions of an Operating System


1. Recognizing input from the input hardware.

2. Sending output to the display screen, normally monitor.

3. Keep files and directories on the disk.

4. Control peripheral devices such as disk drive and printer.

5. Make sure that different programs or users that run at the same time do not interfere each other in the memory in used.

6. Ensure that unauthorized users do not access the system.

7. Act as the host for application program to run on the computer.

8. handle the details of the operation of the hardware to relieve application programs from having to manage these details and makes it easier to write applications.

9. Support the running/execution of programs by the users.

10. Schedules the activities of the CPU and resources and make job more efficient and to prevent deadlock .

11. Provides an additional working memory on USB flash devices and can be combined with SuperFetch.

12. Support a variety of networking protocols. This means computers with different type of operating system are also able to connect to each other.

13. Gives information about the status of operation of each application to the user and sends messages about the errors that may have occurred .

14. Transforms the the physical world of devices, instructions, memory, and time into virtual world (graphical).

15. Creating a file system which enable the user to manage the file and its document (rename, copy, paste, cut, delete, relocate, etc.)

16. Provide a medium of interaction between computer and user.

17. Provide System tools (programs) used to monitor computer performance, debug problems, or maintain parts of the system.

18. Temporarily store application memory which is accessed less frequently on disk or other media to make the space available for other programs.

19. Ensure that all programs are given regular time on the CPU. This implies that all programs must be limited in how much time they are allowed to spend on the CPU without being interrupted.

20. Distinguish between requests which should be allowed to be processed, and others which should not be processed.

21. Provides a set of libraries or functions which programs may use to perform specific tasks especially relating to interfacing with computer system components.


Monday, August 4, 2008

Detail Functions of Operating System

1. Act as the base when running the application software.

OS acts as the base of application software. Application program is like the branches, it can't grow out if there is no trunk. So OS is like the trunk of a tree. Both OS and application software must work together to get the fruits (work done).

2. Handle the details of each hardware.

As a host of a computer, one of the purposes of the operating system is to handle the details of hardware. This relieves the application software from having to manage the details and therefore it is easier to write an application.

3. Program execution

Support the running program by the users is the basic function of the operating system. In a multiprogramming operating system, running program is normally referred to as processes. Process management refers to the facilities provided by the operating system to support the creation, execution, and destruction of process, and to facilitate different kind of interaction, and limit others.

4. Handle interrupts

In modern operating system, interrupts are handled by the operating system's kernel (the central component of most computer OS). Interrupts may come from either computer hardware or a running program. When either of them triggers the interrupt, the OS kernel decides how to deal with this event, generally by running some process code, or just ignoring it.

5. Memory management

The multiprogramming OS's kernel is responsible in managing all the system memory which in use by programs. This is to ensure a program does not interfere the memory that is already used by another running program. Since programs are used at the same time, each program must has an independant access to the memory.

6. Virtual memory addressing

Virtual memory addressing means the kernel can choose which memory each program may use at any given time, allowing the operating system to use the same memory locations for multiple tasks. In modern OS, application memory which is accessed less frequently can be temporarily stored in disk or other media to make that space available for other programs.

7. Networking

Operating systems support a variety of networking protocols. This means that computers running dissimilar operating systems can participate in a common network for sharing resources such as files, printer, scanner, wireless connection, etc.