conn: reduce initial memory in Receive()#215
Open
florianl wants to merge 1 commit intomdlayher:mainfrom
Open
Conversation
florianl
added a commit
to florianl/go-diag
that referenced
this pull request
Jul 20, 2024
Until mdlayher/netlink#215 is merged use a replace statement to reduce the memory footprint. Signed-off-by: Florian Lehner <dev@der-flo.net>
This was referenced Jul 20, 2024
florianl
added a commit
to florianl/go-diag
that referenced
this pull request
Jun 7, 2025
Until mdlayher/netlink#215 is merged use a replace statement to reduce the memory footprint. Signed-off-by: Florian Lehner <dev@der-flo.net>
Reduce memory footprint by starting with a smaller buffer and adjust the buffer size accordingly after peeking at the upcoming netlink message. Signed-off-by: Florian Lehner <dev@der-flo.net>
nickgarlis
reviewed
Nov 5, 2025
| // Receive receives one or more Messages from netlink. | ||
| func (c *conn) Receive() ([]Message, error) { | ||
| b := make([]byte, os.Getpagesize()) | ||
| for { |
Contributor
There was a problem hiding this comment.
I wonder whether the reason for the loop here was to make sure we are not falling behind the kernel in an async scenario. Perhaps @mdlayher wanted to avoid setting the buffer to the exact number of available bytes.
Is it possible for more bytes come in before the next recvmsg call ? I think that shouldn't happen but have you confirmed that @florianl ?
If it's indeed safe then it'd be nice to have this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce memory footprint by starting with a smaller buffer and adjust the buffer size accordingly after peeking at the upcoming netlink message.