quiche: Implement QuicStreamBufferAllocator#6550
Conversation
Signed-off-by: Dan Zhang <danzh@google.com>
wu-bin
left a comment
There was a problem hiding this comment.
The PR description says backed by tcmalloc, but it actually just uses the standard malloc/free functions, which may or may not be tcmalloc underneath?
Overall LGTM except some nits.
bazel/repository_locations.bzl
Outdated
| # Static snapshot of https://quiche.googlesource.com/quiche/+archive/4fbea5de9afdf30611b27afd54c45a596944f9c2.tar.gz | ||
| sha256 = "2cf9f5ea62a03ca0d8773fe4f56949b72c28ac5b1bcf43d850a571f4e32add2a", | ||
| urls = ["https://storage.googleapis.com/quiche-envoy-integration/4fbea5de9afdf30611b27afd54c45a596944f9c2.tar.gz"], | ||
| # Static snapshot of https://quiche.googlesource.com/quiche/+archive/553a966443258b103c97326f94b53b03b933361d.tar.gz |
There was a problem hiding this comment.
Can you help me update it to a version at or after https://quiche.googlesource.com/quiche/+/a27fd44c5c53a67f3fa772b805363eff039411d5?
bazel/external/quiche.BUILD
Outdated
| ) | ||
|
|
||
| cc_library( | ||
| name = "quic_buffer_allocator_interface_lib", |
There was a problem hiding this comment.
How about "quic_buffer_allocator_lib", which is the name used internally?
There was a problem hiding this comment.
+1 -- most build targets in envoy end with "_lib" or "_interface", not both.
| // consumed or referenced directly by other Envoy code. It serves purely as a | ||
| // porting layer for QUICHE. | ||
|
|
||
| #include "quiche/quic/core/quic_buffer_allocator.h" |
There was a problem hiding this comment.
#include <stdlib.h> for malloc&free.
There was a problem hiding this comment.
or <cstdlib>, which is guaranteed idempotent.
jmarantz
left a comment
There was a problem hiding this comment.
looks great modulo nits.
| public: | ||
| ~QuicStreamBufferAllocatorImpl() override {} | ||
|
|
||
| char* New(size_t size) override { return static_cast<char*>(malloc(size)); } |
There was a problem hiding this comment.
above these put // QuickBufferAllocator per envoy convention.
| char* p = allocator.New(1024); | ||
| EXPECT_NE(nullptr, p); | ||
| memset(p, 'a', 1024); | ||
| allocator.Delete(p); |
There was a problem hiding this comment.
You could also in this test ensure that the total allocated bytes was the same before and after this delete, via Memory::Stats::totalCurrentlyAllocated() before and after. See test/common/stats/thread_local_store_test.cc , test HeapStatsThreadLocalStoreTest.MemoryWithoutTls for an example. Only do that test if TestUtil::hasDeterministicMallocStats() is true.
|
@wu-bin that's the way tcmalloc works: it overrides malloc and free as well as operator new and delete. It's worth noting that compiling with tcmalloc enabled is controlled by bazel flags, and I think it might not be enabled on some platform (Mac?) |
@jmarantz That's true, but other memory allocators also overrides malloc/free etc.
|
|
@wu-bin RE "other memory allocators" -- you're right of course :) The implementation here doesn't really depend on tcmalloc and doesn't claim it does, except in the PR description. It's just delegating to the system memory allocator, which seems fine to me. @danzh2010 maybe just change the description to reflect that? |
|
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
danzh2010
left a comment
There was a problem hiding this comment.
After the discussion about tcmalloc, it seems that the simplest way is to use quic's SimpleBufferAllocator as the impl. If tcmalloc turns out not to be sufficient, we can consider other buffer pool later.
bazel/external/quiche.BUILD
Outdated
| ) | ||
|
|
||
| cc_library( | ||
| name = "quic_buffer_allocator_interface_lib", |
bazel/repository_locations.bzl
Outdated
| # Static snapshot of https://quiche.googlesource.com/quiche/+archive/4fbea5de9afdf30611b27afd54c45a596944f9c2.tar.gz | ||
| sha256 = "2cf9f5ea62a03ca0d8773fe4f56949b72c28ac5b1bcf43d850a571f4e32add2a", | ||
| urls = ["https://storage.googleapis.com/quiche-envoy-integration/4fbea5de9afdf30611b27afd54c45a596944f9c2.tar.gz"], | ||
| # Static snapshot of https://quiche.googlesource.com/quiche/+archive/553a966443258b103c97326f94b53b03b933361d.tar.gz |
| // consumed or referenced directly by other Envoy code. It serves purely as a | ||
| // porting layer for QUICHE. | ||
|
|
||
| #include "quiche/quic/core/quic_buffer_allocator.h" |
| public: | ||
| ~QuicStreamBufferAllocatorImpl() override {} | ||
|
|
||
| char* New(size_t size) override { return static_cast<char*>(malloc(size)); } |
| char* p = allocator.New(1024); | ||
| EXPECT_NE(nullptr, p); | ||
| memset(p, 'a', 1024); | ||
| allocator.Delete(p); |
Signed-off-by: Dan Zhang <danzh@google.com>
| bool deterministic_stats = Envoy::Stats::TestUtil::hasDeterministicMallocStats(); | ||
| size_t start_mem; | ||
| if (deterministic_stats) { | ||
| start_mem = Envoy::Memory::Stats::totalCurrentlyAllocated(); |
There was a problem hiding this comment.
Might as well just assign start_mem conditionally.
| size_t start_mem; | ||
| if (deterministic_stats) { | ||
| start_mem = Envoy::Memory::Stats::totalCurrentlyAllocated(); | ||
| std::cerr << "start mem " << start_mem << "\n"; |
Signed-off-by: Dan Zhang <danzh@google.com>
|
/assign @mattklein123 |
| TEST_F(QuicPlatformTest, TestEnvoyQuicBufferAllocator) { | ||
| bool deterministic_stats = Envoy::Stats::TestUtil::hasDeterministicMallocStats(); | ||
| const size_t start_mem = | ||
| deterministic_stats ? Envoy::Memory::Stats::totalCurrentlyAllocated() : 0; |
There was a problem hiding this comment.
actually you don't need to conditionalize this; totalCurrentlyAllocated() will return 0 if deterministic_stats is false.
Signed-off-by: Dan Zhang <danzh@google.com>
Implement this API with default SimpleBufferAllocator which use bare new and delete. In light of flag-enabled tcmalloc support, the default implementation will use tcmalloc underneath.
Roll up quiche tar ball to ba6354aa1b39f3d9788ead909ad3e678ac863938
Risk Level: low, not in use
Testing: Added simple test in test/extensions/quic_listeners/quiche/platform:quic_platform_test
Part of #2557