>
> Dividing inside the kernel (especially by a variable) is a
> recipe for disaster - don't do that ... ever! :)
You dont want me to wear that tshirt i see !
So we can account only for PAGE_SIZE or 1:
----------------------------------------------------------------
--- ../linux-4.4.111/kernel/vserver/limit.c 2018-01-14 10:20:44.395367243 +0100
+++ ./kernel/vserver/limit.c 2018-01-20 10:45:34.396558271 +0100
@@ -270,9 +270,15 @@
res_limit = mem_cgroup_mem_limit_pages(mcg);
res_usage = mem_cgroup_mem_usage_pages(mcg);
- if (res_limit != PAGE_COUNTER_MAX)
- val->totalram = res_limit;
- val->freeram = val->totalram - res_usage;
+ if (res_limit != PAGE_COUNTER_MAX) {
+ if ( val->mem_unit == 1 ) {
+ val->totalram = res_limit >> PAGE_SHIFT;
+ val->freeram = val->totalram - ( res_usage >> PAGE_SHIFT );
+ } else {
+ val->totalram = res_limit;
+ val->freeram = val->totalram - res_usage;
+ }
+ }
val->bufferram = 0;
val->totalhigh = 0;
val->freehigh = 0;
@@ -303,17 +309,21 @@
goto out;
swap_limit = memsw_limit - res_limit;
- /* we have a swap limit? */
- if (memsw_limit != PAGE_COUNTER_MAX)
- val->totalswap = swap_limit;
+ /* calculate swap part */
+ swap_usage = (memsw_usage > res_usage) ? memsw_usage - res_usage : 0;
- /* calculate swap part */
- swap_usage = (memsw_usage > res_usage) ?
- memsw_usage - res_usage : 0;
-
- /* total shown minus usage gives free swap */
- val->freeswap = (swap_usage < swap_limit) ?
- val->totalswap - swap_usage : 0;
+ /* we have a swap limit? */
+ if (memsw_limit != PAGE_COUNTER_MAX){
+ /* sysinfo unit is bytes OR PAGE_SIZE ? */
+ if ( val->mem_unit == 1 ) {
+ val->totalswap = swap_limit >> PAGE_SHIFT;
+ val->freeswap = (swap_usage < swap_limit) ? ( swap_limit - swap_usage ) >> PAGE_SHIFT : 0;
+ } else {
+ val->totalswap = swap_limit;
+ val->freeswap = (swap_usage < swap_limit) ? swap_limit - swap_usage : 0;
+
+ }
+ }
out:
#else /* !CONFIG_MEMCG_SWAP */
val->totalswap = 0;
----------------------------------------------------------------
sounds cool ?
Ghislain.
Received on Sat Jan 20 09:46:27 2018