Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

update: Return memory to host on memory update. #793

Closed

Conversation

jcvenegas
Copy link
Member

If memory update will reduce memory we want to get memory
back to the host and restrict the guest to use more memory.

$ docker exec -ti kata-1 free -h
              total        used        free      shared  buff/cache   available
Mem:           5.9G         23M        5.8G        8.2M         18M        5.8G
Swap:            0B          0B          0B
$ docker update --memory 2G kata-1
kata-1
$ docker exec -ti kata-1 free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G         56M        1.8G        8.2M         18M        1.8G
Swap:            0B          0B          0B

Fixes: #790

Signed-off-by: Jose Carlos Venegas Munoz jose.carlos.venegas.munoz@intel.com

@jcvenegas jcvenegas added wip feature New functionality labels Sep 27, 2018
@jcvenegas
Copy link
Member Author

jcvenegas commented Sep 27, 2018

Create container with 6GB and stress the memory with 75%

+ docker run -tdi --name kata-1 -m 6G --rm --runtime kata-runtime stress-ng bash
55d15db690fc059f66edc9f286add9856e9eaf29f033b5a0c0ea3f4feb462d4d
+ docker exec -ti kata-1 free -h
              total        used        free      shared  buff/cache   available
Mem:           5.9G         24M        5.8G        8.2M         18M        5.8G
Swap:            0B          0B          0B
# qemu memory consumption (smem)
  PID User     Command                         Swap      USS      PSS      RSS
28465 root     /opt/kata/bin/qemu-system-x        0   286.4M   286.4M   286.4M
+ docker exec -ti kata-1 stress-ng --vm 1 --vm-bytes 75% --vm-method all --verify -t 20s -v
stress-ng: debug: [12] 1 processor online, 1 processor configured
stress-ng: debug: [12] main: can't set oom_score_adj
stress-ng: info:  [12] dispatching hogs: 1 vm
stress-ng: debug: [12] cache allocate: default cache size: 16384K
stress-ng: debug: [12] starting stressors
stress-ng: debug: [12] 1 stressor spawned
stress-ng: debug: [16] stress-ng-vm: can't set oom_score_adj
stress-ng: debug: [16] stress-ng-vm: started [16] (instance 0)
stress-ng: debug: [16] stress-ng-vm using method 'all'
stress-ng: debug: [16] stress-ng-vm: exited [16] (instance 0)
stress-ng: debug: [12] process [16] terminated
stress-ng: info:  [12] successful run completed in 20.16s
# qemu memory consumption (smem)
  PID User     Command                         Swap      USS      PSS      RSS
28465 root     /opt/kata/bin/qemu-system-x        0     4.6G     4.6G     4.6G

update memory to reduce it.

With balloon:

+ docker update --memory 1G kata-1
kata-1
+ sleep 5s
+ docker exec -ti kata-1 free -h
              total        used        free      shared  buff/cache   available
Mem:           898M         40M        839M        8.2M         18M        795M
Swap:            0B          0B          0B
# qemu memory consumption (smem)
  PID User     Command                         Swap      USS      PSS      RSS
28465 root     /opt/kata/bin/qemu-system-x        0   310.8M   310.8M   310.8M

without balloon:

+ docker update --memory 1G kata-1
kata-1
+ sleep 5s
+ docker exec -ti kata-1 free -h
              total        used        free      shared  buff/cache   available
Mem:           5.9G         24M        5.8G        8.2M         18M        5.8G
Swap:            0B          0B          0B
# qemu memory consumption (smem)
  PID User     Command                         Swap      USS      PSS      RSS 
30038 root     /opt/kata/bin/qemu-system-x        0     4.6G     4.6G     4.6G 

@jcvenegas
Copy link
Member Author

So I am getting an strange behavior when hotplug memory just by adding -balloon virtio. When I hotplug memory the kernel total memory is not near what I expect. It is increased but not as I would like.

[jcvenega@jcvenega-nuc runtime]$ docker run -dti -m 256M --runtime kata-runtime --name kata-1 stress-ng
ec02de8650364902004e3a73047ea8219d077d8fe0b321f2c3c8440263fad725
[jcvenega@jcvenega-nuc runtime]$ docker exec -ti kata-1  free -h
              total        used        free      shared  buff/cache   available
