From 59caa7a04577579a899efdebff3fdb1377737138 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 16 Jul 2020 20:46:14 -0700 Subject: logd: always compress SerializedLogChunk in FinishWriting() When calculating the space used for pruning, if a log chunk is compressed, that size is used otherwise the uncompressed size is used. This is intended to reach a steady state where 1/4 of the log buffer is the uncompressed log chunk that is being written to and the other 3/4 of the log buffer is compressed logs. If we wait until there are no readers referencing the log chunk before compressing it, we end up with 2 uncompressed logs (the one that was just filled, that readers are still referencing, and the new one that was allocated to fit the most recent log), which take up 1/2 of the log buffer's allotted size and will thus cause prune to delete more compressed logs than it should. Instead, we should always compress the log chunks in FinishWriting() such that the compressed size will always be used for log chunks other than the one that is not actively written to. Decompressed logs due to readers are ephemeral by their nature and thus don't add to the log buffer size for pruning. Test: observe that log buffers can be filled in the presence of a reader. Change-Id: Ie21ccff032e41c4a0e51710cc435c5ab316563cb --- logd/SerializedFlushToState.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'logd/SerializedFlushToState.cpp') diff --git a/logd/SerializedFlushToState.cpp b/logd/SerializedFlushToState.cpp index 2633348cf..b02ccc349 100644 --- a/logd/SerializedFlushToState.cpp +++ b/logd/SerializedFlushToState.cpp @@ -31,7 +31,7 @@ SerializedFlushToState::SerializedFlushToState(uint64_t start, LogMask log_mask) SerializedFlushToState::~SerializedFlushToState() { log_id_for_each(i) { if (log_positions_[i]) { - log_positions_[i]->buffer_it->DecReaderRefCount(true); + log_positions_[i]->buffer_it->DecReaderRefCount(); } } } @@ -78,7 +78,7 @@ void SerializedFlushToState::AddMinHeapEntry(log_id_t log_id) { logs_needed_from_next_position_[log_id] = true; } else { // Otherwise, if there is another buffer piece, move to that and do the same check. - buffer_it->DecReaderRefCount(true); + buffer_it->DecReaderRefCount(); ++buffer_it; buffer_it->IncReaderRefCount(); log_positions_[log_id]->read_offset = 0; @@ -134,7 +134,7 @@ void SerializedFlushToState::Prune(log_id_t log_id, } // // Decrease the ref count since we're deleting our reference. - buffer_it->DecReaderRefCount(false); + buffer_it->DecReaderRefCount(); // Delete in the reference. log_positions_[log_id].reset(); -- cgit v1.2.3