From 609a2d95f822b35ae80864f4483ba01835b7c9e6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 23 Sep 2019 11:48:16 +1000 Subject: [PATCH] AP_Logger: try harder to use close to user buffer size this stops us drastically reducing buffer size when low on memory --- libraries/AP_Logger/AP_Logger_File.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Logger/AP_Logger_File.cpp b/libraries/AP_Logger/AP_Logger_File.cpp index 5ae398c448..4cb436d957 100644 --- a/libraries/AP_Logger/AP_Logger_File.cpp +++ b/libraries/AP_Logger/AP_Logger_File.cpp @@ -83,10 +83,14 @@ void AP_Logger_File::Init() } bufsize *= 1024; + const uint32_t desired_bufsize = bufsize; + // If we can't allocate the full size, try to reduce it until we can allocate it while (!_writebuf.set_size(bufsize) && bufsize >= _writebuf_chunk) { - hal.console->printf("AP_Logger_File: Couldn't set buffer size to=%u\n", (unsigned)bufsize); - bufsize >>= 1; + bufsize *= 0.9; + } + if (bufsize >= _writebuf_chunk && bufsize != desired_bufsize) { + hal.console->printf("AP_Logger: reduced buffer %u/%u\n", (unsigned)bufsize, (unsigned)desired_bufsize); } if (!_writebuf.get_size()) {