google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.63k stars 1.29k forks source link

Improve coalescingRead in netstack/netstack.go #1071

Closed hbhasker closed 3 years ago

hbhasker commented 4 years ago

Netstack/netstack.go uses coalescingRead() to read from the underlying TCP endpoint which in turn calls fetchReadView(). fetchReadView() internally calls Endpoint.Read() which locks/unlocks the endpoint mutex. Given that in case of TCP especially the coalescingRead() can be quite large and each packet when read via fdbased/endpoint.go is made up multiple views the number of locks/unlocks required add significant contention on the endpoint lock.

Acquiring the lock once at start of coalescingRead and unlocking at end should significantly reduce the contention on the endpoint mutex.

hbhasker commented 3 years ago

This bug is now redundant after the changes to use io.Reader and changes to Read API itself. Closing.