fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / vs_memory.h
1 #ifndef _VS_MEMORY_H
2 #define _VS_MEMORY_H
3
4 #include "vserver/limit.h"
5 #include "vserver/base.h"
6 #include "vserver/context.h"
7 #include "vserver/debug.h"
8 #include "vserver/context.h"
9 #include "vserver/limit_int.h"
10
11
12 #define __acc_add_long(a,v)     (*(v) += (a))
13 #define __acc_inc_long(v)       (++*(v))
14 #define __acc_dec_long(v)       (--*(v))
15
16 #if     NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
17 #define __acc_add_atomic(a,v)   atomic_long_add(a,v)
18 #define __acc_inc_atomic(v)     atomic_long_inc(v)
19 #define __acc_dec_atomic(v)     atomic_long_dec(v)
20 #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
21 #define __acc_add_atomic(a,v)   __acc_add_long(a,v)
22 #define __acc_inc_atomic(v)     __acc_inc_long(v)
23 #define __acc_dec_atomic(v)     __acc_dec_long(v)
24 #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
25
26
27 #define vx_acc_page(m,d,v,r) do {                                       \
28         if ((d) > 0)                                                    \
29                 __acc_inc_long(&(m->v));                                \
30         else                                                            \
31                 __acc_dec_long(&(m->v));                                \
32         __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
33 } while (0)
34
35 #define vx_acc_page_atomic(m,d,v,r) do {                                \
36         if ((d) > 0)                                                    \
37                 __acc_inc_atomic(&(m->v));                              \
38         else                                                            \
39                 __acc_dec_atomic(&(m->v));                              \
40         __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
41 } while (0)
42
43
44 #define vx_acc_pages(m,p,v,r) do {                                      \
45         unsigned long __p = (p);                                        \
46         __acc_add_long(__p, &(m->v));                                   \
47         __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
48 } while (0)
49
50 #define vx_acc_pages_atomic(m,p,v,r) do {                               \
51         unsigned long __p = (p);                                        \
52         __acc_add_atomic(__p, &(m->v));                                 \
53         __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
54 } while (0)
55
56
57
58 #define vx_acc_vmpage(m,d) \
59         vx_acc_page(m, d, total_vm,  RLIMIT_AS)
60 #define vx_acc_vmlpage(m,d) \
61         vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
62 #define vx_acc_file_rsspage(m,d) \
63         vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
64 #define vx_acc_anon_rsspage(m,d) \
65         vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
66
67 #define vx_acc_vmpages(m,p) \
68         vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
69 #define vx_acc_vmlpages(m,p) \
70         vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
71 #define vx_acc_file_rsspages(m,p) \
72         vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
73 #define vx_acc_anon_rsspages(m,p) \
74         vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
75
76 #define vx_pages_add(s,r,p)     __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
77 #define vx_pages_sub(s,r,p)     vx_pages_add(s, r, -(p))
78
79 #define vx_vmpages_inc(m)               vx_acc_vmpage(m, 1)
80 #define vx_vmpages_dec(m)               vx_acc_vmpage(m,-1)
81 #define vx_vmpages_add(m,p)             vx_acc_vmpages(m, p)
82 #define vx_vmpages_sub(m,p)             vx_acc_vmpages(m,-(p))
83
84 #define vx_vmlocked_inc(m)              vx_acc_vmlpage(m, 1)
85 #define vx_vmlocked_dec(m)              vx_acc_vmlpage(m,-1)
86 #define vx_vmlocked_add(m,p)            vx_acc_vmlpages(m, p)
87 #define vx_vmlocked_sub(m,p)            vx_acc_vmlpages(m,-(p))
88
89 #define vx_file_rsspages_inc(m)         vx_acc_file_rsspage(m, 1)
90 #define vx_file_rsspages_dec(m)         vx_acc_file_rsspage(m,-1)
91 #define vx_file_rsspages_add(m,p)       vx_acc_file_rsspages(m, p)
92 #define vx_file_rsspages_sub(m,p)       vx_acc_file_rsspages(m,-(p))
93
94 #define vx_anon_rsspages_inc(m)         vx_acc_anon_rsspage(m, 1)
95 #define vx_anon_rsspages_dec(m)         vx_acc_anon_rsspage(m,-1)
96 #define vx_anon_rsspages_add(m,p)       vx_acc_anon_rsspages(m, p)
97 #define vx_anon_rsspages_sub(m,p)       vx_acc_anon_rsspages(m,-(p))
98
99
100 #define vx_pages_avail(m,p,r) \
101         __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
102
103 #define vx_vmpages_avail(m,p)   vx_pages_avail(m, p, RLIMIT_AS)
104 #define vx_vmlocked_avail(m,p)  vx_pages_avail(m, p, RLIMIT_MEMLOCK)
105 #define vx_anon_avail(m,p)      vx_pages_avail(m, p, VLIMIT_ANON)
106 #define vx_mapped_avail(m,p)    vx_pages_avail(m, p, VLIMIT_MAPPED)
107
108 #define vx_rss_avail(m,p) \
109         __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
110
111
112 enum {
113         VXPT_UNKNOWN = 0,
114         VXPT_ANON,
115         VXPT_NONE,
116         VXPT_FILE,
117         VXPT_SWAP,
118         VXPT_WRITE
119 };
120
121 #if 0
122 #define vx_page_fault(mm,vma,type,ret)
123 #else
124
125 static inline
126 void __vx_page_fault(struct mm_struct *mm,
127         struct vm_area_struct *vma, int type, int ret)
128 {
129         struct vx_info *vxi = mm->mm_vx_info;
130         int what;
131 /*
132         static char *page_type[6] =
133                 { "UNKNOWN", "ANON","NONE", "FILE", "SWAP", "WRITE" };
134         static char *page_what[4] =
135                 { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
136 */
137
138         if (!vxi)
139                 return;
140
141         what = (ret & 0x3);
142
143 /*      printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
144                 type, what, ret, page_type[type], page_what[what]);
145 */
146         if (ret & VM_FAULT_WRITE)
147                 what |= 0x4;
148         atomic_inc(&vxi->cacct.page[type][what]);
149 }
150
151 #define vx_page_fault(mm,vma,type,ret)  __vx_page_fault(mm,vma,type,ret)
152 #endif
153
154
155 extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
156
157 #else
158 #warning duplicate inclusion
159 #endif