root/mm/swap_state.c

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

DEFINITIONS

This source file includes following definitions.
  1. show_swap_cache_info
  2. add_to_swap_cache
  3. init_swap_cache
  4. swap_duplicate

   1 /*
   2  *  linux/mm/swap_state.c
   3  *
   4  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
   5  *  Swap reorganised 29.12.95, Stephen Tweedie
   6  */
   7 
   8 #include <linux/mm.h>
   9 #include <linux/sched.h>
  10 #include <linux/head.h>
  11 #include <linux/kernel.h>
  12 #include <linux/kernel_stat.h>
  13 #include <linux/errno.h>
  14 #include <linux/string.h>
  15 #include <linux/stat.h>
  16 #include <linux/swap.h>
  17 #include <linux/fs.h>
  18 #include <linux/swapctl.h>
  19 
  20 #include <asm/dma.h>
  21 #include <asm/system.h> /* for cli()/sti() */
  22 #include <asm/segment.h> /* for memcpy_to/fromfs */
  23 #include <asm/bitops.h>
  24 #include <asm/pgtable.h>
  25 
  26 /*
  27  * To save us from swapping out pages which have just been swapped in and
  28  * have not been modified since then, we keep in swap_cache[page>>PAGE_SHIFT]
  29  * the swap entry which was last used to fill the page, or zero if the
  30  * page does not currently correspond to a page in swap. PAGE_DIRTY makes
  31  * this info useless.
  32  */
  33 unsigned long *swap_cache;
  34 
  35 #ifdef SWAP_CACHE_INFO
  36 unsigned long swap_cache_add_total = 0;
  37 unsigned long swap_cache_add_success = 0;
  38 unsigned long swap_cache_del_total = 0;
  39 unsigned long swap_cache_del_success = 0;
  40 unsigned long swap_cache_find_total = 0;
  41 unsigned long swap_cache_find_success = 0;
  42 
  43 void show_swap_cache_info(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45         printk("Swap cache: add %ld/%ld, delete %ld/%ld, find %ld/%ld\n",
  46                 swap_cache_add_total, swap_cache_add_success, 
  47                 swap_cache_del_total, swap_cache_del_success,
  48                 swap_cache_find_total, swap_cache_find_success);
  49 }
  50 #endif
  51 
  52 int add_to_swap_cache(unsigned long addr, unsigned long entry)
     /* [previous][next][first][last][top][bottom][index][help] */
  53 {
  54         struct swap_info_struct * p = &swap_info[SWP_TYPE(entry)];
  55 
  56 #ifdef SWAP_CACHE_INFO
  57         swap_cache_add_total++;
  58 #endif
  59         if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
  60                 entry = xchg(swap_cache + MAP_NR(addr), entry);
  61                 if (entry)  {
  62                         printk("swap_cache: replacing non-NULL entry\n");
  63                 }
  64 #ifdef SWAP_CACHE_INFO
  65                 swap_cache_add_success++;
  66 #endif
  67                 return 1;
  68         }
  69         return 0;
  70 }
  71 
  72 unsigned long init_swap_cache(unsigned long mem_start,
     /* [previous][next][first][last][top][bottom][index][help] */
  73         unsigned long mem_end)
  74 {
  75         unsigned long swap_cache_size;
  76 
  77         mem_start = (mem_start + 15) & ~15;
  78         swap_cache = (unsigned long *) mem_start;
  79         swap_cache_size = MAP_NR(mem_end);
  80         memset(swap_cache, 0, swap_cache_size * sizeof (unsigned long));
  81         return (unsigned long) (swap_cache + swap_cache_size);
  82 }
  83 
  84 void swap_duplicate(unsigned long entry)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         struct swap_info_struct * p;
  87         unsigned long offset, type;
  88 
  89         if (!entry)
  90                 return;
  91         offset = SWP_OFFSET(entry);
  92         type = SWP_TYPE(entry);
  93         if (type & SHM_SWP_TYPE)
  94                 return;
  95         if (type >= nr_swapfiles) {
  96                 printk("Trying to duplicate nonexistent swap-page\n");
  97                 return;
  98         }
  99         p = type + swap_info;
 100         if (offset >= p->max) {
 101                 printk("swap_duplicate: weirdness\n");
 102                 return;
 103         }
 104         if (!p->swap_map[offset]) {
 105                 printk("swap_duplicate: trying to duplicate unused page\n");
 106                 return;
 107         }
 108         p->swap_map[offset]++;
 109         return;
 110 }
 111 

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