root/include/linux/pagemap.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. page_address
  2. _page_hashfn
  3. find_page
  4. remove_page_from_hash_queue
  5. add_page_to_hash_queue
  6. remove_page_from_inode_queue
  7. add_page_to_inode_queue

   1 #ifndef _LINUX_PAGEMAP_H
   2 #define _LINUX_PAGEMAP_H
   3 
   4 /*
   5  * Page-mapping primitive inline functions
   6  *
   7  * Copyright 1995 Linus Torvalds
   8  */
   9 
  10 static inline unsigned long page_address(struct page * page)
     /* [previous][next][first][last][top][bottom][index][help] */
  11 {
  12         return PAGE_OFFSET + PAGE_SIZE*(page - mem_map);
  13 }
  14 
  15 #define PAGE_HASH_BITS 10
  16 #define PAGE_HASH_SIZE (1 << PAGE_HASH_BITS)
  17 
  18 #define PAGE_AGE_VALUE 16
  19 
  20 extern unsigned long page_cache_size;
  21 extern struct page * page_hash_table[PAGE_HASH_SIZE];
  22 
  23 /*
  24  * We use a power-of-two hash table to avoid a modulus,
  25  * and get a reasonable hash by knowing roughly how the
  26  * inode pointer and offsets are distributed (ie, we
  27  * roughly know which bits are "significant")
  28  */
  29 static inline unsigned long _page_hashfn(struct inode * inode, unsigned long offset)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31 #define i (((unsigned long) inode)/sizeof(unsigned long))
  32 #define o (offset >> PAGE_SHIFT)
  33 #define s(x) ((x)+((x)>>PAGE_HASH_BITS))
  34         return s(i+o) & (PAGE_HASH_SIZE-1);
  35 #undef i
  36 #undef o
  37 #undef s
  38 }
  39 
  40 #define page_hash(inode,offset) page_hash_table[_page_hashfn(inode,offset)]
  41 
  42 static inline struct page * find_page(struct inode * inode, unsigned long offset)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44         struct page *page;
  45 
  46         for (page = page_hash(inode, offset); page ; page = page->next_hash) {
  47                 if (page->inode != inode)
  48                         continue;
  49                 if (page->offset != offset)
  50                         continue;
  51                 page->age = PAGE_AGE_VALUE | (page->age >> 1);
  52                 page->count++;
  53                 break;
  54         }
  55         return page;
  56 }
  57 
  58 static inline void remove_page_from_hash_queue(struct page * page)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         struct page **p = &page_hash(page->inode,page->offset);
  61 
  62         page_cache_size--;
  63         if (page->next_hash)
  64                 page->next_hash->prev_hash = page->prev_hash;
  65         if (page->prev_hash)
  66                 page->prev_hash->next_hash = page->next_hash;
  67         if (*p == page)
  68                 *p = page->next_hash;
  69         page->next_hash = page->prev_hash = NULL;
  70 }
  71 
  72 static inline void add_page_to_hash_queue(struct inode * inode, struct page * page)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74         struct page **p = &page_hash(inode,page->offset);
  75 
  76         page_cache_size++;
  77         page->age = PAGE_AGE_VALUE;
  78         page->prev_hash = NULL;
  79         if ((page->next_hash = *p) != NULL)
  80                 page->next_hash->prev_hash = page;
  81         *p = page;
  82 }
  83 
  84 static inline void remove_page_from_inode_queue(struct page * page)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         struct inode * inode = page->inode;
  87 
  88         page->inode = NULL;
  89         inode->i_nrpages--;
  90         if (inode->i_pages == page)
  91                 inode->i_pages = page->next;
  92         if (page->next)
  93                 page->next->prev = page->prev;
  94         if (page->prev)
  95                 page->prev->next = page->next;
  96         page->next = NULL;
  97         page->prev = NULL;
  98 }
  99 
 100 static inline void add_page_to_inode_queue(struct inode * inode, struct page * page)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         struct page **p = &inode->i_pages;
 103 
 104         inode->i_nrpages++;
 105         page->inode = inode;
 106         page->prev = NULL;
 107         if ((page->next = *p) != NULL)
 108                 page->next->prev = page;
 109         *p = page;
 110 }
 111 
 112 extern void update_vm_cache(struct inode *, unsigned long, const char *, int);
 113 
 114 #endif

/* [previous][next][first][last][top][bottom][index][help] */