Page 370 - DCAP103_Principle of operating system
P. 370

Unit 12: Processes and Threads in Windows



            thought they would have enough address space forever. They were wrong. The problem is back.   Notes
            Large programs often need more than the 2 GB or 3 GB of user address space Windows 2000
            allocates to them, so bank switching is back, now called address windowing extensions. This
            facility allows programs to map into shuffle chunks of memory in and out of the user portion
            of the address space (and especially above the dreaded 4 GB boundary). Since it is only used
            on servers with more than 2 GB of physical memory, we will defer the discussion until the
            next edition of this site (by which time even entry-level desktop machines will be feeling the
            32-bit pinch).

            12.3.2 Memory Management System Calls
            The Win32 API contains a number of functions that allow a process to manage its virtual
            memory explicitly. The most important of these functions are listed in Figure 12.11. All of them
            operate on a region consisting either of a single page or a sequence of two or more pages that
            are consecutive in the virtual address space.

                        Figure 12.11: The Principal Win32 API Functions for Managing
                                    Virtual Memory in Windows 2000


               Win32 API function    Description
               VirtualAlloc          Reserve or commit a region
               VirtualFree           Release or decommit a region

               VirtualProtect        Change the read/write/execute protection on a region
               VirtualQuery          Inquire about the status of a region
               VirtualLock           Make a region memory resident (i.e., disable paging for it)

               VirtualUnlock         Make a region pageable in the usual way
               CreateFileMapping     Create a file mapping object and (optionally) assign it a name
               MapViewOfFile         Map (part of) a file into the address space
               UnmapViewOfFile       Remove a mapped file from the address space
               OpenFileMapping       Open a previously created file mapping object



            The first four API functions are used to allocate, free, protect and query regions of virtual address
            space. Allocated regions always begin on 64 KB boundaries to minimize porting problems to
            future architectures with pages larger than current ones (up to 64 KB). The actual amount of
            address space allocated can be less than 64 KB, but must be a multiple of the page size. The next
            two give a process the ability to hardware pages in memory so they will not be paged out and to
            undo this property. A real-time program might need this ability, for example. A limit is enforced
            by the operating system to prevent processes from getting too greedy. Actually, the pages can
            be removed from memory, but only if the entire process is swapped out. When it is brought
            back, all the locked pages are reloaded before any thread can start running again. Although
            not shown in Figure 12.11, Windows 2000 also has API functions to allow a process to access
            the virtual memory of a different process over which it has been given control (i.e., for which
            it has a handle). The last four API functions listed are for managing memory-mapped files. To
            map a file, a file mapping object (see Figure 12.4) must first be created, with CreateFileMapping.
            This function returns a handle to the file mapping object and optionally enters a name for it




                                             LOVELY PROFESSIONAL UNIVERSITY                                   363
   365   366   367   368   369   370   371   372   373   374   375