Skip to contentSkip to conversation

Do we need remote charging for cpu and cpuacct subsys?

Question Hao Lee 3 participants 7 messages Jul 2, 2021 – Jul 9, 2021

Subsystems (2)
lore
Share & tools
lore

Hao Lee

author
#0 lore raw

Hi,

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

I want to know if the community has a plan to do this? What will the community approach look like?

I think we need to move the active_memcg to a separated active_cgroup struct, and the latter will contain active_memcg, active_tg, and active_cpuacct.

Regards,
Hao Lee

#1 lore raw

Hello,

Quoted 6 lines · Hao Lee

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

I also want to see this upstream, and am actually working on it right now, have been for some time.

So far, this is needed to properly account multithreaded padata jobs, memory reclaim, and net rx. Android folks have raised this issue in the past too, though I'm not aware of the specific kthreads that are giving them problems.

So naturally, I'm curious about your use case and how it may be different from these others. What kworkers would you like to account?

Quoted 2 lines

I want to know if the community has a plan to do this? What will the community approach look like?

There has been discussion about this here,

https://lore.kernel.org/lkml/[email protected]/

more recently here,

https://lore.kernel.org/lkml/[email protected]/

and we may talk about it at LPC:

https://www.linuxplumbersconf.org/event/11/page/104-accepted-microconferences#cont-perform

Quoted 2 lines

I think we need to move the active_memcg to a separated active_cgroup struct, and the latter will contain active_memcg, active_tg, and active_cpuacct.

I'm not seeing how that could work for cases that don't know the cgroup when the remote charging period begins. The only one I'm aware of that's like that is net rx, where the work to process packets has to start before their ultimate destination, and therefore cgroup, is known.

thanks,
Daniel

#2 lore raw

+ Android folks

Quoted 10 lines · Daniel Jordan

Hello,

Quoted 6 lines · Hao Lee

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

Quoted 7 lines

I also want to see this upstream, and am actually working on it right now, have been for some time.

So far, this is needed to properly account multithreaded padata jobs, memory reclaim, and net rx. Android folks have raised this issue in the past too, though I'm not aware of the specific kthreads that are giving them problems.

Pavan, Wei, do you have any details about this?

Quoted 28 lines

So naturally, I'm curious about your use case and how it may be different from these others. What kworkers would you like to account?

Quoted 2 lines

I want to know if the community has a plan to do this? What will the community approach look like?

There has been discussion about this here,

   https://lore.kernel.org/lkml/20200219214112.4kt573kyzbvmbvn3-S51bK0XF4qpuJJETbFA3a0B3C2bhBk7L0E9HWUfgJXw@public.gmane.org/

more recently here,

https://lore.kernel.org/lkml/YGxjwKbec68sCcqo-NiLfg/[email protected]/

and we may talk about it at LPC:

https://www.linuxplumbersconf.org/event/11/page/104-accepted-microconferences#cont-perform

Quoted 2 lines

I think we need to move the active_memcg to a separated active_cgroup struct, and the latter will contain active_memcg, active_tg, and active_cpuacct.

I'm not seeing how that could work for cases that don't know the cgroup when the remote charging period begins. The only one I'm aware of that's like that is net rx, where the work to process packets has to start before their ultimate destination, and therefore cgroup, is known.

thanks,
Daniel

author
#3 lore raw
In reply to Daniel Jordan
Quoted 14 lines · Daniel Jordan

Hello,

Quoted 6 lines · Hao Lee

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

I also want to see this upstream, and am actually working on it right now, have been for some time.

Quoted 7 lines

So far, this is needed to properly account multithreaded padata jobs, memory reclaim, and net rx. Android folks have raised this issue in the past too, though I'm not aware of the specific kthreads that are giving them problems.

So naturally, I'm curious about your use case and how it may be different from these others. What kworkers would you like to account?

Thanks. We use a workqueue to perform asynchronous reclaim for cgroups. The kworker may consume lots of CPU cycles if the cgroup memory pressure is extremely high, so we want to charge the cpu usage to the related cgroup for which the kworker works. Otherwise, the reclaim kworker will steal cpu time from the system level, which breaks the resource isolation.

Quoted 8 lines
Quoted 3 lines

