Make BufferEncoder use 512 byte aligned buffers
Performance testing suggest that O_DIRECT is significantly faster than
using the more standard write calls. This requires much larger
alignment in the buffers used, and larger buffer sizes to be performant.
Modify BufferEncoder to use sector sized alignment.
Change-Id: Ie07b864b98b85caf631926565c97a56a469ca21d
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/logging/buffer_encoder.h b/aos/events/logging/buffer_encoder.h
index 34de00a..f4a6251 100644
--- a/aos/events/logging/buffer_encoder.h
+++ b/aos/events/logging/buffer_encoder.h
@@ -112,7 +112,21 @@
private:
size_t total_bytes_ = 0;
- ResizeableBuffer input_buffer_;
+ // A class which uses aligned_alloc to allocate sector aligned blocks of
+ // memory.
+ class AlignedReallocator {
+ public:
+ static void *Realloc(void *old, size_t old_size, size_t new_capacity) {
+ void *new_memory = std::aligned_alloc(512, new_capacity);
+ if (old) {
+ memcpy(new_memory, old, old_size);
+ free(old);
+ }
+ return new_memory;
+ }
+ };
+
+ AllocatorResizeableBuffer<AlignedReallocator> input_buffer_;
std::vector<absl::Span<const uint8_t>> return_queue_;
};