Mem:           234M         20M        201M        1.7M         12M        204M
Swap:            0B          0B          0B
[jcvenega@jcvenega-nuc runtime]$ docker update --memory 4G --memory-swap 4G kata-1
kata-1
[jcvenega@jcvenega-nuc runtime]$ docker exec -ti kata-1  free -h
              total        used        free      shared  buff/cache   available
Mem:           746M         81M        652M        1.7M         12M        647M
Swap:            0B          0B          0B

@jcvenegas
Copy link
Member Author

update: I just tried in a VM with the kata kernel and same qemu binary and worked I'll debug in the kata guest OS.

@jcvenegas
Copy link
Member Author

found the issue, will send the fix

@jodh-intel
Copy link
Contributor

jodh-intel commented Sep 28, 2018

nice.

lgtm

Approved with PullApprove

@jcvenegas jcvenegas force-pushed the balloon-update-remove branch 5 times, most recently from 61a8e9c to d25cee5 Compare October 4, 2018 15:52
@jcvenegas
Copy link
Member Author

depends on kata-containers/govmm#55

@jcvenegas
Copy link
Member Author

@jcvenegas @sboeuf I think this is ready to a new review. I think this is almost the final version, just waiting to merge kata-containers/govmm#55 and I will create a PR to test this on tests repo.

@sboeuf
Copy link

sboeuf commented Oct 4, 2018

@jcvenegas Ok I'll take a look later today!

@jcvenegas
Copy link
Member Author

/test

1 similar comment
@jcvenegas
Copy link
Member Author

/test

@codecov
Copy link

codecov bot commented Oct 4, 2018

Codecov Report

Merging #793 into master will increase coverage by 1.70%.
The diff coverage is 65.78%.

@@            Coverage Diff             @@
##           master     #793      +/-   ##
==========================================
+ Coverage   51.67%   53.38%   +1.70%     
==========================================
  Files         107      110       +3     
  Lines       14615    18759    +4144     
==========================================
+ Hits         7552    10014    +2462     
- Misses       6152     7592    +1440     
- Partials      911     1153     +242     

addMemDevice := &memoryDevice{
sizeMB: 0,
}
data, err := c.sandbox.hypervisor.hotplugAddDevice(addMemDevice, memoryDev)
Copy link

Choose a reason for hiding this comment

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

Why are we trying to hotplug more memory here? We're in the case where oldMemMB == newMemMB, and as mentioned by the debug log the current memory will not be modified.

Copy link

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

Discussed offline with @jcvenegas. This needs some changes to prevent from introducing the balloon knowledge at the container.go level.

return 0, fmt.Errorf("Unable to hotplug %d MiB memory, the SB has %d MiB and the maximum amount is %d MiB",
memDev.sizeMB, currentMemory, q.config.MemorySize)
if memDev.sizeMB == 0 {
// handle case when not memory added (because not needed)
Copy link

Choose a reason for hiding this comment

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

// handle the case where no memory is added (because not needed)

Copy link

Choose a reason for hiding this comment

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

Well, actually I would remove the comment since there's nothing to do in this case.
Just print a log and return.

"hotplug": "memory",
},
).Debug("Not needed to hotplug, updating balloon")
return 0, q.updateMemoryBalloon(currentMemory)
Copy link

Choose a reason for hiding this comment

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

Why do we need to update the balloon, this case should be a simple no-op, right?

@jcvenegas
Copy link
Member Author

/test

@jcvenegas
Copy link
Member Author

/test

1 similar comment
@jcvenegas
Copy link
Member Author

/test

@jcvenegas
Copy link
Member Author

@sboeuf take a look, I think now is more explicit the the balloon usage. @linzichang @clarecch please take a look this PR is planning to move part of the logic on how we manage memory. The last to commits do that.

@cedriccchen
Copy link
Contributor

Hi @jcvenegas , most of this PR looks nice, but two doubts:

  1. Why should we move hotplug logic from container to sandbox? I think c.sandbox.XXX is the same as s.XXX.
  2. I am glad to see the thought of virtcontainers: hotplug memory with kata-runtime update command. #624 (comment) is almost realized, as @linzichang and me are too busy to handle the Support elastic memory hotplug #788 issue. Just a question, do we need vm_reserved_memory memtions in virtcontainers: hotplug memory with kata-runtime update command. #624 (comment) to keep the vm running normally when sandbox memory is all used by container? With vm_reserved_memory , we can still hotplug memory from hostos as long as hostos has enough free memory , and the guestos will not panic even if all sandbox memory is used by container.


