cgroup limit memory usage failed on Ubuntu?

I want to limit the memory usage of a process using cgroup but failed with error

sh: echo: I/O error

After creating a test dir in /sys/fs/cgroup/memory. I opened two shell, one run sudo sh -c "echo $$ >> cgroup.procs" to set the process, the other is to set memory limit.

It seems it’s ok to set large memory: sudo sh -c "echo 25M > memory.limit_in_bytes" while will fail to set low memmory: sudo sh -c "echo 2M > memory.limit_in_bytes".

OS: Ubuntu 18.04.2 LTS

Source: StackOverflow