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

Eliminate CGo usage from cgroup package #1238

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kakkoyun
Copy link
Member

@kakkoyun kakkoyun commented Jan 19, 2023

Signed-off-by: Kemal Akkoyun kakkoyun@gmail.com

We should remove as many CGo dependencies as possible. Switching from Go to C code at runtime always comes with increased costs in terms of CPU usage, so that is another reason to avoid mixed code.

TODO

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
@kakkoyun kakkoyun requested a review from a team as a code owner January 19, 2023 17:56
}
ret := *(*uint64)(unsafe.Pointer(&hf.Bytes()[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Writing down some notes, as I was confused at first. Reading the source code helped quite a bit 😄 .

Please feel free to correct this if I got some stuff wrong.

Before

We always allocated cgid_file_handle with uint64_t cgid (the handle data), which should always fit.

Now

.Bytes + .Type are allocated + 32 Bytes for the handle, which should be enough for us.

Then the Bytes() call that was throwing me off because thought that it was returning the whole raw buffer, including Bytes and Type, but they are skipped.

One more thing I wonder why they did .Bytes +4 rather than something like the below which I think would be easier for maintenance and clearer? I guess it's due to perf reasons, but not sure.

return unsafe.Slice((*byte(unsafe.Pointer(uintptr(unsafe.Pointer(&fh.fileHandle.Bytes))+unsafe.Sizeof(&fh))), n)

Copy link
Contributor

@javierhonduco javierhonduco left a comment

Choose a reason for hiding this comment

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

Great improvement!! 🎉

@kakkoyun kakkoyun marked this pull request as draft January 24, 2023 16:59
@kakkoyun
Copy link
Member Author

The ID extraction mechanism has issues (current and upcoming). I'm double-checking it.

@javierhonduco
Copy link
Contributor

The other day I forgot to suggest this, should we add this new implementation while keeping the old one and then run both and compare for mismatches?

That way we can ensure that the new implementation behaves exactly as the current one. What do you think?

@kakkoyun
Copy link
Member Author

The other day I forgot to suggest this, should we add this new implementation while keeping the old one and then run both and compare for mismatches?

That way we can ensure that the new implementation behaves exactly as the current one. What do you think?

For sure. FWIW, the previous implementation also gives an empty string.

On the other hand, I'm also questioning the need for this. It's not used anywhere. And we don't add it as a metadata label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants