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

shm: Create shared /dev/shm#357

Merged
egernst merged 1 commit intokata-containers:masterfrom
amshinde:handle-shared-shm
Jun 11, 2018
Merged

shm: Create shared /dev/shm#357
egernst merged 1 commit intokata-containers:masterfrom
amshinde:handle-shared-shm

Conversation

@amshinde
Copy link
Member

This commit checks the size of "/dev/shm" for the sandbox container
which is then used to create the shared memory inside the guest.
kata agent then uses this size to set up a sandbox level shm
storage. The containers then simply bind mount this sandbox level
shm.

With this, we will now be able to support docker --shm-size option
as well have a shared shm within containers in a pod, since they are
supposed to be in the same IPC namespace.

Fixed #356

Signed-off-by: Archana Shinde archana.m.shinde@intel.com

@amshinde amshinde force-pushed the handle-shared-shm branch 2 times, most recently from cda7583 to ed1746d Compare June 1, 2018 00:51
@amshinde
Copy link
Member Author

amshinde commented Jun 1, 2018

@bergwolf PTAL. Let me know what you think about the approach. I am planning to add a new Storage in the kata agent with driver "shm" that will create a tmpfs based storage.

grpcSpec.Mounts[idx].Type = "tmpfs"
grpcSpec.Mounts[idx].Source = "shm"
grpcSpec.Mounts[idx].Options = []string{"noexec", "nosuid", "nodev", "mode=1777", "size=65536k"}
grpcSpec.Mounts[idx].Options = []string{"noexec", "nosuid", "nodev", "mode=1777", sizeOption}

Choose a reason for hiding this comment

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

It might be worth adding a log call to show the requested size for debugging purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added log calls for the shm size.

continue
}

shmSize = vc.DefaultShmSize

Choose a reason for hiding this comment

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

Why is this set inside the loop? Can't you just initialize shmSize to this value as currently if there is no host mount this function will return 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jodh-intel I have added a break here. If no shm mount is found, then the shmSize will be zero, hence it is initialized to zero. In case host shm is to be used, this will be set to DefaultShmSize.

@bergwolf
Copy link
Member

bergwolf commented Jun 4, 2018

@amshinde Can you reuse kata-containers/agent/pull/236 and base your change on top of #307? shm is just a special case of tmpfs and tmpfs is handled as ephemeral storage in #307.

@WeiZhang555
Copy link
Member

@bergwolf Maybe we can create a new general storage type in kata-agent, for supporting the case that sharing a volume among containers in pod, but not share it with host?

@bergwolf
Copy link
Member

bergwolf commented Jun 4, 2018

@WeiZhang555 Sharing a volume within the guest is already supported, by letting different containers bind mount the same volume source at the sandbox level. Each container can mount the referenced volume to its own namespace.

@amshinde amshinde force-pushed the handle-shared-shm branch from ed1746d to e5e498e Compare June 4, 2018 19:40
@amshinde
Copy link
Member Author

amshinde commented Jun 4, 2018

@bergwolf I have changed this PR to use ehemeral storage now,, instead of introducing a new storage specific to just shm. PTAL.

@amshinde amshinde force-pushed the handle-shared-shm branch from e5e498e to 233f964 Compare June 5, 2018 00:26
shmStorage := &grpc.Storage{
Driver: kataEphemeralDevType,
MountPoint: path,
Source: "shm",
Copy link
Member Author

Choose a reason for hiding this comment

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

@bergwolf I just realised that the source in case of /dev/shm is set to shm and not tmpfs, various for ephemeral volumes it is tmpfs .

$ sudo docker run -it --runtime=runc  debian sh -c "mount | grep shm"
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)

This source field would need to be changed to tmpfs to use the ephemeral storage. I know shm is a special case of tmpfs, but I havent looked into the implications of doing this, do you think it is ok to use tmpfs instead of shm.

I would prefer to introduce a new storage type for shm to be consistent with runc behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

@amshinde for ephemeral storage, the source actually does not matter. You can set it as shm or tmpfs or whatever, and it will be shown as such inside the container. Do you mean that kata-agent would only accept tmpfs source for ephemeral storage? If so, we need to fix it in kata-agent side.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bergwolf Yes, you are right. I set this to shm and tested it.

@amshinde amshinde force-pushed the handle-shared-shm branch from 233f964 to 105dd1e Compare June 5, 2018 01:33
@amshinde amshinde changed the title wip: shm: Create shared /dev/shm shm: Create shared /dev/shm Jun 5, 2018
@bergwolf
Copy link
Member

