[Users] fake swap != 0 in VE? (solved)

Thomas Sattler sattler at med.uni-frankfurt.de
Wed Feb 13 04:50:49 EST 2008


> Why not
> mount --bind fakememinfo /proc/meminfo
> inside the VE? Would be easiest, but the
> contents will not match real meminfo
> because they do not get updated.

I didn't expect this to work ...
... But it does. :-)

I attached a little script to be run as root
inside a VE to fake swap. 512MB are default,
you can change it on the commandline:

Output is, in the example above, cut at "free"
to prevent linewrap:

# free -m
              total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:            0          0          0

# openvz_fake_swap
              total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:          512          0        512

# openvz_fake_swap 4096
              total       used       free
Mem:          4096        104       3991
-/+ buffers/cache:        104       3991
Swap:         4096          0       4096

Thanks a lot!
Thomas

-------------- next part --------------
#!/bin/bash

SWAP="${1:-512}"

NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"

umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo

free -m



More information about the Users mailing list