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

DirectByteBuf implementations should not force free memory #893

Merged
merged 1 commit into from
Dec 11, 2019

Conversation

Scottmitch
Copy link
Member

Motivation:
ServiceTalk doesn't expose reference counting and relies upon GC for memory
reclamation. Buffer objects are resizable an in the event a buffer is resized
(e.g. a write operation needs to expand the buffer) this will result in
allocating new memory and Netty will attempt to deallocate the old memory.
Applications may be multi-threaded and it is possible another thread will still
have a reference to this old memory location due to visibility constraints. We
should prevent Netty from force-freeing this old memory and instead rely upon GC
to avoid undefined behavior.

Modifications:

  • ServiceTalk DirectByteBuf implementations to override freeDirect(ByteBuffer)
    and do nothing.

Result:
Less risk for resize operation resulting in referencing freed memory.

Motivation:
ServiceTalk doesn't expose reference counting and relies upon GC for memory
reclamation. Buffer objects are resizable an in the event a buffer is resized
(e.g. a write operation needs to expand the buffer) this will result in
allocating new memory and Netty will attempt to deallocate the old memory.
Applications may be multi-threaded and it is possible another thread will still
have a reference to this old memory location due to visibility constraints. We
should prevent Netty from force-freeing this old memory and instead rely upon GC
to avoid undefined behavior.

Modifications:
- ServiceTalk DirectByteBuf implementations to override freeDirect(ByteBuffer)
  and do nothing.

Result:
Less risk for resize operation resulting in referencing freed memory.
Copy link
Collaborator

@NiteshKant NiteshKant left a comment

Choose a reason for hiding this comment

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

Makes sense

@Scottmitch Scottmitch merged commit 0c4280d into apple:master Dec 11, 2019
@Scottmitch Scottmitch deleted the direct_buff_no_free branch December 11, 2019 16:42
@Scottmitch
Copy link
Member Author

this change is mostly reverted by #894 after discussion on netty/netty#9850

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.

None yet

2 participants