5 #include <linux/percpu_counter.h>
7 #include <linux/atomic.h>
8 #include <uapi/linux/mman.h>
10 extern int sysctl_overcommit_memory
;
11 extern int sysctl_overcommit_ratio
;
12 extern struct percpu_counter vm_committed_as
;
14 unsigned long vm_memory_committed(void);
16 static inline void vm_acct_memory(long pages
)
18 percpu_counter_add(&vm_committed_as
, pages
);
21 static inline void vm_unacct_memory(long pages
)
23 vm_acct_memory(-pages
);
27 * Allow architectures to handle additional protection bits
30 #ifndef arch_calc_vm_prot_bits
31 #define arch_calc_vm_prot_bits(prot) 0
34 #ifndef arch_vm_get_page_prot
35 #define arch_vm_get_page_prot(vm_flags) __pgprot(0)
38 #ifndef arch_validate_prot
40 * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have
41 * already been masked out.
43 * Returns true if the prot flags are valid
45 static inline int arch_validate_prot(unsigned long prot
)
47 return (prot
& ~(PROT_READ
| PROT_WRITE
| PROT_EXEC
| PROT_SEM
)) == 0;
49 #define arch_validate_prot arch_validate_prot
53 * Optimisation macro. It is equivalent to:
54 * (x & bit1) ? bit2 : 0
55 * but this version is faster.
56 * ("bit1" and "bit2" must be single bits)
58 #define _calc_vm_trans(x, bit1, bit2) \
59 ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
60 : ((x) & (bit1)) / ((bit1) / (bit2)))
63 * Combine the mmap "prot" argument into "vm_flags" used internally.
65 static inline unsigned long
66 calc_vm_prot_bits(unsigned long prot
)
68 return _calc_vm_trans(prot
, PROT_READ
, VM_READ
) |
69 _calc_vm_trans(prot
, PROT_WRITE
, VM_WRITE
) |
70 _calc_vm_trans(prot
, PROT_EXEC
, VM_EXEC
) |
71 arch_calc_vm_prot_bits(prot
);
75 * Combine the mmap "flags" argument into "vm_flags" used internally.
77 static inline unsigned long
78 calc_vm_flag_bits(unsigned long flags
)
80 return _calc_vm_trans(flags
, MAP_GROWSDOWN
, VM_GROWSDOWN
) |
81 _calc_vm_trans(flags
, MAP_DENYWRITE
, VM_DENYWRITE
) |
82 _calc_vm_trans(flags
, MAP_LOCKED
, VM_LOCKED
);
84 #endif /* _LINUX_MMAN_H */