-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
} | ||
ret := *(*uint64)(unsafe.Pointer(&hf.Bytes()[0])) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement!! 🎉
The ID extraction mechanism has issues (current and upcoming). I'm double-checking it. |
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. |
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