Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

podman run - avoid calls to JSONDeepCopy #11781

Merged
merged 4 commits into from
Sep 29, 2021

Conversation

vrothberg
Copy link
Member

A series of commits to avoid all calls to JSONDeepCopy when running a simple podman run --rm -d busybox true. After 5d6ea90 this drops another 100kB of memory usage.

Please refer to the individual commits for change descriptions.

Note, this needs a head nod from @mheon.

Access the container's spec field directly inside of libpod instead of
calling Spec() which in turn creates expensive JSON deep copies.

Accessing the field directly drops memory consumption of a simple
podman run --rm busybox true from ~700kB to ~600kB.

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <[email protected]>
To avoid creating an expensive deep copy, create an internal function to
access the exec session.

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <[email protected]>
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 29, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 29, 2021
@Luap99
Copy link
Member

Luap99 commented Sep 29, 2021

Is there reason why you closed the copier.Copy() instead of JSONDeepCopy() PR, this should still help for the case were we need a deep copy.

libpod/runtime.go Outdated Show resolved Hide resolved
@vrothberg
Copy link
Member Author

Is there reason why you closed the copier.Copy() instead of JSONDeepCopy() PR, this should still help for the case were we need a deep copy.

Based on your and @mheon's feedback, I decided to first optimize the code and then take another look, if needed, at optimizing JSONDeepCopy. @mheon pointed out https://github.com/kubernetes/gengo/tree/master/examples/deepcopy-gen which may be a nice alternative.

Add a new function to libpod to directly access the runtime
configuration without creating an expensive deep copy.  Further migrate
a number of callers to this new function.

This drops the number of calls to JSONDeepCopy from 4 to 1 in a simple
`podman run --rm -d busybox top`.

Future work: Please note that there are more callers of GetConfig() that
can me migrated to GetConfigNoCopy().

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <[email protected]>
Do not create an expensive deep copy for the provided spec.Spec
when creating a container.  No API should be expected to create
deep copies of arguments unless explicitly documented.

This removes the last call to JSONDeepCopy in a simple
`podman run --rm -d busybox true`.

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <[email protected]>
@vrothberg
Copy link
Member Author

quay.io looks flaky at the moment.

// GetConfig returns the configuration used by the runtime.
// Note that the returned value is not a copy and must hence
// only be used in a reading fashion.
func (r *Runtime) GetConfigNoCopy() (*config.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little uncomfortable about this one, since it does give a backdoor into the Libpod config. I am OK with merging but would prefer more warnings telling people to avoid whenever possible, and how this is fastpath only, etc.

Copy link
Member

Choose a reason for hiding this comment

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

(If we could get lint to throw errors whenever someone adds a use, requiring a manual whitelisting, that would be neat, but that sounds beyond the scope of this PR)

@vrothberg
Copy link
Member Author

Whoooo, green.

@containers/podman-maintainers PTAL

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

@umohnani8
Copy link
Member

LGTM

@rhatdan
Copy link
Member

rhatdan commented Sep 29, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2021
@openshift-merge-robot openshift-merge-robot merged commit 4b9cd92 into containers:main Sep 29, 2021
@vrothberg vrothberg deleted the spec branch September 30, 2021 08:03
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants