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

Clean up a hostinfo to reduce memory usage #955

Merged
merged 3 commits into from
Nov 2, 2023
Merged

Conversation

nbrownus
Copy link
Collaborator

@nbrownus nbrownus commented Aug 15, 2023

This removes a lot of state from HostInfo to reduce our memory footprint for active tunnels.

Base automatically changed from getOrHandshake to master August 21, 2023 23:51
@nbrownus nbrownus marked this pull request as ready for review August 23, 2023 15:01
Copy link
Member

@wadey wadey left a comment

Choose a reason for hiding this comment

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

First read through, mostly concerns about the locking changes

@@ -350,22 +340,6 @@ func ixHandshakeStage2(f *Interface, addr *udp.Addr, via *ViaSender, hostinfo *H
}

ci := hostinfo.ConnectionState
if ci.ready {
Copy link
Member

Choose a reason for hiding this comment

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

if we remove this ci.ready check, I think we need a different double check after the hh.Lock() to see if a different thread already completed the handshake for this host? How do we protected about late handshake packets coming in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I expect in this version it would fail when trying to read a noise message. The next PR in the series would put these calls to ixHandshake* within the pending hostmap lock to avoid these races.

Comment on lines -143 to -144
hostinfo.Lock()
defer hostinfo.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

The race detector might get upset about this, even if its okay in theory. I guess we can see what happens.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like its fine, at least running make smoke-docker-race shows no race detector complaints during the smoke test.

handshake_manager.go Outdated Show resolved Hide resolved
Comment on lines +175 to +176
hh.Lock()
defer hh.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

I think everytime we do a lock like this, we need to double check afterwards if another thread beat us to finishing out this entry, right? (or add a comment about why no-one could have beat us to it).

Comment on lines -458 to -459
hostinfo.Lock()
defer hostinfo.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we need this anymore? Shouldn't be at least doublecheck that someone else didn't already handle a recv_error for this hostinfo on a different thread?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The lock didn't really do anything for us before. If we have two threads in this code path and 1 is temporarily blocked on the hostinfo lock, they will have the same outcome.

@wadey wadey added this to the v1.8.0 milestone Oct 27, 2023
wadey
wadey previously approved these changes Oct 27, 2023
@nbrownus nbrownus merged commit a44e1b8 into master Nov 2, 2023
6 checks passed
@nbrownus nbrownus deleted the smaller-hostinfo branch November 2, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants