\chapter{Miscellaneous}
\section{Page Flags}\label{pageflags}

\newcommand{\mtable}[2]{
\vspace{8pt}
\noindent \begin{tabularx}{15cm}{#1}#2
\end{tabularx}
\vspace{8pt}
}


This section will describe the bit values the page$\rightarrow$flags
can have. The are all declared in \url{include/linux/mm.h}. This is a
description of each bit. 
\nopagebreak

\begin{description}
\idx{PG\_locked} This bit is set when the page must be locked in memory
                for disk I/O. When I/O starts, this bit is set and released
                when it completes 
                
\idx{PG\_error} If an error occurs during disk I/O, this bit is set 

\idx{PG\_referenced} If a page is mapped and it is referenced through the
                mapping,index hash table, this bit is set. It's used during
                page replacement for moving the page around the LRU lists 
                
\idx{PG\_uptodate} When a page is read from disk without error, this bit will
                be set.  
                
\idx{PG\_dirty} This indicates if a page needs to be flushed to disk. When
                a page is written to that is backed by disk, it is not
                flushed immediately, this bit is needed to ensure a dirty
                page is not freed before it's written out 
                
\idx{PG\_unused} This bit is literally unused 

\idx{PG\_lru}   If a page is on either the active\_list or the inactive\_list,
                this bit will be set. 
                
\idx{PG\_active} This bit is set if a page is on the active\_list LRU and
                cleared when it is removed. It marks a page as been hot.                 
\idx{PG\_slab}  This will flag a page as been used by the slab allocator 

\idx{PG\_skip}   Used by some architectures so skip over parts of the address
                space.         
                
\idx{PG\_highmem} Pages in high memory cannot be mapped permanetly by the
                kernel. Pages that are in high memory are flagged with 
                this bit during \texttt{ mem\_init} 
                
\idx{PG\_checked} Only used by the EXT2 filesystem 

\idx{PG\_arch\_1} Quoting directly from the code. \emph{PG\_arch\_1 is an
                architecture specific page state bit.  The generic code 
                guarantees that this bit is cleared for a page when it
                first is entered into the page cache} 

\idx{PG\_reserved} This is set for pages that can never be swapped out. It is
                set during init until the machine as booted up. Later it
                is used to flag empty pages or ones that do not even exist 

\idx{PG\_launder} This bit is important only to the page replacement policy.
                When the VM wants to swap out a page, it will set this
                bit and call the writepage function. When scanning,
                it encounters a page with this bit and PG\_locked set,
                it will wait for the I/O to complete 

\end{description}


There are helper macros provided to help set, test and clear the bits.

\mtable{llll}{
\texttt{ Bit name}      & \texttt{ Set}        & \texttt{ Test}       & \texttt{ Clear} \\
PG\_locked      & LockPage   & PageLocked & UnlockPage \\
PG\_error       & SetPageError & PageError & ClearPageError\\
PG\_referenced  & SetPageReferenced & PageReferenced & ClearPageReferenced \\
PG\_uptodate    & SetPageUptodate & PageUptodate & ClearPageUptodate \\
PG\_dirty       & SetPageDirty & PageDirty & ClearPageDirty \\
PG\_unused      & n/a & n/a & n/a \\
PG\_lru         & TestSetPageLRU & PageLRU & TestClearPageLRU \\
PG\_active      & SetPageActive & PageActive & ClearPageActive \\
PG\_slab        & PageSetSlab & PageSlab & PageClearSlab \\
PG\_skip        & n/a & n/a & n/a \\
PG\_highmem     & n/a & PageHighMem & n/a \\
PG\_checked     & SetPageChecked & PageChecked & n/a\\
PG\_arch\_1     & n/a & n/a & n/a\\
PG\_reserved    & SetPageReserved & PageReserved & ClearPageReserved\\
PG\_launder     & SetPageLaunder & PageLaunder & ClearPageLaunder \\
}
