OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [mm/] [swap_state.c] - Blame information for rev 1634

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1634 jcastillo
/*
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)
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 index, unsigned long entry)
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 + index, 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,
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
/* We shouldn't be able to have more processes sharing a swapped page than
85
   we can count in the swap map */
86
#if NR_TASKS > SWAP_MAP_MAX
87
#error SWAP_MAP_MAX is too small
88
#endif
89
 
90
void swap_duplicate(unsigned long entry)
91
{
92
        struct swap_info_struct * p;
93
        unsigned long offset, type;
94
 
95
        if (!entry)
96
                return;
97
        offset = SWP_OFFSET(entry);
98
        type = SWP_TYPE(entry);
99
        if (type & SHM_SWP_TYPE)
100
                return;
101
        if (type >= nr_swapfiles) {
102
                printk("Trying to duplicate nonexistent swap-page\n");
103
                return;
104
        }
105
        p = type + swap_info;
106
        if (offset >= p->max) {
107
                printk("swap_duplicate: weirdness, entry %08lx\n", entry);
108
                return;
109
        }
110
        if (!p->swap_map[offset])
111
                printk("swap_duplicate: trying to duplicate unused page, "
112
                       "entry %08lx\n", entry);
113
        else if (p->swap_map[offset] == SWAP_MAP_RESERVED)
114
                printk("swap_duplicate: trying to duplicate reserved page, "
115
                       "entry %08lx\n", entry);
116
        else p->swap_map[offset]++;
117
        return;
118
}
119
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.