cleanup
[linux-2.4.21-pre4.git] / mm / swap.c
1 /*
2  *  linux/mm/swap.c
3  *
4  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
5  */
6
7 /*
8  * This file contains the default values for the opereation of the
9  * Linux VM subsystem. Fine-tuning documentation can be found in
10  * linux/Documentation/sysctl/vm.txt.
11  * Started 18.12.91
12  * Swap aging added 23.2.95, Stephen Tweedie.
13  * Buffermem limits added 12.3.98, Rik van Riel.
14  */
15
16 #include <linux/mm.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/swap.h>
19 #include <linux/swapctl.h>
20 #include <linux/pagemap.h>
21 #include <linux/init.h>
22
23 #include <asm/dma.h>
24 #include <asm/uaccess.h> /* for copy_to/from_user */
25 #include <asm/pgtable.h>
26
27 /* How many pages do we try to swap or page in/out together? */
28 int page_cluster;
29
30 pager_daemon_t pager_daemon = {
31         512,    /* base number for calculating the number of tries */
32         SWAP_CLUSTER_MAX,       /* minimum number of tries */
33         8,      /* do swap I/O in clusters of this size */
34 };
35
36 /*
37  * Move an inactive page to the active list.
38  */
39 static inline void activate_page_nolock(struct page * page)
40 {
41         if (PageLRU(page) && !PageActive(page)) {
42                 del_page_from_inactive_list(page);
43                 add_page_to_active_list(page);
44         }
45 }
46
47 void activate_page(struct page * page)
48 {
49         spin_lock(&pagemap_lru_lock);
50         activate_page_nolock(page);
51         spin_unlock(&pagemap_lru_lock);
52 }
53
54 /**
55  * lru_cache_add: add a page to the page lists
56  * @page: the page to add
57  */
58 void lru_cache_add(struct page * page)
59 {
60         if (!PageLRU(page)) {
61                 spin_lock(&pagemap_lru_lock);
62                 if (!TestSetPageLRU(page))
63                         add_page_to_inactive_list(page);
64                 spin_unlock(&pagemap_lru_lock);
65         }
66 }
67
68 /**
69  * __lru_cache_del: remove a page from the page lists
70  * @page: the page to add
71  *
72  * This function is for when the caller already holds
73  * the pagemap_lru_lock.
74  */
75 void __lru_cache_del(struct page * page)
76 {
77         if (TestClearPageLRU(page)) {
78                 if (PageActive(page)) {
79                         del_page_from_active_list(page);
80                 } else {
81                         del_page_from_inactive_list(page);
82                 }
83         }
84 }
85
86 /**
87  * lru_cache_del: remove a page from the page lists
88  * @page: the page to remove
89  */
90 void lru_cache_del(struct page * page)
91 {
92         spin_lock(&pagemap_lru_lock);
93         __lru_cache_del(page);
94         spin_unlock(&pagemap_lru_lock);
95 }
96
97 /*
98  * Perform any setup for the swap system
99  */
100 void __init swap_setup(void)
101 {
102         unsigned long megs = num_physpages >> (20 - PAGE_SHIFT);
103
104         /* Use a smaller cluster for small-memory machines */
105         if (megs < 16)
106                 page_cluster = 2;
107         else
108                 page_cluster = 3;
109         /*
110          * Right now other parts of the system means that we
111          * _really_ don't want to cluster much more
112          */
113 }