Skip to content

Fix memory update to -1#22578

Closed
boynux wants to merge 1 commit intomoby:masterfrom
boynux:fix-memory-update
Closed

Fix memory update to -1#22578
boynux wants to merge 1 commit intomoby:masterfrom
boynux:fix-memory-update

Conversation

@boynux
Copy link
Contributor

@boynux boynux commented May 7, 2016

- What I did
Close #22516

- How I did it
If memory parameter is not changed by update command set is as '-1'

- How to verify it
docker create --name test -m 50m busybox:latest
docker inspect -f '{{.HostConfig.Memory}}' test
#52428800
docker update -m -1 test
docker inspect -f '{{.HostConfig.Memory}}' test
# -1


docker run -it -d --name test2 -m 50m busybox:latest
docker stats test2
# Shows 50m memory limit
docker update -m -1 test2
docker stats test2
# Shows no memory limits (host memory)

- Description for the changelog
Remove memory constraints after creating/running container with update command

Possibility to set memory to '-1' which removes memory constraints

Signed-off-by: boynux [email protected]

@boynux boynux force-pushed the fix-memory-update branch 2 times, most recently from 5b20ac4 to e98bea3 Compare May 8, 2016 09:51
@runcom
Copy link
Member

runcom commented May 8, 2016

ping @hqhq

@boynux
Copy link
Contributor Author

boynux commented May 8, 2016

There is a bug in my pull request I'm trying to fix that.

@boynux boynux force-pushed the fix-memory-update branch from 527ed44 to d4b761f Compare May 8, 2016 15:28
@boynux
Copy link
Contributor Author

boynux commented May 8, 2016

Pull request is ready for review, and I'm not sure why windowsTP5 is failing!
Ping @hqhq @runcom

@hqhq
Copy link
Contributor

hqhq commented May 9, 2016

I think it makes more sense to use docker update --memory -1 <id> to unset memory limit to unlimited, because it's the way to reflect cgroup api.

@boynux
Copy link
Contributor Author

boynux commented May 9, 2016

@hqhq yes, seems more legit. I'll update my changes accordingly. I guess that would a bit easier as well.

@thaJeztah thaJeztah added the status/failing-ci Indicates that the PR in its current state fails the test suite label May 9, 2016
@boynux boynux force-pushed the fix-memory-update branch 2 times, most recently from 68b107c to c59cec3 Compare May 10, 2016 20:43
@boynux
Copy link
Contributor Author

boynux commented May 11, 2016

ping @hqhq I'm done with your suggested changes, and I think gccgo failure is not related to my changes.

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label May 11, 2016
@boynux boynux force-pushed the fix-memory-update branch from ceb8d3d to 3096cde Compare May 11, 2016 07:34
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label May 11, 2016
@hqhq
Copy link
Contributor

hqhq commented May 11, 2016

@boynux Thanks, but docs need to be updated as well.

@boynux
Copy link
Contributor Author

boynux commented May 11, 2016

@hqhq sure, actually I wanted to ask this question. Where are the docs please?

Update:
I update Cli docs please let me know if other docs need update as well.

@thaJeztah thaJeztah removed the status/failing-ci Indicates that the PR in its current state fails the test suite label May 11, 2016
@hqhq
Copy link
Contributor

hqhq commented May 16, 2016

@boynux It's not working in my box:

$ docker update -m -1 d3cc5496e730
Error response from daemon: Cannot update container d3cc5496e730be54b9c109a5216fa92aa5ec7ed3c2382266850e6eda0947b71b: rpc error: code = 2 desc = "failed to write 4294967295 to memory.limit_in_bytes: write /sys/fs/cgroup/memory/docker/d3cc5496e730be54b9c109a5216fa92aa5ec7ed3c2382266850e6eda0947b71b/memory.limit_in_bytes: invalid argument\n"

I guess your change is not complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not sufficient to update a created container, you should also update a started container.

Copy link
Contributor Author