bergwolf commented Jun 5, 2018

LTGM! Thanks @amshinde !

My only concern is that we are mounting all these volumes under kataGuestSharedDir that is actually the mount point of 9pfs. This might confuse the 9pfs, e.g., these internal volume mountpoints directories are also visible to host side via 9pfs.

@jodh-intel
Copy link

jodh-intel commented Jun 5, 2018

/cc @grahamwhaley for the 9p comment.

lgtm although the CI doesn't look very happy.

Approved with PullApprove

@katabuilder
Copy link

PSS Measurement:
Qemu: 159671 KB
Proxy: 4689 KB
Shim: 11070 KB

Memory inside container:
Total Memory: 2045972 KB
Free Memory: 1996756 KB

@amshinde amshinde force-pushed the handle-shared-shm branch from 6dd6c10 to 4e8ec27 Compare June 6, 2018 19:44
@katabuilder
Copy link

PSS Measurement:
Qemu: 161784 KB
Proxy: 4783 KB
Shim: 10822 KB

Memory inside container:
Total Memory: 2045972 KB
Free Memory: 1995756 KB

@amshinde amshinde force-pushed the handle-shared-shm branch from 4e8ec27 to ddd6bf8 Compare June 6, 2018 23:24
@katabuilder
Copy link

PSS Measurement:
Qemu: 161773 KB
Proxy: 6814 KB
Shim: 10823 KB

Memory inside container:
Total Memory: 2045972 KB
Free Memory: 1996384 KB

@amshinde amshinde force-pushed the handle-shared-shm branch from ddd6bf8 to 9d793f6 Compare June 7, 2018 00:02
@katabuilder
Copy link

PSS Measurement:
Qemu: 159750 KB
Proxy: 6744 KB
Shim: 8975 KB

Memory inside container:
Total Memory: 2045972 KB
Free Memory: 1997128 KB

@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #357 into master will increase coverage by <.01%.
The diff coverage is 67.39%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #357      +/-   ##
=========================================
+ Coverage   63.79%   63.8%   +<.01%     
=========================================
  Files          87      87              
  Lines        8765    8807      +42     
=========================================
+ Hits         5592    5619      +27     
- Misses       2574    2586      +12     
- Partials      599     602       +3
Impacted Files Coverage Δ
virtcontainers/mount.go 80.17% <ø> (ø) ⬆️
virtcontainers/sandbox.go 67.17% <100%> (+0.05%) ⬆️
virtcontainers/kata_agent.go 30.25% <51.85%> (+0.46%) ⬆️
virtcontainers/pkg/oci/utils.go 78.4% <88.88%> (+0.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd2bf15...4d470e5. Read the comment docs.

@amshinde
Copy link
Member Author

amshinde commented Jun 7, 2018

@jodh-intel I am no longer using kataGuestSharedDir , so the shm mount will be not be visible to the host side via 9pfs. CI has been fixed as well.

@jodh-intel
Copy link

Hi @amshinde - ok. codecov is complaining, but I think if you create a unit test for getShmSize() it'll be within thresholds.

@amshinde amshinde force-pushed the handle-shared-shm branch 2 times, most recently from ccc752e to abf82b4 Compare June 10, 2018 08:34
This commit checks the size of "/dev/shm" for the sandbox container
which is then used to create the shared memory inside the guest.
kata agent then uses this size to set up a sandbox level ephemeral
storage for shm. The containers then simply bind mount this sandbox level
shm.

With this, we will now be able to support docker --shm-size option
as well have a shared shm within containers in a pod, since they are
supposed to be in the same IPC namespace.

Fixes kata-containers#356

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
@amshinde amshinde force-pushed the handle-shared-shm branch from abf82b4 to 4d470e5 Compare June 10, 2018 08:55
@katabuilder
Copy link

PSS Measurement:
Qemu: 162138 KB
Proxy: 6723 KB
Shim: 10733 KB

Memory inside container:
Total Memory: 2045972 KB
Free Memory: 1998492 KB

@amshinde
Copy link
Member Author

@egernst @sboeuf Can you merge this one? Code coverage needed to be fixed which has been done now.

@egernst egernst merged commit ca9f7ab into kata-containers:master Jun 11, 2018
@amshinde amshinde deleted the handle-shared-shm branch July 11, 2019 22:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants