Skip to content

core: introduce MemorySwapMax#3659

Merged
poettering merged 1 commit intosystemd:masterfrom
walyong:memory_swap_limit_v02
Aug 31, 2016
Merged

core: introduce MemorySwapMax#3659
poettering merged 1 commit intosystemd:masterfrom
walyong:memory_swap_limit_v02

Conversation

@walyong
Copy link
Contributor

@walyong walyong commented Jul 5, 2016

Similar to MemoryMax=, MemorySwapMax= limits swap usage. This controls
controls "memory.swap.max" attribute in unified cgroup.

@walyong
Copy link
Contributor Author

walyong commented Jul 5, 2016

This PR is new version of #2171.

log_cgroup_compat(u, "Applying MemoryLimit %" PRIu64 " as MemoryMax", max);

swap_max = c->memory_swap_limit;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This translation doesn't make sense to me. memsw of cgroup v1 and swap of cgroup v2 have very different semantics and I don't think it'd be a good idea to translate the two back and forth this way. Given that systemd omits other aspects of memcg on cgroup v1 and that memsw is difficult to wrap one's head around, I'd recommend just implementing swap max for cgroup v2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd followed the max = c->memory_limit; for swap_max. But I'm agreeing to your opinion. Because the unified cgroup swap is operating different with legacy cgroup as menthioned at:

The combined memory+swap accounting and limiting is replaced by real
control over swap space.
https://www.kernel.org/doc/Documentation/cgroup-v2.txt

So memory_limit and memory_swap_limit have to be used only for legacy cgroup. And memory_max and memory_swap_max have to be used only for unified cgroup.

I will rework this soon.

Thanks you for comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we should add new options just for the legacy hierarchy. I think we should add these new settings only for the new hierarchy, and accept that the legacy stays the way it is...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemd has already two memory control options.
MemoryMax=bytes is for "memory.max" unified hierarchy control group attribute. MemoryLimit=bytes is for "memory.limit_in_bytes" legacy control group attribute.

Now, I'd like to add two memory options, MemorySwapMax= and MemorySwapLimit=. Do you want to add only MemorySwapMax= option?
Many of systems are still using legacy cgroup. So, to support legacy, I think both options are needed. Further, there are difference in memory operations between legacy and unified. At legacy, memory.memsw.limit_in_bytes is accounting and limiting memory+swap. But, at unified, memory.swap.max handles only swap.

So, I think, systemd needs both options to make a pair of corresponding memory control option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the memsw semantics is a bit too confusing especially given that it goes away with v2 and am not too sure how useful memsw limit is. So, I'd much prefer just adding the knob for v2. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea would be to only add memorySwapMax=, but leave MemorySwapLimit= out.

@poettering
Copy link
Member

Patch looks pretty OK code-wise, but I think it would be best to follow @htejun's advice and only expose the cgroupsv2 version of this for now. Any chance you could rework the patch accordingly?

@poettering poettering added cgroups reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Jul 25, 2016
@poettering
Copy link
Member

(And sorry for taking so long to review this!)

@walyong walyong changed the title core: introduce MemorySwapMax= and MemorySwapLimit= core: introduce MemorySwapMax Aug 25, 2016
@walyong
Copy link
Contributor Author

walyong commented Aug 25, 2016

Sorry for my late rework.

I removed codes for MemorySwapLimit=. So this PR includes MemorySwapMax=only. (i.e. only for unified cgroup)

According to .github/CONTRIBUTING.md:

After you have pushed a new version, try to remove the reviewed/needs-rework label. Also add a comment about the new version (no notification is sent just for the commits, so it's easy to miss the update without an explicit comment).

But I can not remove reviewed/needs-rework tag.

if (cgroup_context_has_unified_memory_config(c)) {
max = c->memory_max;
else {
swap_max = c->memory_swap_max;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, the logic is kinda weird here. Also with @max. How about removing initialization of @max and init @swap_max to CGROUP_LIMIT_MAX? Or just init both @max and @swap_max to CGROUP_LIMIT_MAX.

Copy link
Member

@zonque zonque Aug 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads-up: this isn't kerneldoc. On GitHub, you mention a user named "max" with that @-notation :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the heads-up @zonque. :)

@htejun
Copy link
Contributor

htejun commented Aug 25, 2016

It prolly needs documentation updates too?

@poettering
Copy link
Member

looks pretty good. Misses documentation though. Could you add a short description of this to the man page, please?

(don't mind the label thing: apparently only admins of the project can add/remove them. That's why I wrote "try" in that text...)

Similar to MemoryMax=, MemorySwapMax= limits swap usage. This controls
controls "memory.swap.max" attribute in unified cgroup.
@poettering poettering merged commit cf08b48 into systemd:master Aug 31, 2016
@walyong walyong deleted the memory_swap_limit_v02 branch September 1, 2016 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cgroups pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks

Development

Successfully merging this pull request may close these issues.

4 participants