1 #ifndef _VX_LIMIT_INT_H
2 #define _VX_LIMIT_INT_H
8 #define VXD_RCRES_COND(r) VXD_CBIT(cres, (r))
9 #define VXD_RLIMIT_COND(r) VXD_CBIT(limit, (r))
11 extern const char *vlimit_name[NUM_LIMITS];
13 static inline void __vx_acc_cres(struct vx_info *vxi,
14 int res, int dir, void *_data, char *_file, int _line)
16 if (VXD_RCRES_COND(res))
17 vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
18 (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
19 (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
20 (dir > 0) ? "++" : "--", _data, _file, _line);
25 __rlim_inc(&vxi->limit, res);
27 __rlim_dec(&vxi->limit, res);
30 static inline void __vx_add_cres(struct vx_info *vxi,
31 int res, int amount, void *_data, char *_file, int _line)
33 if (VXD_RCRES_COND(res))
34 vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
35 (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
36 (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
37 amount, _data, _file, _line);
42 __rlim_add(&vxi->limit, res, amount);
46 int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
48 int cond = (value > __rlim_rmax(limit, res));
51 __rlim_rmax(limit, res) = value;
56 int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
58 int cond = (value < __rlim_rmin(limit, res));
61 __rlim_rmin(limit, res) = value;
66 void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
68 if (!__vx_cres_adjust_max(limit, res, value))
69 __vx_cres_adjust_min(limit, res, value);
75 -1 ... over soft limit
76 0 ... over hard limit */
78 static inline int __vx_cres_avail(struct vx_info *vxi,
79 int res, int num, char *_file, int _line)
81 struct _vx_limit *limit;
84 if (VXD_RLIMIT_COND(res))
85 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
86 (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
87 (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
88 (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
89 (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
95 value = __rlim_get(limit, res);
97 if (!__vx_cres_adjust_max(limit, res, value))
98 __vx_cres_adjust_min(limit, res, value);
103 if (__rlim_soft(limit, res) == RLIM_INFINITY)
105 if (value + num <= __rlim_soft(limit, res))
108 if (__rlim_hard(limit, res) == RLIM_INFINITY)
110 if (value + num <= __rlim_hard(limit, res))
113 __rlim_hit(limit, res);
118 static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
121 rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
123 rlim_t value, sum = 0;
126 while ((res = *array++)) {
127 value = __rlim_get(limit, res);
128 __vx_cres_fixup(limit, res, value);
135 rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
137 rlim_t value = __vx_cres_array_sum(limit, array + 1);
140 if (value == __rlim_get(limit, res))
143 __rlim_set(limit, res, value);
144 /* now adjust min/max */
145 if (!__vx_cres_adjust_max(limit, res, value))
146 __vx_cres_adjust_min(limit, res, value);
151 static inline int __vx_cres_array_avail(struct vx_info *vxi,
152 const int *array, int num, char *_file, int _line)
154 struct _vx_limit *limit;
165 value = __vx_cres_array_sum(limit, array+1);
167 __rlim_set(limit, res, value);
168 __vx_cres_fixup(limit, res, value);
170 return __vx_cres_avail(vxi, res, num, _file, _line);
174 static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
179 /* complex resources first */
180 if ((id < 0) || (id == RLIMIT_RSS))
181 __vx_cres_array_fixup(limit, VLA_RSS);
183 for (res=0; res<NUM_LIMITS; res++) {
184 if ((id > 0) && (res != id))
187 value = __rlim_get(limit, res);
188 __vx_cres_fixup(limit, res, value);
190 /* not supposed to happen, maybe warn? */
191 if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
192 __rlim_rmax(limit, res) = __rlim_hard(limit, res);
197 #endif /* __KERNEL__ */
198 #endif /* _VX_LIMIT_INT_H */