Skip to contentSkip to conversation

CGROUPS: HowTo: perform force_empty

DISCUSSION PINTU KUMAR 2 participants 4 messages Feb 2, 2015 1 message not in the archive cgroup

lore
Share & tools
lore
#0 lore raw

Hi,

I have a question about memory cgroups under Linux kernel 3.10.
Under: /sys/fs/cgroup/memory/:

I found, memory.force_empty.
But, when I try to do the following it says invalid argument:

# echo 0 > memory.force_empty
sh: echo: write error: Invalid argument

It even fails with "echo 1"

I am using this command from the shell using the root login. Can you tell me how to execute the force_empty command.

Or, how to release all the memory under all cgroups and release it to the system?

Under, mm/memcontrol.c , if I use the function: mem_cgroup_force_empty(struct mem_cgroup *memcg), will it help to release all memory?
But, then, how to initialize the memcg data structure?

Can you provide some example to use this API, from some other kernel sub-system.

Thank you.
Regards,
Pintu

#1 lore raw
Quoted 11 lines · PINTU KUMAR

Hi,

I have a question about memory cgroups under Linux kernel 3.10.
Under: /sys/fs/cgroup/memory/:

I found, memory.force_empty.
But, when I try to do the following it says invalid argument:

# echo 0 > memory.force_empty
sh: echo: write error: Invalid argument

It even fails with "echo 1"

It is not clear on which cgroup you are trying to invoke force_empty. The knob is disabled for the root memcg so I suppose this is why you see the failure.

Quoted 2 lines

I am using this command from the shell using the root login. Can you tell me how to execute the force_empty command.

You can echo anything to the knob to trigger the reclaim.

Quoted 2 lines

Or, how to release all the memory under all cgroups and release it to the system?

Why would you use memcg API to release memory from the system as whole? What are you trying to achieve?

Quoted 5 lines

Under, mm/memcontrol.c , if I use the function: mem_cgroup_force_empty(struct mem_cgroup *memcg), will it help to release all memory?
But, then, how to initialize the memcg data structure?
Can you provide some example to use this API, from some other kernel sub-system.

mem_cgroup_force_empty is an internal memory controller functionality which is not supposed to be used from other kernel subsystems. Why would you want to force reclaim on memcg level from the kernel in the first place?

Signature · 2 lines
Michal Hocko
SUSE Labs

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi,

Quoted 20 lines

-----Original Message-----
From: Michal Hocko [mailto:[email protected]] On Behalf Of Michal Hocko
Sent: Monday, February 02, 2015 5:45 PM
To: PINTU KUMAR
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: CGROUPS: HowTo: perform force_empty

Quoted 10 lines · PINTU KUMAR

Hi,

I have a question about memory cgroups under Linux kernel 3.10.
Under: /sys/fs/cgroup/memory/:

I found, memory.force_empty.
But, when I try to do the following it says invalid argument:

# echo 0 > memory.force_empty
sh: echo: write error: Invalid argument
Quoted 4 lines
Quoted 1 line

It even fails with "echo 1"

It is not clear on which cgroup you are trying to invoke force_empty. The knob is disabled for the root memcg so I suppose this is why you see the

failure.

Quoted 1 line

Ok, please let me know how to use it for specific group, and where to check the group info.
Also, why we should not run it for: root_mem_cgroup

Quoted 11 lines
Quoted 2 lines

I am using this command from the shell using the root login. Can you tell me how to execute the force_empty command.

You can echo anything to the knob to trigger the reclaim.

Quoted 2 lines

Or, how to release all the memory under all cgroups and release it to the system?

Why would you use memcg API to release memory from the system as whole? What are you trying to achieve?

Actually, the problem is that, the system is running with low memory, after few application launch.
When, I see the cgroup: memory.stat, lots are memory is available in cgroups. I also observed that system performs force_reclaim in background, to reclaim some memory from the background cgroup.
But, at some scenario, I wanted to clean-up entire cgroup and start from fresh, without killing the application, or without rebooting the system. This is only for some experiment purpose.

Quoted 10 lines
Quoted 2 lines

Under, mm/memcontrol.c , if I use the function:
mem_cgroup_force_empty(struct mem_cgroup *memcg), will it help to release

all memory?

Quoted 3 lines

But, then, how to initialize the memcg data structure? Can you provide some example to use this API, from some other kernel sub-system.