@boynux boynux May 17, 2016

Choose a reason for hiding this comment

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

correct, I'll add more tests.

@boynux
Copy link
Contributor Author

boynux commented May 17, 2016

@hqhq Regarding your test, that's interesting, the integration tests does exactly what you did and it passes the test (false-positive?). I also tried that several times with no issues. Would you please provide the create/run command for your container as well.

I'll check again to see if something is missing.

@hqhq
Copy link
Contributor

hqhq commented May 18, 2016

@boynux The integration test updates a stopped container, and my test is update a running container, just use:

$ docker run -ti --rm -n test -m 300M ubuntu bash
[switch to another terminal]
$ docker update -m -1 test

@LK4D4
Copy link
Contributor

LK4D4 commented May 23, 2016

@boynux do you still have time to work on this?

@boynux
Copy link
Contributor Author

boynux commented May 23, 2016

Sorry I was very busy last week and this week too. I partially implemented
the run part but not ready to submit.

I don't promise this week but definitely next week I'm able to finish the
work. If there is schedule to release this this week then I'd suggest
someone picks up the last part otherwise I'll finish that by next week. (I
don't promise but if I find some time free this week I'll try to finish
that).

On Mon, May 23, 2016, 10:40 PM Alexander Morozov [email protected]
wrote:

@boynux https://github.com/boynux do you still have time to work on
this?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#22578 (comment)

@coolljt0725
Copy link
Contributor

@boynux set swap memory to -1 and then set memory to -1 still doesn't work ? what's the issue?

@justincormack
Copy link
Contributor

@boynux can you rebase? Can take another look and see if we can resolve.

@boynux
Copy link
Contributor Author

boynux commented Sep 25, 2016

I've rebased the my fork against master. Unfortunately my tests are broken now (which used to work :( )

@boynux
Copy link
Contributor Author

boynux commented Sep 27, 2016

Wow! All test passed! What's going on here?
ping @coolljt0725, @justincormack

@mlaventure
Copy link
Contributor

I couldn't test the swap option, the memory one works for me.

LGTM if someone can check the swap update.

re-ping @coolljt0725, @justincormack

@coolljt0725
Copy link
Contributor

sorry for late response, missing some note from github _:)

This doesn't work for me, I need to unset the memory.memsw.limit_in_bytes before docker update -m -1 xxx.

[root@fedora docker]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
64e9cbd26239        busybox             "sh"                31 seconds ago      Up 30 seconds                           agitated_boyd
[root@fedora docker]# cd 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b/
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# cat memory.limit_in_bytes
209715200
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# cat memory.memsw.limit_in_bytes
419430400
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# docker update -m -1 64e9cbd26239
Error response from daemon: Cannot update container 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b: rpc error: code = 2 desc = failed to write -1 to memory.limit_in_bytes: write /sys/fs/cgroup/memory/docker/64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b/memory.limit_in_bytes: invalid argument
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# echo -1 > memory.memsw.limit_in_bytes
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# docker update -m -1 64e9cbd26239
64e9cbd26239
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# docker version
Client:
 Version:      1.13.0-dev
 API version:  1.25
 Go version:   go1.6.3
 Git commit:   43922d0
 Built:        Tue Oct 18 08:46:30 2016
 OS/Arch:      linux/amd64
 Experimental: true

Server:
 Version:      1.13.0-dev
 API version:  1.25
 Go version:   go1.6.3
 Git commit:   43922d0
 Built:        Tue Oct 18 08:46:30 2016
 OS/Arch:      linux/amd64
 Experimental: true
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# cat memory.memsw.limit_in_bytes
9223372036854771712
[root@fedora 64e9cbd26239c17b669e3529f7f017370336d051b7cb6c2738cadc2cb724f64b]# cat memory.limit_in_bytes
9223372036854771712


Before unset the memory limit, we need to unset the --memory-swap first if the system has enable the memory swap limit because docker will set the memory swap limit to double the memory limit by default.

