Page 259 - DCAP103_Principle of operating system
P. 259

Principles of Operating Systems



                   Notes
                                       few_vnode           vnode of the file system swap directory (/paging) under
                                                           which the swap files are created.
                                       fsw_bsize           Block size used on this file system; used to determine
                                                           how much space fsw_reserve is reserving.
                                       fsw_head            Index into swaptab [ ] of first, last entry
                                       fsw_tail            associated with this file system swap.

                                       fsw_mntpoint        File system mount point; character representation of
                                                           fsw_vnode,  used  for  utilities  (such  as  swapinfo  (1M)
                                                           and error messages.



                                 7.6.7.2 Swaptab and Swapmap Structures
                                 Two  structures  track  swap  space.  The  swaptab[ ]  array  tracks  a  chunk  of  swap  space.
                                 swapmap entries hold swap information on a per-page level. swaptab defaults to track a
                                 2MB chunk of space and swapmap tracks each page within that 2MB chunk. Each entry
                                 in the swaptab[ ] array has a pointer (called st_swpmp) to a unique swapmap. swapmap
                                 entries have backwards pointers to the swaptab index. There is one entry in the swapmap for
                                 each page represented by the swaptab entry (default 2 MB, or 512 pages); that is, swapmap
                                 conforms in size to swchunk. A linked list of free swap pages begin at the swaptab entry’s
                                 st_free and use each free swapmap entry’s sm_next. When a page of swap is needed, the
                                 kernel walks the structures (using the getswap( ) routine in vm_swalloc.c), which calls other
                                 routines that actually locate the chunk, and so forth.
                                    •  Beginning with the lowest priority, we begin by examining swdev_pri[].curr, which points
                                      to a swdevt entry.
                                    •  If sw_nfpgs is zero (no free pages), we follow the pointer sw_next to get the next swdevt
                                      entry at this priority.
                                    •  If none of these have free pages, we move on to swfs pri[].curr, the file system swap at
                                      this priority, checking fsw_nfpgs for free pages.
                                 If we are still unsuccessful, we move to the next priority and try again.

                                    •  Once we find a swdevt or fswdevt with free pages, we walk that device’s swaptab list,
                                      starting with sw head or fsw head, and using st next in each swaptab entry, until we find
                                      a swaptab entry with non-zero st nfpgs.
                                    •  st free points to the first free swapmap entry (and thus first free page) in this swaptab
                                      chunk.

                                    •  The  swalloc( )  routine  creates  a  disk  block  descriptor  (dbd)  using  14  bits  of  dbd_data
                                      for the swaptab index and 14 bits for the swapmap index. The r_bstore in the region is
                                      set to the disk device vnode or the file system directory vnode, and the dbd is marked
                                      DBD_BSTORE.
                                 When faulting in from swap, the same process is followed as for faulting in from the file system:
                                 r_bstore and dbd_data are hashed together and checked for a soft fault, then devswap_pagein( )
                                 is called. The devswap_pagein( ) routine uses the dbd_data as a 14-bit swaptab index and a 14-
                                 bit swapmap index to determine the location of the page on disk. Now all information needed
                                 to retrieve the page from swap has been stored.






        252                               LOVELY PROFESSIONAL UNIVERSITY
   254   255   256   257   258   259   260   261   262   263   264