blob: 4ad21c5863fdf997330d06b331d315d694ad7e07 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_MMAN_H
2#define _LINUX_MMAN_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <asm/mman.h>
5
6#define MREMAP_MAYMOVE 1
7#define MREMAP_FIXED 2
8
9#define OVERCOMMIT_GUESS 0
10#define OVERCOMMIT_ALWAYS 1
11#define OVERCOMMIT_NEVER 2
David Woodhouse9cdcb562006-04-25 14:18:07 +010012
13#ifdef __KERNEL__
14#include <linux/config.h>
15#include <linux/mm.h>
16
17#include <asm/atomic.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019extern int sysctl_overcommit_memory;
20extern int sysctl_overcommit_ratio;
21extern atomic_t vm_committed_space;
22
23#ifdef CONFIG_SMP
24extern void vm_acct_memory(long pages);
25#else
26static inline void vm_acct_memory(long pages)
27{
28 atomic_add(pages, &vm_committed_space);
29}
30#endif
31
32static inline void vm_unacct_memory(long pages)
33{
34 vm_acct_memory(-pages);
35}
36
37/*
38 * Optimisation macro. It is equivalent to:
39 * (x & bit1) ? bit2 : 0
40 * but this version is faster.
41 * ("bit1" and "bit2" must be single bits)
42 */
43#define _calc_vm_trans(x, bit1, bit2) \
44 ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
45 : ((x) & (bit1)) / ((bit1) / (bit2)))
46
47/*
48 * Combine the mmap "prot" argument into "vm_flags" used internally.
49 */
50static inline unsigned long
51calc_vm_prot_bits(unsigned long prot)
52{
53 return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
54 _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
55 _calc_vm_trans(prot, PROT_EXEC, VM_EXEC );
56}
57
58/*
59 * Combine the mmap "flags" argument into "vm_flags" used internally.
60 */
61static inline unsigned long
62calc_vm_flag_bits(unsigned long flags)
63{
64 return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
65 _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
66 _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
67 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
68}
David Woodhouse9cdcb562006-04-25 14:18:07 +010069#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif /* _LINUX_MMAN_H */