From 0071085c7e6b149997a60dec15b2ab52d1d98449 Mon Sep 17 00:00:00 2001 From: yuxianjiang Date: Mon, 24 May 2021 10:07:09 +0800 Subject: [PATCH] [bugfix] #issue65 fts query cause OOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit problem ==== FTS query will allocate lots of memory in small piece in mem_heap_alloc. Releasing these small pieces can't recycle these memory and return them to OS. solution ==== 1、Allocate memory in large pieces 2、Force calling malloc_trim to recyle memory --- storage/innobase/fts/fts0que.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index 13b2177..80eb09a 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -35,6 +35,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #include "dict0dict.h" #include "fts0ast.h" @@ -2501,7 +2502,7 @@ static MY_ATTRIBUTE((warn_unused_result)) dberr_t fts_query_phrase_search( { ib_vector_t *tokens; ib_vector_t *orig_tokens; - mem_heap_t *heap = mem_heap_create(sizeof(fts_string_t)); + mem_heap_t *heap = mem_heap_create(1 * 1024 * 1024); ib_alloc_t *heap_alloc; ulint num_token; @@ -2657,6 +2658,9 @@ static MY_ATTRIBUTE((warn_unused_result)) dberr_t fts_query_phrase_search( func_exit: mem_heap_free(heap); + int r = malloc_trim(0); + if (r < 0) + ib::info() << "fts malloc_trim failed." ; /* Don't need it anymore. */ query->matched = nullptr; -- 1.8.3.1