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

agent:image: Refactor code to improve memory efficiency of image service #9325

Merged
merged 1 commit into from Mar 26, 2024

Conversation

ChengyuZhu6
Copy link
Member

@ChengyuZhu6 ChengyuZhu6 commented Mar 21, 2024

Currently, .lock().await.clone() results in Option<ImageService> being duplicated in memory with each call to singleton(). Consequently, if kata-agent receives numerous image pulling requests simultaneously, it will lead to the allocation of multiple Option<ImageService> instances in memory, thereby consuming additional memory resources.

In image.rs, we introduce two public functions: merge_bundle_oci() and init_image_service(). These functions will encapsulate the operations on IMAGE_SERVICE, ensuring that its internal details remain hidden from external modules such as rpc.rs.

Fixes: #9225 -- part II

@ChengyuZhu6
Copy link
Member Author

cc @Xynnn007

@katacontainersbot katacontainersbot added the size/large Task of significant size label Mar 21, 2024
@ChengyuZhu6 ChengyuZhu6 force-pushed the image_service branch 2 times, most recently from a2d87ce to 8d6a22b Compare March 21, 2024 04:51
@ChengyuZhu6
Copy link
Member Author

/test

Copy link
Contributor

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

Thanks. lgtm

Copy link
Member

@stevenhorsman stevenhorsman left a comment

Choose a reason for hiding this comment

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

I'm not a rust expert, but my understanding of this PR is that rather than have the lock().await.clone() on the singleton method which as you say will result in memory duplication, you've effectively moving the clone and lock down only when it's needed in functions, which should reduce the resources. Assuming that I've not missed the point - this makes sense to me. Thanks!

@fidencio
Copy link
Member

/test

@ChengyuZhu6 ChengyuZhu6 force-pushed the image_service branch 7 times, most recently from 098cfa9 to dcad5ca Compare March 23, 2024 06:21
Currently, `.lock().await.clone()` results in `Option<ImageService>` being duplicated in memory with each call to `singleton()`.
Consequently, if kata-agent receives numerous image pulling requests simultaneously,
it will lead to the allocation of multiple `Option<ImageService>` instances in memory, thereby consuming additional memory resources.

In image.rs, we introduce two public functions:
`merge_bundle_oci()` and `init_image_service()`. These functions will encapsulate
the operations on `IMAGE_SERVICE`, ensuring that its internal details remain
hidden from external modules such as `rpc.rs`.

Fixes: kata-containers#9225 -- part II

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
@ChengyuZhu6 ChengyuZhu6 force-pushed the image_service branch 2 times, most recently from 87fca3f to f47408f Compare March 24, 2024 23:48
@stevenhorsman
Copy link
Member

/test

Copy link
Member

@arronwy arronwy left a comment

Choose a reason for hiding this comment

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

Thanks @ChengyuZhu6 LGTM!

@ChengyuZhu6 ChengyuZhu6 merged commit d16971e into kata-containers:main Mar 26, 2024
290 of 297 checks passed
@ChengyuZhu6 ChengyuZhu6 deleted the image_service branch March 26, 2024 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test size/large Task of significant size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize guest pull feature
6 participants