mem_cgroup_force_empty is an internal memory controller functionality which is not supposed to be used from other kernel subsystems. Why would you want to force reclaim on memcg level from the kernel in the first place?

I observe that force reclaim is already happening, during low memory condition. Similarly, I want to use force_empty option.
But, I worry about, how to initialize the : struct mem_cgroup *memcg What field, and what value I should set in this structure, to pass to force_empty.
This is only for some experiment purpose.

Otherwise, please let me know, how to use the:
try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, ....), which is found in mm/vmscan.c
In any case, I need to know how to initialize the mem_cgroup structure.

Once the experiment results are successful, I will share the details back. Thank you for your reply.

Quoted 3 lines

--
Michal Hocko
SUSE Labs

#4 lore raw
Quoted 22 lines · PINTU KUMAR

Hi,

Quoted 20 lines

-----Original Message-----
From: Michal Hocko [mailto:[email protected]] On Behalf Of Michal Hocko
Sent: Monday, February 02, 2015 5:45 PM
To: PINTU KUMAR
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: CGROUPS: HowTo: perform force_empty

Quoted 10 lines · PINTU KUMAR

Hi,

I have a question about memory cgroups under Linux kernel 3.10.
Under: /sys/fs/cgroup/memory/:

I found, memory.force_empty.
But, when I try to do the following it says invalid argument:

# echo 0 > memory.force_empty
sh: echo: write error: Invalid argument
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

It even fails with "echo 1"

It is not clear on which cgroup you are trying to invoke force_empty. The knob is disabled for the root memcg so I suppose this is why you see the failure.

Ok, please let me know how to use it for specific group, and where to check the group info.

echo foo > $path_to_your_memcg/memory.force_empty

and you can get information about memory consumption for a particular memcg in
cat $path_to_your_memcg/memory.stat

Quoted 1 line

Also, why we should not run it for: root_mem_cgroup

Because the primary motivation for force_empty knob was to free reclaimable pages before the groups itself is removed. If this wasn't done then the pages would stay on LRU and got reclaimed only under memory pressure. The root memcg cannot be removed so it really didn't make much sense to allow the know for it.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

I am using this command from the shell using the root login. Can you tell me how to execute the force_empty command.

You can echo anything to the knob to trigger the reclaim.

Quoted 2 lines

Or, how to release all the memory under all cgroups and release it to the system?

Quoted 8 lines
Quoted 3 lines

Why would you use memcg API to release memory from the system as whole? What are you trying to achieve?

Actually, the problem is that, the system is running with low memory, after few application launch.
When, I see the cgroup: memory.stat, lots are memory is available in cgroups. I also observed that system performs force_reclaim in background, to reclaim some memory from the background cgroup.

Once there is a memory pressure (global or triggered by hard limit on memcg) there is a memory reclaim activated which scans and reclaims memcgs proportionally.

Quoted 3 lines

But, at some scenario, I wanted to clean-up entire cgroup and start from fresh, without killing the application, or without rebooting the system. This is only for some experiment purpose.

I am not sure I understand. How do you want to clean up the group when there are still tasks running in them? What about memory consumed by those tasks?

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

Under, mm/memcontrol.c , if I use the function:
mem_cgroup_force_empty(struct mem_cgroup *memcg), will it help to release all memory?
But, then, how to initialize the memcg data structure?
Can you provide some example to use this API, from some other kernel sub-system.

mem_cgroup_force_empty is an internal memory controller functionality which is not supposed to be used from other kernel subsystems. Why would you want to force reclaim on memcg level from the kernel in the first place?

Quoted 5 lines

I observe that force reclaim is already happening, during low memory condition. Similarly, I want to use force_empty option.
But, I worry about, how to initialize the : struct mem_cgroup *memcg What field, and what value I should set in this structure, to pass to force_empty.

You definitely shouldn't abuse memcg internals to trigger memcg reclaim. There is a good reason why that API is not exported for external use.

Quoted 9 lines

This is only for some experiment purpose.

Otherwise, please let me know, how to use the:
try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, ....), which is found in mm/vmscan.c
In any case, I need to know how to initialize the mem_cgroup structure.

Once the experiment results are successful, I will share the details back. Thank you for your reply.

Signature · 2 lines
Michal Hocko
SUSE Labs