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

conn: reduce initial memory in Receive() #215

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

Conversation

florianl
Copy link
Contributor

@florianl florianl commented Jun 25, 2024

Reduce memory footprint by starting with a smaller buffer and adjust the buffer size accordingly after peeking at the upcoming netlink message.

// on current master
$ go test -memprofile mem.orig.out .
// on this PR
$ go test  -memprofile mem.new.out .
$ go tool pprof -base=mem.orig.out mem.new.out
(pprof) top
Showing nodes accounting for -1081.85MB, 41.71% of 2593.47MB total
Dropped 34 nodes (cum <= 12.97MB)
Showing top 10 nodes out of 25
      flat  flat%   sum%        cum   cum%
-1226.36MB 47.29% 47.29% -1074.85MB 41.44%  github.com/mdlayher/netlink.(*conn).Receive
   92.51MB  3.57% 43.72%   144.01MB  5.55%  github.com/mdlayher/socket.rwT[go.shape.struct { github.com/mdlayher/socket.n int; github.com/mdlayher/socket.oobn int; github.com/mdlayher/socket.recvflags int; github.com/mdlayher/socket.from golang.org/x/sys/unix.Sockaddr }]
   46.50MB  1.79% 41.93%    51.51MB  1.99%  golang.org/x/sys/unix.Recvmsg
     -19MB  0.73% 42.66%      -19MB  0.73%  github.com/mdlayher/socket.rwT[go.shape.int]
   10.50MB   0.4% 42.25%   154.51MB  5.96%  github.com/mdlayher/socket.(*Conn).Recvmsg
       8MB  0.31% 41.95%      -11MB  0.42%  github.com/mdlayher/socket.(*Conn).Sendmsg
    3.50MB  0.13% 41.81% -1071.35MB 41.31%  github.com/mdlayher/netlink.(*Conn).receive
    2.50MB 0.096% 41.71%    -7.50MB  0.29%  github.com/mdlayher/netlink.(*conn).Send
         0     0% 41.71%  -516.45MB 19.91%  github.com/mdlayher/netlink.(*Conn).Execute
         0     0% 41.71%  -553.40MB 21.34%  github.com/mdlayher/netlink.(*Conn).Receive

flag_trunc

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 <[email protected]>
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 <[email protected]>
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.

1 participant