// Memory is not updated if memory limit not set
if newResources.MemMB != 0 {
c.config.Resources.MemMB = newResources.MemMB
Copy link
Contributor

Choose a reason for hiding this comment

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

If just a part of memory is hotplugged successfully, the memory limit cgroup of container should not be set to newResources.MemMB, which is expected to be hotplugged.

Copy link
Member Author

@jcvenegas jcvenegas Oct 15, 2018

Choose a reason for hiding this comment

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

@clarecch I need to test this,
from my perspective we still need to update the cgroup

  • the container should update its cgroup
  • The sandbox manage the memory from the guest.

I expect that cgroup limit does not depends on the guest physical memory, so we can set the cgroup with more memory than the memory that is available in the VM.

An example that is valid is when:

  1. have a sandbox/pod/VM with all (almost ) the memory of the host added.
    create sandbox, create container -memory all the host memory
  2. Then we add another container to the Sandbox/pod/VM without any memory cgroup.
  3. After we update the cgroup of the new container to increase memory.
    a. The sandbox wont increase the memory but the container will share the memory with other containers and the cgroup will be limited.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explanation.

@raravena80
Copy link
Member

@jcvenegas ping, any updates?

@raravena80
Copy link
Member

@jcvenegas ping, any updates? Thx.

@grahamwhaley
Copy link
Contributor

Branch is now conflicted (again). @jcvenegas - can you give us an update on your plan with this at least - are you actively pursuing and still hoping to land?

@raravena80
Copy link
Member

@jcvenegas any updates? Thx!

@caoruidong
Copy link
Member

ping @jcvenegas

@raravena80
Copy link
Member

@jcvenegas ping.

@raravena80
Copy link
Member

ping @jcvenegas

@caoruidong
Copy link
Member

ping @jcvenegas Shall we close it?

@jcvenegas
Copy link
Member Author

/test

@jcvenegas jcvenegas force-pushed the balloon-update-remove branch 3 times, most recently from ab8ac47 to fc0f210 Compare September 13, 2019 16:07
Request to return memory back using balloon.

Fixes: kata-containers#790

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
Now that we are in qemu 4.x it is not need to
handle it in an special way for balloon.

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
@jcvenegas
Copy link
Member Author

/test

@jcvenegas
Copy link
Member Author

I'll try to get this PR merged this year, @bergwolf @egernst please take a look would be nice to have it merged for 1.9

@jcvenegas
Copy link
Member Author

@devimc @egernst @bergwolf ping place take a look

Copy link

@devimc devimc left a comment

Choose a reason for hiding this comment

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

thanks @jcvenegas

@@ -1128,6 +1134,9 @@ func (q *qemu) hotplugVFIODevice(device *config.VFIODev, op operation) (err erro
devID := device.ID

if op == addDevice {

// When HasVFIODevice is set balloon size is set to maximal memory
Copy link

Choose a reason for hiding this comment

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

and where is HasVFIODevice set ?

@raravena80
Copy link
Member

raravena80 commented Nov 15, 2019

@jcvenegas any update on this PR?

@jcvenegas
Copy link
Member Author

@raravena80 thanks for ping on this I was waiting for feedback from @egernst and @bergwolf if still we want to enable this, the PR is functional but this PR does not have a lot of priority today.

@raravena80
Copy link
Member

@jcvenegas any updates?

Your weekly Kata herder.

@jodh-intel
Copy link
Contributor

Hmm, this is a pain - the only failing CI is the nemu one. But we no longer support that so we could land this. But GitHub won't let us. Thoughts @jcvenegas?

@chavafg - btw, as nemu is dead, do we still need the nemu CI jobs?

@grahamwhaley
Copy link
Contributor

a re-submit as a new PR might be the easiest thing to do.
Good thought on the CI - if we have not done it already.

@chavafg
Copy link
Contributor

chavafg commented Jan 20, 2020

@jodh-intel we already removed the nemu CI for master branch.
We still have it running for stable branches (1.8.x)... Although not sure if we still support that branch. Maybe we can now remove it definitely.

The nemu register above was from an old execution, we can ignore it, or as @grahamwhaley comments, the PR can be re-pushed.

@jcvenegas
Copy link
Member Author

@jodh-intel its being a long time of this PR I think make sense to ask to @kata-containers/architecture-committee if we want it or should I close it.

@raravena80
Copy link
Member

@chavafg @jcvenegas any updates on this PR? Thx

@jcvenegas jcvenegas closed this May 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use memory ballooning when memory is reduced