diff --git a/storage/innobase/buf/buf0mtflu.cc b/storage/innobase/buf/buf0mtflu.cc
index aae90e48168736621e70b35ae46030d35e383e72..ee52a11c394d354c338dca2e325e36f467a56260 100644
--- a/storage/innobase/buf/buf0mtflu.cc
+++ b/storage/innobase/buf/buf0mtflu.cc
@@ -367,14 +367,6 @@ DECLARE_THREAD(mtflush_io_thread)(void* arg)
 	mutex_exit(&(mtflush_io->thread_global_mtx));
 
 	while (TRUE) {
-
-#ifdef UNIV_MTFLUSH_DEBUG
- 		fprintf(stderr, "InnoDB: Note. Thread %lu work queue len %lu return queue len %lu\n",
- 					os_thread_get_curr_id(),
- 					ib_wqueue_len(mtflush_io->wq),
- 					ib_wqueue_len(mtflush_io->wr_cq));
-#endif /* UNIV_MTFLUSH_DEBUG */
-
 		mtflush_service_io(mtflush_io, this_thread_data);
 
 
diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc
index bbe53f4d16322ade2abc1efaa6613bccd6bab3ab..f9c7bcd75c412430501f3a772c88ca20ffe305fc 100644
--- a/storage/innobase/fts/fts0fts.cc
+++ b/storage/innobase/fts/fts0fts.cc
@@ -580,6 +580,7 @@ fts_cache_init(
 	cache->sync_heap->arg = mem_heap_create(1024);
 
 	cache->total_size = 0;
+	cache->total_size_at_sync = 0;
 
 	mutex_enter((ib_mutex_t*) &cache->deleted_lock);
 	cache->deleted_doc_ids = ib_vector_create(
@@ -3571,11 +3572,14 @@ fts_add_doc_by_id(
 					get_doc->index_cache,
 					doc_id, doc.tokens);
 
-				bool	need_sync = false;
-				if ((cache->total_size > fts_max_cache_size / 10
-				     || fts_need_sync)
-				    && !cache->sync->in_progress) {
-					need_sync = true;
+				bool	need_sync = !cache->sync->in_progress
+					&& (fts_need_sync
+					    || (cache->total_size
+						- cache->total_size_at_sync)
+					    > fts_max_cache_size / 10);
+				if (need_sync) {
+					cache->total_size_at_sync =
+						cache->total_size;
 				}
 
 				rw_lock_x_unlock(&table->fts->cache->lock);
diff --git a/storage/innobase/include/fts0types.h b/storage/innobase/include/fts0types.h
index 21d32c7d313e9cc859fa24b64eb713ab84768389..d49bc7c0254f7176b9f5e1c8992767810c7c0cd8 100644
--- a/storage/innobase/include/fts0types.h
+++ b/storage/innobase/include/fts0types.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -150,6 +150,9 @@ struct fts_cache_t {
 	size_t		total_size;	/*!< total size consumed by the ilist
 					field of all nodes. SYNC is run
 					whenever this gets too big */
+	/** total_size at the time of the previous SYNC request */
+	size_t		total_size_at_sync;
+
 	fts_sync_t*	sync;		/*!< sync structure to sync data to
 					disk */
 	ib_alloc_t*	sync_heap;	/*!< The heap allocator, for indexes
diff --git a/storage/innobase/include/ut0wqueue.h b/storage/innobase/include/ut0wqueue.h
index 5a895f4ea3c93aa04df81e3fb9870cc70973fa69..d9cc7aec9c9622c62cf7b7a4747c0ea84cb183ff 100644
--- a/storage/innobase/include/ut0wqueue.h
+++ b/storage/innobase/include/ut0wqueue.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2006, 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2019, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -46,6 +46,8 @@ struct ib_wqueue_t
 	ib_mutex_t	mutex;
 	/** Work item list */
 	ib_list_t*	items;
+	/** ib_list_len(*items) */
+	size_t		length;
 	/** event we use to signal additions to list;
 	os_event_set() and os_event_reset() are protected by the mutex */
 	os_event_t	event;
@@ -103,12 +105,5 @@ void*
 ib_wqueue_nowait(
 /*=============*/
 	ib_wqueue_t*	wq);		/*<! in: work queue */
-/********************************************************************
-Get number of items on queue.
-@return number of items on queue */
-ulint
-ib_wqueue_len(
-/*==========*/
-	ib_wqueue_t*	wq);		/*<! in: work queue */
 
 #endif /* IB_WORK_QUEUE_H */
diff --git a/storage/innobase/ut/ut0wqueue.cc b/storage/innobase/ut/ut0wqueue.cc
index ae97009430e038676bbf1698f0f2abf1e3f2f33e..45af449cff988e3e8bdf59e45b7b46abac56b81c 100644
--- a/storage/innobase/ut/ut0wqueue.cc
+++ b/storage/innobase/ut/ut0wqueue.cc
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2006, 2015, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2019, MariaDB Corporation.
+Copyright (c) 2019, 2021, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -45,6 +45,7 @@ ib_wqueue_create(void)
 
 	wq->items = ib_list_create();
 	wq->event = os_event_create(0);
+	wq->length = 0;
 
 	return(wq);
 }
@@ -76,6 +77,8 @@ ib_wqueue_add(ib_wqueue_t* wq, void* item, mem_heap_t* heap, bool wq_locked)
 	}
 
 	ib_list_add_last(wq->items, item, heap);
+	wq->length++;
+	ut_ad(wq->length == ib_list_len(wq->items));
 	os_event_set(wq->event);
 
 	if (!wq_locked) {
@@ -102,12 +105,12 @@ ib_wqueue_wait(
 
 		if (node) {
 			ib_list_remove(wq->items, node);
-
-			if (!ib_list_get_first(wq->items)) {
+			if (!--wq->length) {
 				/* We must reset the event when the list
 				gets emptied. */
 				os_event_reset(wq->event);
 			}
+			ut_ad(wq->length == ib_list_len(wq->items));
 
 			break;
 		}
@@ -142,7 +145,8 @@ ib_wqueue_timedwait(
 
 		if (node) {
 			ib_list_remove(wq->items, node);
-
+			wq->length--;
+			ut_ad(wq->length == ib_list_len(wq->items));
 			mutex_exit(&wq->mutex);
 			break;
 		}
@@ -204,20 +208,3 @@ bool ib_wqueue_is_empty(ib_wqueue_t* wq)
 	mutex_exit(&wq->mutex);
 	return is_empty;
 }
-
-/********************************************************************
-Get number of items on queue.
-@return number of items on queue */
-ulint
-ib_wqueue_len(
-/*==========*/
-	ib_wqueue_t*	wq)		/*<! in: work queue */
-{
-	ulint len = 0;
-
-	mutex_enter(&wq->mutex);
-	len = ib_list_len(wq->items);
-	mutex_exit(&wq->mutex);
-
-        return(len);
-}