I'm trying to make ansible
set InnoDB buffer pool size to some percent of available memory. But ansible_memtotal_mb
and free
report how much memory the host has. How do I figure out how much memory is available from inside container? Container name is not known in advance.
UPD I'm running debian jessie
, and pass cgroup_enable=memory
parameter to the kernel.
host
====
# lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-3.16.0-4-amd64
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
# grep cgroup /var/lib/lxc/sta/config
lxc.cgroup.memory.limit_in_bytes = 1000M
# mount | grep memory
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
# cd /sys/fs/cgroup/memory
# cat memory.limit_in_bytes
18446744073709551615
# cat lxc/sta/memory.limit_in_bytes
1048576000
container
=========
$ cat /proc/self/cgroup
9:perf_event:/lxc/sta
8:blkio:/
7:net_cls,net_prio:/lxc/sta
6:freezer:/lxc/sta
5:devices:/
4:memory:/
3:cpu,cpuacct:/
2:cpuset:/lxc/sta
1:name=systemd:/user.slice/user-0.slice/session-10304.scope/system.slice/ssh.service
# mount | grep memory
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
# cd /sys/fs/cgroup/memory
# cat memory.limit_in_bytes
18446744073709551615
# cat lxc/sta/memory.limit_in_bytes
1048576000