Sorry, I found when I ran `echo 3 > /proc/sys/vm/drop_caches`, the leak memory was released very slowly.
The `Page Cache` of the opened log file is the reason to cause leak. Because the `struct page` contains
`struct mem_cgroup *mem_cgroup` which has a large chunk of memory. Thanks everyone for helping me to
solve the problem.
The last question: If I alloc many small pages and not free them, will I exhaust the memory ( because every page contains `mem_cgroup` )?
Sorry, there's a leak indeed. The memory was leaking all the time and I tried to run command `echo 3 > /proc/sys/vm/drop_caches`, it didn't help.
But when I delete the log files which was created by the failed systemd service, the leak(cached) memory was released.
I suspect the leak is relevant to the inode objects.
At 2018-11-19 16:30:45, "Vladimir Davydov" <vdavydov.dev@gmail.com> wrote:
>On Sun, Nov 18, 2018 at 08:44:14AM +0800, dong wrote:
>> First of all,I can see memory leak when I run ‘free -g’ command.
>
>This doesn't mean there's a leak. The kernel may postpone freeing memory
>until there's memory pressure. In particular cgroup objects are not
>released until there are objects allocated from the corresponding kmem
>caches. Those objects may be inodes or dentries, which are freed lazily.
>Looks like restarting a service causes recreation of a memory cgroup and
>hence piling up dead cgroups. Try to drop caches.
>
>>So I enabled kmemleak. I got the messages above. When I run ‘cat
>>/sys/kernel/debug/kmemleak’, nothing came up. Instead, the ‘dmesg’
>>command show me the leak messages. So the messages is not the leak
>>reason?How can I detect the real memory leak?Thanks!