I want to know if the community has a plan to do this? What will the community approach look like?

There has been discussion about this here,

   https://lore.kernel.org/lkml/20200219214112.4kt573kyzbvmbvn3-S51bK0XF4qpuJJETbFA3a0B3C2bhBk7L0E9HWUfgJXw@public.gmane.org/

Yes, our work is very similar to Johannes'.

Quoted 7 lines

more recently here,

https://lore.kernel.org/lkml/YGxjwKbec68sCcqo-NiLfg/[email protected]/

and we may talk about it at LPC:

https://www.linuxplumbersconf.org/event/11/page/104-accepted-microconferences#cont-perform

I also found that you posted a patchset in 2019 to introduce a cgroup-aware workqueue. In that discussion, back-charging is considered to be a suitable solution.

    https://lore.kernel.org/lkml/20190611195549.GL3341036-LpCCV3molIbIZ9tKgghJQw2O0Ztt9esIQQ4Iyu8u01E@public.gmane.org/

I also have a question here. Are the back-charging and remote charging the same thing?

Quoted 6 lines
Quoted 3 lines

I think we need to move the active_memcg to a separated active_cgroup struct, and the latter will contain active_memcg, active_tg, and active_cpuacct.

I'm not seeing how that could work for cases that don't know the cgroup when the remote charging period begins.

This is indeed a problem. Neither cgroup-aware kthread nor remote charging can address this. Maybe this is the biggest obstacle hindering fine-grained charging.

Quoted 3 lines

The only one I'm aware of
that's like that is net rx, where the work to process packets has to start before their ultimate destination, and therefore cgroup, is known.

Sorry. Is this a typo? It seems the word "known" should be "unknown"...

Regards,
Hao Lee

Quoted 3 lines

thanks,
Daniel

#4 lore raw

Hi,

[only replying now b/c I was out most of this week]

Quoted 9 lines · Hao Lee
Quoted 2 lines · Daniel Jordan

So naturally, I'm curious about your use case and how it may be different from these others. What kworkers would you like to account?

Thanks. We use a workqueue to perform asynchronous reclaim for cgroups. The kworker may consume lots of CPU cycles if the cgroup memory pressure is extremely high, so we want to charge the cpu usage to the related cgroup for which the kworker works. Otherwise, the reclaim kworker will steal cpu time from the system level, which breaks the resource isolation.

Ok, that helps.

Quoted 2 lines

I also have a question here. Are the back-charging and remote charging the same thing?

Basically yes.

Quoted 5 lines
Quoted 3 lines

The only one I'm aware of
that's like that is net rx, where the work to process packets has to start before their ultimate destination, and therefore cgroup, is known.

Sorry. Is this a typo? It seems the word "known" should be "unknown"...

What I'm saying is, the work to process packets starts when the cgroup is unknown.

maintainer
#5 lore raw
In reply to Hao Lee

Hello,

Quoted 9 lines · Hao Lee

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

I want to know if the community has a plan to do this? What will the community approach look like?

Yeah, we need sth like this to account for cpu cycles spent in commont path but caused by specific cgroups - e.g. memory reclaim, net packet rx and so on. There were some mentions of needing somthing like that but haven't been any patchsets or concrete efforts that I know of.

Thanks.

Signature · 1 line
tejun
author
#6 lore raw
Quoted 11 lines · Tejun Heo

Hello,

Quoted 7 lines · Hao Lee

memcg currently has a remote charging mechanism that can charge usage to other memcg instead of the one the task belongs to.

In our environment, we need to account the cpu usage consumed by some kworkers to a specific cgroup. Thus, we want to introduce a remote-charging mechanism to cpu and cpuacct subsys in our kernel.

Quoted 7 lines
Quoted 2 lines

I want to know if the community has a plan to do this? What will the community approach look like?

Yeah, we need sth like this to account for cpu cycles spent in commont path but caused by specific cgroups - e.g. memory reclaim, net packet rx and so on. There were some mentions of needing somthing like that but haven't been any patchsets or concrete efforts that I know of.

Thanks for this reply. I am interested in this area because this feature would be very useful in our containerized environment. I will track related discussions and want to do some work related to remote charging.

Quoted 5 lines

Thanks.

--
tejun