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
  8. wait_on_page

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

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