Call malloc_trim(0) on Linux

This commit is contained in:
Jacob Dufault 2017-08-17 11:02:47 -07:00
parent 2328141d98
commit 3f44307268
4 changed files with 16 additions and 1 deletions

View File

@ -2623,6 +2623,10 @@ void QueryDbMain(const std::string& bin_name, Config* config, MultiQueueWaiter*
config, &db, waiter, &queue, config, &db, waiter, &queue,
&project, &file_consumer_shared, &import_manager, &timestamp_manager, &working_files, &project, &file_consumer_shared, &import_manager, &timestamp_manager, &working_files,
&clang_complete, &include_complete, global_code_complete_cache.get(), non_global_code_complete_cache.get(), signature_cache.get()); &clang_complete, &include_complete, global_code_complete_cache.get(), non_global_code_complete_cache.get(), signature_cache.get());
// Cleanup and free any unused memory.
FreeUnusedMemory();
if (!did_work) { if (!did_work) {
waiter->Wait({ waiter->Wait({
IpcManager::instance()->threaded_queue_for_server_.get(), IpcManager::instance()->threaded_queue_for_server_.get(),

View File

@ -50,4 +50,7 @@ void CopyFileTo(const std::string& destination, const std::string& source);
bool IsSymLink(const std::string& path); bool IsSymLink(const std::string& path);
// Returns any clang arguments that are specific to the current platform. // Returns any clang arguments that are specific to the current platform.
std::vector<std::string> GetPlatformClangArguments(); std::vector<std::string> GetPlatformClangArguments();
// Free any unused memory and return it to the system.
void FreeUnusedMemory();

View File

@ -5,6 +5,7 @@
#include <loguru.hpp> #include <loguru.hpp>
#include <malloc.h>
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <pthread.h> #include <pthread.h>
@ -247,4 +248,8 @@ std::vector<std::string> GetPlatformClangArguments() {
} }
#undef CHECKED #undef CHECKED
void FreeUnusedMemory() {
malloc_trim(0);
}
#endif #endif

View File

@ -226,4 +226,7 @@ std::vector<std::string> GetPlatformClangArguments() {
"-fdelayed-template-parsing" "-fdelayed-template-parsing"
}; };
} }
void FreeUnusedMemory() {}
#endif #endif