@mlaventure maybe your system doesn't enable memory swap limit or am I missing something?

@boynux
Copy link
Contributor Author

boynux commented Oct 18, 2016

I'll write a test for that. It would be easier to test it that way.

@mlaventure
Copy link
Contributor

mlaventure commented Oct 18, 2016

@coolljt0725 correct, memsw isn't enabled on my system :)

@boynux
Copy link
Contributor Author

boynux commented Oct 18, 2016

@coolljt0725 Your test suggests to also update containerd to reset swap? or it's sufficient to do it here? I'm not sure containerd does this in the correct order.

Update: I'm pretty unfamiliar with this code but I guess this is the issue: https://github.com/opencontainers/runc/blob/d1fc80226409b687245e2180d335827027bc3cca/libcontainer/cgroups/fs/memory.go#L98

From the tests I did it seems memory update happens before Swap limit, we can either update runC accordingly or split this into two requests. Or maybe I'm totally lost

@boynux
Copy link
Contributor Author

boynux commented Oct 18, 2016

@coolljt0725 @mlaventure I found the issue, this commit in RunC solves the problem (with some tweaks on Docker side)
So the issue is RunC simply ignores swap changes when it's -1 I just check to see if memory is set to -1 and then silently set swap mem to -1 too. So it passes Kernel validation.

Now what is the process to commit these changes into RunC? Should I do a PR and relate it to this ticket?

RunC Changes: boynux/runc@41afa94

@mlaventure
Copy link
Contributor

@boynux yes, you will need to open a PR in the runc repo (https://github.com/opencontainers/runc). Once merge, we then need to update containerd to use the new version, then vendor containerd here 😅

@boynux
Copy link
Contributor Author

boynux commented Oct 19, 2016

Ok, cool. Then I will submit a PR for RunC, once merged I'll update here.
Thanks

@boynux
Copy link
Contributor Author

boynux commented Oct 20, 2016

@hqhq Can you review RunC pull request please.

Copy link
Contributor

Choose a reason for hiding this comment

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

This if condition is not needed.

So we're hacking like:
uint64(-1) = 18446744073709551615
int64(18446744073709551615) = -1

Is everyone comfortable with that? I prefer we change value type to explicitly say we allow negative value here.

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 removed if statement as it's not needed, I think that was left over from master rebase.
The type change requires change to `containerd' types here: https://github.com/docker/containerd/blob/master/api/grpc/types/api.pb.go#L469

I can update that too, it makes sense to use int64 instead. Please give a thumbs up if my proposed change is correct.

Possibility to set memory to '-1' which indicates no memory imits.

Signed-off-by: boynux <[email protected]>
@boynux boynux force-pushed the fix-memory-update branch from e6edeeb to 57e386c Compare December 1, 2016 08:55
@thaJeztah
Copy link
Member

I'm going to close this for now, because we need the changes in RunC, but ping me when that is merged, then we can reopen

@thaJeztah thaJeztah closed this Dec 22, 2016
kolyshkin added a commit to kolyshkin/runc that referenced this pull request Apr 2, 2020
In cgroupv1, command `runc update $ID --memory -1` sets both
memory and memory+swap to -1 (aka unlimited). This was introduced
by commit 18ebc51 (Reset Swap when memory is set to unlimited,
Oct 19 2016).

This is not the case for cgroupv2. Fix it.

References:
 - opencontainers#1127
 - moby/moby#22578

Signed-off-by: Kir Kolyshkin <[email protected]>
kolyshkin added a commit to kolyshkin/runc that referenced this pull request Apr 2, 2020
In cgroupv1, command `runc update $ID --memory -1` sets both
memory and memory+swap to -1 (aka unlimited). This was introduced
by commit 18ebc51 (Reset Swap when memory is set to unlimited,
Oct 19 2016).

This is not the case for cgroupv2. Fix it.

References:
 - opencontainers#1127
 - moby/moby#22578

Signed-off-by: Kir Kolyshkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.