From 20a960ef8f010f16159a2e0cdfa76099cbfd10f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= <marko.makela@mariadb.com>
Date: Tue, 5 Feb 2019 15:48:27 +0200
Subject: [PATCH] MDEV-17598: Remove rw_lock_list

There is a mutex leak in the code that produces the output for
the information_schema.innodb_mutexes view. If the macro OK()
returns, we would fail to release rw_lock_list_mutex.

This patch removes the whole table and also the output of
SHOW ENGINE INNODB MUTEX. Furthermore, we no longer report
os_wait_count for InnoDB rw-locks.

The gain is that we remove rw_lock_list and rw_lock_list_mutex.
But, we probably should export this information via some other
means, such as PERFORMANCE_SCHEMA.
---
 .../information_schema_all_engines.result     |   8 +-
 .../suite/innodb/r/innodb_mutexes.result      |  35 --
 .../r/innodb_skip_innodb_is_tables.result     |   5 -
 .../suite/innodb/t/innodb_mutexes-master.opt  |   1 -
 mysql-test/suite/innodb/t/innodb_mutexes.test |  66 ----
 .../innodb/t/innodb_skip_innodb_is_tables.opt |  61 +---
 .../t/innodb_skip_innodb_is_tables.test       |   3 -
 storage/innobase/handler/ha_innodb.cc         | 341 ------------------
 storage/innobase/handler/i_s.cc               | 220 -----------
 storage/innobase/handler/i_s.h                |   1 -
 storage/innobase/include/sync0rw.h            |  19 +-
 storage/innobase/include/sync0sync.h          |   1 -
 storage/innobase/sync/sync0arr.cc             |   2 +-
 storage/innobase/sync/sync0debug.cc           |  14 +-
 storage/innobase/sync/sync0rw.cc              | 119 +-----
 storage/innobase/sync/sync0sync.cc            |  16 -
 16 files changed, 29 insertions(+), 883 deletions(-)
 delete mode 100644 mysql-test/suite/innodb/r/innodb_mutexes.result
 delete mode 100644 mysql-test/suite/innodb/t/innodb_mutexes-master.opt
 delete mode 100644 mysql-test/suite/innodb/t/innodb_mutexes.test

diff --git a/mysql-test/main/information_schema_all_engines.result b/mysql-test/main/information_schema_all_engines.result
index 2916858b5a6..d276ec47caa 100644
--- a/mysql-test/main/information_schema_all_engines.result
+++ b/mysql-test/main/information_schema_all_engines.result
@@ -29,7 +29,6 @@ INNODB_CMP_RESET
 INNODB_LOCKS
 INNODB_LOCK_WAITS
 INNODB_METRICS
-INNODB_MUTEXES
 INNODB_SYS_COLUMNS
 INNODB_SYS_FIELDS
 INNODB_SYS_FOREIGN
@@ -109,7 +108,6 @@ INNODB_CMP_RESET	page_size
 INNODB_LOCKS	lock_id
 INNODB_LOCK_WAITS	requesting_trx_id
 INNODB_METRICS	NAME
-INNODB_MUTEXES	NAME
 INNODB_SYS_COLUMNS	TABLE_ID
 INNODB_SYS_FIELDS	INDEX_ID
 INNODB_SYS_FOREIGN	ID
@@ -189,7 +187,6 @@ INNODB_CMP_RESET	page_size
 INNODB_LOCKS	lock_id
 INNODB_LOCK_WAITS	requesting_trx_id
 INNODB_METRICS	NAME
-INNODB_MUTEXES	NAME
 INNODB_SYS_COLUMNS	TABLE_ID
 INNODB_SYS_FIELDS	INDEX_ID
 INNODB_SYS_FOREIGN	ID
@@ -274,7 +271,6 @@ INNODB_CMP_RESET	information_schema.INNODB_CMP_RESET	1
 INNODB_LOCKS	information_schema.INNODB_LOCKS	1
 INNODB_LOCK_WAITS	information_schema.INNODB_LOCK_WAITS	1
 INNODB_METRICS	information_schema.INNODB_METRICS	1
-INNODB_MUTEXES	information_schema.INNODB_MUTEXES	1
 INNODB_SYS_COLUMNS	information_schema.INNODB_SYS_COLUMNS	1
 INNODB_SYS_FIELDS	information_schema.INNODB_SYS_FIELDS	1
 INNODB_SYS_FOREIGN	information_schema.INNODB_SYS_FOREIGN	1
@@ -344,7 +340,6 @@ Database: information_schema
 | INNODB_LOCKS                          |
 | INNODB_LOCK_WAITS                     |
 | INNODB_METRICS                        |
-| INNODB_MUTEXES                        |
 | INNODB_SYS_COLUMNS                    |
 | INNODB_SYS_FIELDS                     |
 | INNODB_SYS_FOREIGN                    |
@@ -414,7 +409,6 @@ Database: INFORMATION_SCHEMA
 | INNODB_LOCKS                          |
 | INNODB_LOCK_WAITS                     |
 | INNODB_METRICS                        |
-| INNODB_MUTEXES                        |
 | INNODB_SYS_COLUMNS                    |
 | INNODB_SYS_FIELDS                     |
 | INNODB_SYS_FOREIGN                    |
@@ -459,5 +453,5 @@ Wildcard: inf_rmation_schema
 | information_schema |
 SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') GROUP BY TABLE_SCHEMA;
 table_schema	count(*)
-information_schema	65
+information_schema	64
 mysql	31
diff --git a/mysql-test/suite/innodb/r/innodb_mutexes.result b/mysql-test/suite/innodb/r/innodb_mutexes.result
deleted file mode 100644
index ff7bfa6f32a..00000000000
--- a/mysql-test/suite/innodb/r/innodb_mutexes.result
+++ /dev/null
@@ -1,35 +0,0 @@
-connect con1,localhost,root,,;
-connect con2,localhost,root,,;
-connect con3,localhost,root,,;
-create table t1(a int not null primary key, b int, c int,d CHAR(100)) engine=innodb;
-create procedure innodb_insert_proc (repeat_count int)
-begin
-declare current_num int;
-set current_num = 0;
-while current_num < repeat_count do
-insert into t1 values(current_num, RAND(), RAND(), substring(MD5(RAND()), -64));
-set current_num = current_num + 1;
-end while;
-end//
-commit;
-set autocommit=0;
-call innodb_insert_proc(20000);
-commit;
-set autocommit=1;
-connection con1;
-delete from t1 where a between 1000 and 1300;
-connection con2;
-update t1 set b=b+1 where a between 2000 and 2600;
-connection con3;
-insert into t1 select a+30000,b,c,d from t1 where a between 3000 and 4000;
-connection default;
-delete from t1 where a between 6000 and 7000;
-connection con1;
-connection con2;
-connection con3;
-connection default;
-disconnect con1;
-disconnect con2;
-disconnect con3;
-drop procedure innodb_insert_proc;
-drop table t1;
diff --git a/mysql-test/suite/innodb/r/innodb_skip_innodb_is_tables.result b/mysql-test/suite/innodb/r/innodb_skip_innodb_is_tables.result
index a90cd22f57a..d2ba20dc92a 100644
--- a/mysql-test/suite/innodb/r/innodb_skip_innodb_is_tables.result
+++ b/mysql-test/suite/innodb/r/innodb_skip_innodb_is_tables.result
@@ -379,7 +379,6 @@ select * from information_schema.innodb_sys_datafiles;
 SPACE	PATH
 Warnings:
 Warning	1012	InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_sys_datafiles but the InnoDB storage engine is not installed
-select * from information_schema.innodb_changed_pages;
 select * from information_schema.innodb_tablespaces_encryption;
 SPACE	NAME	ENCRYPTION_SCHEME	KEYSERVER_REQUESTS	MIN_KEY_VERSION	CURRENT_KEY_VERSION	KEY_ROTATION_PAGE_NUMBER	KEY_ROTATION_MAX_PAGE_NUMBER	CURRENT_KEY_ID	ROTATING_OR_FLUSHING
 Warnings:
@@ -388,10 +387,6 @@ select * from information_schema.innodb_tablespaces_scrubbing;
 SPACE	NAME	COMPRESSED	LAST_SCRUB_COMPLETED	CURRENT_SCRUB_STARTED	CURRENT_SCRUB_ACTIVE_THREADS	CURRENT_SCRUB_PAGE_NUMBER	CURRENT_SCRUB_MAX_PAGE_NUMBER	ROTATING_OR_FLUSHING
 Warnings:
 Warning	1012	InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_tablespaces_scrubbing but the InnoDB storage engine is not installed
-select * from information_schema.innodb_mutexes;
-NAME	CREATE_FILE	CREATE_LINE	OS_WAITS
-Warnings:
-Warning	1012	InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_mutexes but the InnoDB storage engine is not installed
 select * from information_schema.innodb_sys_semaphore_waits;
 THREAD_ID	OBJECT_NAME	FILE	LINE	WAIT_TIME	WAIT_OBJECT	WAIT_TYPE	HOLDER_THREAD_ID	HOLDER_FILE	HOLDER_LINE	CREATED_FILE	CREATED_LINE	WRITER_THREAD	RESERVATION_MODE	READERS	WAITERS_FLAG	LOCK_WORD	LAST_WRITER_FILE	LAST_WRITER_LINE	OS_WAIT_COUNT
 Warnings:
diff --git a/mysql-test/suite/innodb/t/innodb_mutexes-master.opt b/mysql-test/suite/innodb/t/innodb_mutexes-master.opt
deleted file mode 100644
index 493faf1903e..00000000000
--- a/mysql-test/suite/innodb/t/innodb_mutexes-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---innodb-mutexes
\ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_mutexes.test b/mysql-test/suite/innodb/t/innodb_mutexes.test
deleted file mode 100644
index 3b6b949c25d..00000000000
--- a/mysql-test/suite/innodb/t/innodb_mutexes.test
+++ /dev/null
@@ -1,66 +0,0 @@
---source include/have_innodb.inc
-
-connect(con1,localhost,root,,);
-connect(con2,localhost,root,,);
-connect(con3,localhost,root,,);
-
-create table t1(a int not null primary key, b int, c int,d CHAR(100)) engine=innodb;
-
-delimiter //;
-create procedure innodb_insert_proc (repeat_count int)
-begin
-  declare current_num int;
-  set current_num = 0;
-  while current_num < repeat_count do
-    insert into t1 values(current_num, RAND(), RAND(), substring(MD5(RAND()), -64));
-    set current_num = current_num + 1;
-  end while;
-end//
-delimiter ;//
-commit;
-
-set autocommit=0;
-call innodb_insert_proc(20000);
-commit;
-set autocommit=1;
-
-connection con1;
-send delete from t1 where a between 1000 and 1300;
-
-connection con2;
-send update t1 set b=b+1 where a between 2000 and 2600;
-
-connection con3;
-send insert into t1 select a+30000,b,c,d from t1 where a between 3000 and 4000;
-
-connection default;
-send delete from t1 where a between 6000 and 7000;
-
-connection con1;
-reap;
-
-connection con2;
-reap;
-
-connection con3;
-reap;
-
-connection default;
-reap;
-
-disconnect con1;
-disconnect con2;
-disconnect con3;
-
-# test that below does not crash, actual result is not
-# repeatable
---disable_query_log
---disable_result_log
---disable_warnings
-select * from information_schema.innodb_mutexes;
---enable_query_log
---enable_result_log
---enable_warnings
-
-drop procedure innodb_insert_proc;
-drop table t1;
\ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt
index c8a96d2fe93..d7e60820ee3 100644
--- a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt
+++ b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt
@@ -1,67 +1,32 @@
---loose-skip-innodb 
---loose-innodb_trx
---loose-innodb_locks
---loose-innodb_lock_waits
---loose-innodb_cmp
---loose-innodb_cmp_reset
---loose-innodb_cmp_per_index
---loose-innodb_cmp_per_index_reset
---loose-innodb_cmpmem
---loose-innodb_cmpmem_reset
---loose-innodb_metrics
---loose-innodb_ft_default_stopword
---loose-innodb_ft_deleted
---loose-innodb_ft_being_deleted
---loose-innodb_ft_index_cache
---loose-innodb_ft_index_table
---loose-innodb_ft_config
+--loose-skip-innodb
 --loose-innodb_buffer_page
 --loose-innodb_buffer_page_lru
 --loose-innodb_buffer_stats
---loose-innodb_sys_tables
---loose-innodb_sys_tablestats
---loose-innodb_sys_indexes
---loose-innodb_sys_columns
---loose-innodb_sys_fields
---loose-innodb_sys_foreign
---loose-innodb_sys_foreign_cols
---loose-innodb_sys_tablespaces
---loose-innodb_sys_datafiles
---loose-innodb_changed_pages
---loose-innodb_tablespaces_encryption
---loose-innodb_trx
---loose-innodb_locks
---loose-innodb_lock_waits
 --loose-innodb_cmp
---loose-innodb_cmp_reset
 --loose-innodb_cmp_per_index
 --loose-innodb_cmp_per_index_reset
+--loose-innodb_cmp_reset
 --loose-innodb_cmpmem
 --loose-innodb_cmpmem_reset
---loose-innodb_metrics
+--loose-innodb_ft_being_deleted
+--loose-innodb_ft_config
 --loose-innodb_ft_default_stopword
 --loose-innodb_ft_deleted
---loose-innodb_ft_being_deleted
 --loose-innodb_ft_index_cache
 --loose-innodb_ft_index_table
---loose-innodb_ft_config
---loose-innodb_buffer_page
---loose-innodb_buffer_page_lru
---loose-innodb_buffer_stats
---loose-innodb_sys_tables
---loose-innodb_sys_tablestats
---loose-innodb_sys_indexes
+--loose-innodb_lock_waits
+--loose-innodb_locks
+--loose-innodb_metrics
 --loose-innodb_sys_columns
+--loose-innodb_sys_datafiles
 --loose-innodb_sys_fields
 --loose-innodb_sys_foreign
 --loose-innodb_sys_foreign_cols
+--loose-innodb_sys_indexes
+--loose-innodb_sys_semaphore_waits
+--loose-innodb_sys_tables
 --loose-innodb_sys_tablespaces
---loose-innodb_sys_datafiles
---loose-innodb_changed_pages
+--loose-innodb_sys_tablestats
 --loose-innodb_tablespaces_encryption
 --loose-innodb_tablespaces_scrubbing
---loose-innodb_mutexes
---loose-innodb_sys_semaphore_waits
---loose-innodb_tablespaces_scrubbing
---loose-innodb_mutexes
---loose-innodb_sys_semaphore_waits
+--loose-innodb_trx
diff --git a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test
index 01ced047302..2b5b7ddf690 100644
--- a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test
+++ b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test
@@ -29,9 +29,6 @@ select * from information_schema.innodb_sys_foreign;
 select * from information_schema.innodb_sys_foreign_cols;
 select * from information_schema.innodb_sys_tablespaces;
 select * from information_schema.innodb_sys_datafiles;
---error 0,1109
-select * from information_schema.innodb_changed_pages;
 select * from information_schema.innodb_tablespaces_encryption;
 select * from information_schema.innodb_tablespaces_scrubbing;
-select * from information_schema.innodb_mutexes;
 select * from information_schema.innodb_sys_semaphore_waits;
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 153390dbc2d..779bf43bf37 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -602,7 +602,6 @@ static PSI_mutex_info all_innodb_mutexes[] = {
 #  ifdef UNIV_DEBUG
 	PSI_KEY(rw_lock_debug_mutex),
 #  endif /* UNIV_DEBUG */
-	PSI_KEY(rw_lock_list_mutex),
 	PSI_KEY(rw_lock_mutex),
 	PSI_KEY(srv_innodb_monitor_mutex),
 	PSI_KEY(srv_misc_tmpfile_mutex),
@@ -15792,343 +15791,6 @@ innodb_show_status(
 	DBUG_RETURN(ret_val);
 }
 
-/** Callback for collecting mutex statistics */
-struct ShowStatus {
-
-	/** For tracking the mutex metrics */
-	struct Value {
-
-		/** Constructor
-		@param[in]	name		Name of the mutex
-		@param[in]	spins		Number of spins
-		@param[in]	os_waits	OS waits so far
-		@param[in]	calls		Number of calls to enter() */
-		Value(const char*	name,
-		      ulint		spins,
-		      uint64_t		waits,
-		      uint64_t		calls)
-			:
-			m_name(name),
-			m_spins(spins),
-			m_waits(waits),
-			m_calls(calls)
-		{
-			/* No op */
-		}
-
-		/** Mutex name */
-		std::string		m_name;
-
-		/** Spins so far */
-		ulint			m_spins;
-
-		/** Waits so far */
-		uint64_t		m_waits;
-
-		/** Number of calls so far */
-		uint64_t		m_calls;
-	};
-
-	/** Order by m_waits, in descending order. */
-	struct OrderByWaits: public std::binary_function<Value, Value, bool>
-	{
-		/** @return true if rhs < lhs */
-		bool operator()(
-			const Value& lhs,
-			const Value& rhs) const
-			UNIV_NOTHROW
-		{
-			return(rhs.m_waits < lhs.m_waits);
-		}
-	};
-
-	typedef std::vector<Value, ut_allocator<Value> > Values;
-
-	/** Collect the individual latch counts */
-	struct GetCount {
-		typedef latch_meta_t::CounterType::Count Count;
-
-		/** Constructor
-		@param[in]	name		Latch name
-		@param[in,out]	values		Put the values here */
-		GetCount(
-			const char*	name,
-			Values*		values)
-			UNIV_NOTHROW
-			:
-			m_name(name),
-			m_values(values)
-		{
-			/* No op */
-		}
-
-		/** Collect the latch metrics. Ignore entries where the
-		spins and waits are zero.
-		@param[in]	count		The latch metrics */
-		void operator()(Count* count)
-			UNIV_NOTHROW
-		{
-			if (count->m_spins > 0 || count->m_waits > 0) {
-
-				m_values->push_back(Value(
-					m_name,
-					count->m_spins,
-					count->m_waits,
-					count->m_calls));
-			}
-		}
-
-		/** The latch name */
-		const char*	m_name;
-
-		/** For collecting the active mutex stats. */
-		Values*		m_values;
-	};
-
-	/** Constructor */
-	ShowStatus() { }
-
-	/** Callback for collecting the stats
-	@param[in]	latch_meta		Latch meta data
-	@return always returns true */
-	bool operator()(latch_meta_t& latch_meta)
-		UNIV_NOTHROW
-	{
-		latch_meta_t::CounterType*	counter;
-
-		counter = latch_meta.get_counter();
-
-		GetCount	get_count(latch_meta.get_name(), &m_values);
-
-		counter->iterate(get_count);
-
-		return(true);
-	}
-
-	/** Implements the SHOW MUTEX STATUS command, for mutexes.
-	The table structure is like so: Engine | Mutex Name | Status
-	We store the metrics  in the "Status" column as:
-
-		spins=N,waits=N,calls=N"
-
-	The user has to parse the dataunfortunately
-	@param[in,out]	thd		the MySQL query thread of the caller
-	@param[in,out]	stat_print	function for printing statistics
-	@return true on success. */
-	bool to_string(
-		THD*		thd,
-		stat_print_fn*	stat_print)
-		UNIV_NOTHROW;
-
-	/** For collecting the active mutex stats. */
-	Values		m_values;
-};
-
-/** Implements the SHOW MUTEX STATUS command, for mutexes.
-The table structure is like so: Engine | Mutex Name | Status
-We store the metrics  in the "Status" column as:
-
-	spins=N,waits=N,calls=N"
-
-The user has to parse the dataunfortunately
-@param[in,out]	thd		the MySQL query thread of the caller
-@param[in,out]	stat_print	function for printing statistics
-@return true on success. */
-bool
-ShowStatus::to_string(
-	THD*		thd,
-	stat_print_fn*	stat_print)
-	UNIV_NOTHROW
-{
-	uint		hton_name_len = (uint) strlen(innobase_hton_name);
-
-	std::sort(m_values.begin(), m_values.end(), OrderByWaits());
-
-	Values::iterator	end = m_values.end();
-
-	for (Values::iterator it = m_values.begin(); it != end; ++it) {
-
-		int	name_len;
-		char	name_buf[IO_SIZE];
-
-		name_len = snprintf(
-			name_buf, sizeof(name_buf), "%s", it->m_name.c_str());
-
-		int	status_len;
-		char	status_buf[IO_SIZE];
-
-		status_len = snprintf(
-			status_buf, sizeof(status_buf),
-			"spins=%lu,waits=%lu,calls=%llu",
-			static_cast<ulong>(it->m_spins),
-			static_cast<long>(it->m_waits),
-			(ulonglong) it->m_calls);
-
-		if (stat_print(thd, innobase_hton_name,
-			       hton_name_len,
-			       name_buf, static_cast<uint>(name_len),
-			       status_buf, static_cast<uint>(status_len))) {
-
-			return(false);
-		}
-	}
-
-	return(true);
-}
-
-/** Implements the SHOW MUTEX STATUS command, for mutexes.
-@param[in,out]	hton		the innodb handlerton
-@param[in,out]	thd		the MySQL query thread of the caller
-@param[in,out]	stat_print	function for printing statistics
-@return 0 on success. */
-static
-int
-innodb_show_mutex_status(
-	handlerton*
-#ifdef DBUG_ASSERT_EXISTS
-	hton
-#endif
-	,
-	THD*		thd,
-	stat_print_fn*	stat_print)
-{
-	DBUG_ENTER("innodb_show_mutex_status");
-
-	ShowStatus	collector;
-
-	DBUG_ASSERT(hton == innodb_hton_ptr);
-
-	mutex_monitor.iterate(collector);
-
-	if (!collector.to_string(thd, stat_print)) {
-		DBUG_RETURN(1);
-	}
-
-	DBUG_RETURN(0);
-}
-
-/** Implements the SHOW MUTEX STATUS command.
-@param[in,out]	hton		the innodb handlerton
-@param[in,out]	thd		the MySQL query thread of the caller
-@param[in,out]	stat_print	function for printing statistics
-@return 0 on success. */
-static
-int
-innodb_show_rwlock_status(
-	handlerton*
-#ifdef DBUG_ASSERT_EXISTS
-	hton
-#endif
-	,
-	THD*		thd,
-	stat_print_fn*	stat_print)
-{
-	DBUG_ENTER("innodb_show_rwlock_status");
-
-	rw_lock_t*	block_rwlock = NULL;
-	ulint		block_rwlock_oswait_count = 0;
-	uint		hton_name_len = (uint) strlen(innobase_hton_name);
-
-	DBUG_ASSERT(hton == innodb_hton_ptr);
-
-	mutex_enter(&rw_lock_list_mutex);
-
-	for (rw_lock_t* rw_lock = UT_LIST_GET_FIRST(rw_lock_list);
-	     rw_lock != NULL;
-	     rw_lock = UT_LIST_GET_NEXT(list, rw_lock)) {
-
-		if (rw_lock->count_os_wait == 0) {
-			continue;
-		}
-
-		int		buf1len;
-		char		buf1[IO_SIZE];
-
-		if (rw_lock->is_block_lock) {
-
-			block_rwlock = rw_lock;
-			block_rwlock_oswait_count += rw_lock->count_os_wait;
-
-			continue;
-		}
-
-		buf1len = snprintf(
-			buf1, sizeof buf1, "rwlock: %s:%u",
-			innobase_basename(rw_lock->cfile_name),
-			rw_lock->cline);
-
-		int		buf2len;
-		char		buf2[IO_SIZE];
-
-		buf2len = snprintf(
-			buf2, sizeof buf2, "waits=%u",
-			rw_lock->count_os_wait);
-
-		if (stat_print(thd, innobase_hton_name,
-			       hton_name_len,
-			       buf1, static_cast<uint>(buf1len),
-			       buf2, static_cast<uint>(buf2len))) {
-
-			mutex_exit(&rw_lock_list_mutex);
-
-			DBUG_RETURN(1);
-		}
-	}
-
-	if (block_rwlock != NULL) {
-
-		int		buf1len;
-		char		buf1[IO_SIZE];
-
-		buf1len = snprintf(
-			buf1, sizeof buf1, "sum rwlock: %s:%u",
-			innobase_basename(block_rwlock->cfile_name),
-			block_rwlock->cline);
-
-		int		buf2len;
-		char		buf2[IO_SIZE];
-
-		buf2len = snprintf(
-			buf2, sizeof buf2, "waits=" ULINTPF,
-			block_rwlock_oswait_count);
-
-		if (stat_print(thd, innobase_hton_name,
-			       hton_name_len,
-			       buf1, static_cast<uint>(buf1len),
-			       buf2, static_cast<uint>(buf2len))) {
-
-			mutex_exit(&rw_lock_list_mutex);
-
-			DBUG_RETURN(1);
-		}
-	}
-
-	mutex_exit(&rw_lock_list_mutex);
-
-	DBUG_RETURN(0);
-}
-
-/** Implements the SHOW MUTEX STATUS command.
-@param[in,out]	hton		the innodb handlerton
-@param[in,out]	thd		the MySQL query thread of the caller
-@param[in,out]	stat_print	function for printing statistics
-@return 0 on success. */
-static
-int
-innodb_show_latch_status(
-	handlerton*	hton,
-	THD*		thd,
-	stat_print_fn*	stat_print)
-{
-	int	ret = innodb_show_mutex_status(hton, thd, stat_print);
-
-	if (ret != 0) {
-		return(ret);
-	}
-
-	return(innodb_show_rwlock_status(hton, thd, stat_print));
-}
-
 /************************************************************************//**
 Return 0 on success and non-zero on failure. Note: the bool return type
 seems to be abused here, should be an int. */
@@ -16150,8 +15812,6 @@ innobase_show_status(
 		return(innodb_show_status(hton, thd, stat_print) != 0);
 
 	case HA_ENGINE_MUTEX:
-		return(innodb_show_latch_status(hton, thd, stat_print) != 0);
-
 	case HA_ENGINE_LOGS:
 		/* Not handled */
 		break;
@@ -20139,7 +19799,6 @@ i_s_innodb_sys_foreign_cols,
 i_s_innodb_sys_tablespaces,
 i_s_innodb_sys_datafiles,
 i_s_innodb_sys_virtual,
-i_s_innodb_mutexes,
 i_s_innodb_sys_semaphore_waits,
 i_s_innodb_tablespaces_encryption,
 i_s_innodb_tablespaces_scrubbing
diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc
index cedb6e05782..0ccf007e2aa 100644
--- a/storage/innobase/handler/i_s.cc
+++ b/storage/innobase/handler/i_s.cc
@@ -8948,226 +8948,6 @@ UNIV_INTERN struct st_maria_plugin	i_s_innodb_tablespaces_scrubbing =
 	STRUCT_FLD(maturity, MariaDB_PLUGIN_MATURITY_STABLE)
 };
 
-/**  INNODB_MUTEXES  *********************************************/
-/* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_MUTEXES */
-static ST_FIELD_INFO	innodb_mutexes_fields_info[] =
-{
-#define MUTEXES_NAME			0
-	{STRUCT_FLD(field_name,		"NAME"),
-	 STRUCT_FLD(field_length,	OS_FILE_MAX_PATH),
-	 STRUCT_FLD(field_type,		MYSQL_TYPE_STRING),
-	 STRUCT_FLD(value,		0),
-	 STRUCT_FLD(field_flags,	0),
-	 STRUCT_FLD(old_name,		""),
-	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
-#define MUTEXES_CREATE_FILE		1
-	{STRUCT_FLD(field_name,		"CREATE_FILE"),
-	 STRUCT_FLD(field_length,	OS_FILE_MAX_PATH),
-	 STRUCT_FLD(field_type,		MYSQL_TYPE_STRING),
-	 STRUCT_FLD(value,		0),
-	 STRUCT_FLD(field_flags,	0),
-	 STRUCT_FLD(old_name,		""),
-	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
-#define MUTEXES_CREATE_LINE		2
-	{STRUCT_FLD(field_name,		"CREATE_LINE"),
-	 STRUCT_FLD(field_length,	MY_INT32_NUM_DECIMAL_DIGITS),
-	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONG),
-	 STRUCT_FLD(value,		0),
-	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
-	 STRUCT_FLD(old_name,		""),
-	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
-#define MUTEXES_OS_WAITS		3
-	{STRUCT_FLD(field_name,		"OS_WAITS"),
-	 STRUCT_FLD(field_length,	MY_INT64_NUM_DECIMAL_DIGITS),
-	 STRUCT_FLD(field_type,		MYSQL_TYPE_LONGLONG),
-	 STRUCT_FLD(value,		0),
-	 STRUCT_FLD(field_flags,	MY_I_S_UNSIGNED),
-	 STRUCT_FLD(old_name,		""),
-	 STRUCT_FLD(open_method,	SKIP_OPEN_TABLE)},
-
-	END_OF_ST_FIELD_INFO
-};
-
-/*******************************************************************//**
-Function to populate INFORMATION_SCHEMA.INNODB_MUTEXES table.
-Loop through each record in mutex and rw_lock lists, and extract the column
-information and fill the INFORMATION_SCHEMA.INNODB_MUTEXES table.
-@return 0 on success */
-static
-int
-i_s_innodb_mutexes_fill_table(
-/*==========================*/
-	THD*		thd,	/*!< in: thread */
-	TABLE_LIST*	tables,	/*!< in/out: tables to fill */
-	Item*		)	/*!< in: condition (not used) */
-{
-	rw_lock_t*	lock;
-	ulint		block_lock_oswait_count = 0;
-	rw_lock_t*	block_lock = NULL;
-	Field**		fields = tables->table->field;
-
-	DBUG_ENTER("i_s_innodb_mutexes_fill_table");
-	RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str);
-
-	/* deny access to user without PROCESS_ACL privilege */
-	if (check_global_access(thd, PROCESS_ACL)) {
-		DBUG_RETURN(0);
-	}
-
-	// mutex_enter(&mutex_list_mutex);
-
-#ifdef JAN_TODO_FIXME
-	ib_mutex_t*	mutex;
-	ulint		block_mutex_oswait_count = 0;
-	ib_mutex_t*	block_mutex = NULL;
-	for (mutex = UT_LIST_GET_FIRST(os_mutex_list); mutex != NULL;
-	     mutex = UT_LIST_GET_NEXT(list, mutex)) {
-		if (mutex->count_os_wait == 0) {
-			continue;
-		}
-
-		if (buf_pool_is_block_mutex(mutex)) {
-			block_mutex = mutex;
-			block_mutex_oswait_count += mutex->count_os_wait;
-			continue;
-		}
-
-		OK(field_store_string(fields[MUTEXES_NAME], mutex->cmutex_name));
-		OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(mutex->cfile_name)));
-		OK(fields[MUTEXES_CREATE_LINE]->store(mutex->cline, true));
-		fields[MUTEXES_CREATE_LINE]->set_notnull();
-		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)mutex->count_os_wait));
-		OK(schema_table_store_record(thd, tables->table));
-	}
-
-	if (block_mutex) {
-		char buf1[IO_SIZE];
-
-		snprintf(buf1, sizeof buf1, "combined %s",
-			 innobase_basename(block_mutex->cfile_name));
-
-		OK(field_store_string(fields[MUTEXES_NAME], block_mutex->cmutex_name));
-		OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
-		OK(fields[MUTEXES_CREATE_LINE]->store(block_mutex->cline, true));
-		fields[MUTEXES_CREATE_LINE]->set_notnull();
-		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_mutex_oswait_count));
-		OK(schema_table_store_record(thd, tables->table));
-	}
-
-	mutex_exit(&mutex_list_mutex);
-#endif /* JAN_TODO_FIXME */
-
-	mutex_enter(&rw_lock_list_mutex);
-
-	for (lock = UT_LIST_GET_FIRST(rw_lock_list); lock != NULL;
-	     lock = UT_LIST_GET_NEXT(list, lock)) {
-		if (lock->count_os_wait == 0) {
-			continue;
-		}
-
-		if (buf_pool_is_block_lock(lock)) {
-			block_lock = lock;
-			block_lock_oswait_count += lock->count_os_wait;
-			continue;
-		}
-
-		//OK(field_store_string(fields[MUTEXES_NAME], lock->lock_name));
-		OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(lock->cfile_name)));
-		OK(fields[MUTEXES_CREATE_LINE]->store(lock->cline, true));
-		fields[MUTEXES_CREATE_LINE]->set_notnull();
-		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)lock->count_os_wait));
-		OK(schema_table_store_record(thd, tables->table));
-	}
-
-	if (block_lock) {
-		char buf1[IO_SIZE];
-
-		snprintf(buf1, sizeof buf1, "combined %s",
-			 innobase_basename(block_lock->cfile_name));
-
-		//OK(field_store_string(fields[MUTEXES_NAME], block_lock->lock_name));
-		OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
-		OK(fields[MUTEXES_CREATE_LINE]->store(block_lock->cline, true));
-		fields[MUTEXES_CREATE_LINE]->set_notnull();
-		OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_lock_oswait_count));
-		OK(schema_table_store_record(thd, tables->table));
-	}
-
-	mutex_exit(&rw_lock_list_mutex);
-
-	DBUG_RETURN(0);
-}
-
-/*******************************************************************//**
-Bind the dynamic table INFORMATION_SCHEMA.INNODB_MUTEXES
-@return 0 on success */
-static
-int
-innodb_mutexes_init(
-/*================*/
-	void*	p)	/*!< in/out: table schema object */
-{
-	ST_SCHEMA_TABLE*	schema;
-
-	DBUG_ENTER("innodb_mutexes_init");
-
-	schema = (ST_SCHEMA_TABLE*) p;
-
-	schema->fields_info = innodb_mutexes_fields_info;
-	schema->fill_table = i_s_innodb_mutexes_fill_table;
-
-	DBUG_RETURN(0);
-}
-
-UNIV_INTERN struct st_maria_plugin	i_s_innodb_mutexes =
-{
-	/* the plugin type (a MYSQL_XXX_PLUGIN value) */
-	/* int */
-	STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
-
-	/* pointer to type-specific plugin descriptor */
-	/* void* */
-	STRUCT_FLD(info, &i_s_info),
-
-	/* plugin name */
-	/* const char* */
-	STRUCT_FLD(name, "INNODB_MUTEXES"),
-
-	/* plugin author (for SHOW PLUGINS) */
-	/* const char* */
-	STRUCT_FLD(author, plugin_author),
-
-	/* general descriptive text (for SHOW PLUGINS) */
-	/* const char* */
-	STRUCT_FLD(descr, "InnoDB SYS_DATAFILES"),
-
-	/* the plugin license (PLUGIN_LICENSE_XXX) */
-	/* int */
-	STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
-
-	/* the function to invoke when plugin is loaded */
-	/* int (*)(void*); */
-	STRUCT_FLD(init, innodb_mutexes_init),
-
-	/* the function to invoke when plugin is unloaded */
-	/* int (*)(void*); */
-	STRUCT_FLD(deinit, i_s_common_deinit),
-
-	/* plugin version (for SHOW PLUGINS) */
-	/* unsigned int */
-	STRUCT_FLD(version, INNODB_VERSION_SHORT),
-
-	/* struct st_mysql_show_var* */
-	STRUCT_FLD(status_vars, NULL),
-
-	/* struct st_mysql_sys_var** */
-	STRUCT_FLD(system_vars, NULL),
-
-        /* Maria extension */
-	STRUCT_FLD(version_info, INNODB_VERSION_STR),
-        STRUCT_FLD(maturity, MariaDB_PLUGIN_MATURITY_STABLE),
-};
-
 /**  SYS_SEMAPHORE_WAITS  ************************************************/
 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_SYS_SEMAPHORE_WAITS */
 static ST_FIELD_INFO	innodb_sys_semaphore_waits_fields_info[] =
diff --git a/storage/innobase/handler/i_s.h b/storage/innobase/handler/i_s.h
index 4ff2248c28e..f48669ddeac 100644
--- a/storage/innobase/handler/i_s.h
+++ b/storage/innobase/handler/i_s.h
@@ -59,7 +59,6 @@ extern struct st_maria_plugin	i_s_innodb_sys_foreign;
 extern struct st_maria_plugin	i_s_innodb_sys_foreign_cols;
 extern struct st_maria_plugin	i_s_innodb_sys_tablespaces;
 extern struct st_maria_plugin	i_s_innodb_sys_datafiles;
-extern struct st_maria_plugin	i_s_innodb_mutexes;
 extern struct st_maria_plugin	i_s_innodb_sys_virtual;
 extern struct st_maria_plugin	i_s_innodb_tablespaces_encryption;
 extern struct st_maria_plugin	i_s_innodb_tablespaces_scrubbing;
diff --git a/storage/innobase/include/sync0rw.h b/storage/innobase/include/sync0rw.h
index 4f23e81185c..f1c1fca7678 100644
--- a/storage/innobase/include/sync0rw.h
+++ b/storage/innobase/include/sync0rw.h
@@ -2,7 +2,7 @@
 
 Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
-Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
+Copyright (c) 2017, 2019, MariaDB Corporation.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -105,11 +105,6 @@ struct rw_lock_t;
 struct rw_lock_debug_t;
 #endif /* UNIV_DEBUG */
 
-typedef UT_LIST_BASE_NODE_T(rw_lock_t)	rw_lock_list_t;
-
-extern rw_lock_list_t			rw_lock_list;
-extern ib_mutex_t			rw_lock_list_mutex;
-
 /** Counters for RW locks. */
 extern rw_lock_stats_t	rw_lock_stats;
 
@@ -534,15 +529,6 @@ rw_lock_is_locked(
 	ulint		lock_type);	/*!< in: lock type: RW_LOCK_S,
 					RW_LOCK_X or RW_LOCK_SX */
 #ifdef UNIV_DEBUG
-/***************************************************************//**
-Prints debug info of currently locked rw-locks. */
-void
-rw_lock_list_print_info(
-/*====================*/
-	FILE*		file);		/*!< in: file where to print */
-
-/*#####################################################################*/
-
 /*********************************************************************//**
 Prints info of a debug struct. */
 void
@@ -613,9 +599,6 @@ struct rw_lock_t
 	/** Line number where last time x-locked */
 	unsigned	last_x_line:14;
 
-	/** Count of os_waits. May not be accurate */
-	uint32_t	count_os_wait;
-
 	/** All allocated rw locks are put into a list */
 	UT_LIST_NODE_T(rw_lock_t) list;
 
diff --git a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h
index 5af2cbfe6c5..b34a7309e53 100644
--- a/storage/innobase/include/sync0sync.h
+++ b/storage/innobase/include/sync0sync.h
@@ -87,7 +87,6 @@ extern mysql_pfs_key_t page_zip_stat_per_index_mutex_key;
 # ifdef UNIV_DEBUG
 extern mysql_pfs_key_t	rw_lock_debug_mutex_key;
 # endif /* UNIV_DEBUG */
-extern mysql_pfs_key_t	rw_lock_list_mutex_key;
 extern mysql_pfs_key_t	rw_lock_mutex_key;
 extern mysql_pfs_key_t	srv_innodb_monitor_mutex_key;
 extern mysql_pfs_key_t	srv_misc_tmpfile_mutex_key;
diff --git a/storage/innobase/sync/sync0arr.cc b/storage/innobase/sync/sync0arr.cc
index 9221a643213..8aa11dc7f25 100644
--- a/storage/innobase/sync/sync0arr.cc
+++ b/storage/innobase/sync/sync0arr.cc
@@ -1385,7 +1385,7 @@ sync_arr_fill_sys_semphore_waits_table(
 						OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_FILE], innobase_basename(rwlock->last_x_file_name)));
 						OK(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->store(rwlock->last_x_line, true));
 						fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_LINE]->set_notnull();
-						OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_OS_WAIT_COUNT], rwlock->count_os_wait));
+						//OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_OS_WAIT_COUNT], rwlock->count_os_wait));
 					}
 				}
 			}
diff --git a/storage/innobase/sync/sync0debug.cc b/storage/innobase/sync/sync0debug.cc
index 8fa4e6c5bd2..711ddbfc9a7 100644
--- a/storage/innobase/sync/sync0debug.cc
+++ b/storage/innobase/sync/sync0debug.cc
@@ -1,7 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2018, MariaDB Corporation.
+Copyright (c) 2017, 2019, MariaDB Corporation.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -1370,9 +1370,6 @@ sync_latch_meta_init()
 
 	LATCH_ADD_MUTEX(RTR_PATH_MUTEX, SYNC_ANY_LATCH, rtr_path_mutex_key);
 
-	LATCH_ADD_MUTEX(RW_LOCK_LIST, SYNC_NO_ORDER_CHECK,
-			rw_lock_list_mutex_key);
-
 	LATCH_ADD_MUTEX(RW_LOCK_MUTEX, SYNC_NO_ORDER_CHECK, rw_lock_mutex_key);
 
 	LATCH_ADD_MUTEX(SRV_INNODB_MONITOR, SYNC_NO_ORDER_CHECK,
@@ -1720,12 +1717,6 @@ sync_check_init()
 
 	sync_latch_meta_init();
 
-	/* Init the rw-lock & mutex list and create the mutex to protect it. */
-
-	UT_LIST_INIT(rw_lock_list, &rw_lock_t::list);
-
-	mutex_create(LATCH_ID_RW_LOCK_LIST, &rw_lock_list_mutex);
-
 	ut_d(LatchDebug::init());
 
 	sync_array_init();
@@ -1737,10 +1728,7 @@ sync_check_close()
 {
 	ut_d(LatchDebug::shutdown());
 
-	mutex_free(&rw_lock_list_mutex);
-
 	sync_array_close();
 
 	sync_latch_meta_destroy();
 }
-
diff --git a/storage/innobase/sync/sync0rw.cc b/storage/innobase/sync/sync0rw.cc
index 0f78136c71c..3283c25798a 100644
--- a/storage/innobase/sync/sync0rw.cc
+++ b/storage/innobase/sync/sync0rw.cc
@@ -140,10 +140,6 @@ wait_ex_event:	A thread may only wait on the wait_ex_event after it has
 
 rw_lock_stats_t		rw_lock_stats;
 
-/* The global list of rw-locks */
-rw_lock_list_t		rw_lock_list;
-ib_mutex_t		rw_lock_list_mutex;
-
 #ifdef UNIV_DEBUG
 /******************************************************************//**
 Creates a debug info struct. */
@@ -229,22 +225,12 @@ rw_lock_create_func(
 	less than 8192. cline is unsigned:13. */
 	ut_ad(cline <= 8192);
 	lock->cline = cline;
-	lock->count_os_wait = 0;
 	lock->last_x_file_name = "not yet reserved";
 	lock->last_x_line = 0;
 	lock->event = os_event_create(0);
 	lock->wait_ex_event = os_event_create(0);
 
 	lock->is_block_lock = 0;
-
-	mutex_enter(&rw_lock_list_mutex);
-
-	ut_ad(UT_LIST_GET_FIRST(rw_lock_list) == NULL
-	      || UT_LIST_GET_FIRST(rw_lock_list)->magic_n == RW_LOCK_MAGIC_N);
-
-	UT_LIST_ADD_FIRST(rw_lock_list, lock);
-
-	mutex_exit(&rw_lock_list_mutex);
 }
 
 /******************************************************************//**
@@ -258,17 +244,9 @@ rw_lock_free_func(
 {
 	ut_ad(rw_lock_validate(lock));
 	ut_a(lock->lock_word.load(std::memory_order_relaxed) == X_LOCK_DECR);
-
-	mutex_enter(&rw_lock_list_mutex);
-
 	os_event_destroy(lock->event);
-
 	os_event_destroy(lock->wait_ex_event);
 
-	UT_LIST_REMOVE(rw_lock_list, lock);
-
-	mutex_exit(&rw_lock_list_mutex);
-
 	/* We did an in-place new in rw_lock_create_func() */
 	ut_d(lock->~rw_lock_t());
 	/* Sometimes (maybe when compiled with GCC -O3) the above call
@@ -295,34 +273,26 @@ rw_lock_s_lock_spin(
 	lint		spin_count = 0;
 	int64_t		count_os_wait = 0;
 
-	/* We reuse the thread id to index into the counter, cache
-	it here for efficiency. */
-
 	ut_ad(rw_lock_validate(lock));
 
 lock_loop:
-
 	/* Spin waiting for the writer field to become free */
 	HMT_low();
-	while (i < srv_n_spin_wait_rounds &&
-	       lock->lock_word.load(std::memory_order_relaxed) <= 0) {
+	while (lock->lock_word.load(std::memory_order_relaxed) <= 0) {
 		ut_delay(srv_spin_wait_delay);
-		i++;
+		if (++i >= srv_n_spin_wait_rounds) {
+			os_thread_yield();
+			break;
+		}
 	}
 
 	HMT_medium();
-	if (i >= srv_n_spin_wait_rounds) {
-		os_thread_yield();
-	}
-
 	++spin_count;
 
 	/* We try once again to obtain the lock */
 	if (rw_lock_s_lock_low(lock, pass, file_name, line)) {
 
-		if (count_os_wait > 0) {
-			lock->count_os_wait +=
-				static_cast<uint32_t>(count_os_wait);
+		if (count_os_wait) {
 			rw_lock_stats.rw_s_os_wait_count.add(count_os_wait);
 		}
 
@@ -351,11 +321,7 @@ rw_lock_s_lock_spin(
 
 			sync_array_free_cell(sync_arr, cell);
 
-			if (count_os_wait > 0) {
-
-				lock->count_os_wait +=
-					static_cast<uint32_t>(count_os_wait);
-
+			if (count_os_wait) {
 				rw_lock_stats.rw_s_os_wait_count.add(
 					count_os_wait);
 			}
@@ -472,8 +438,7 @@ rw_lock_x_lock_wait_func(
 	HMT_medium();
 	rw_lock_stats.rw_x_spin_round_count.add(n_spins);
 
-	if (count_os_wait > 0) {
-		lock->count_os_wait += static_cast<uint32_t>(count_os_wait);
+	if (count_os_wait) {
 		rw_lock_stats.rw_x_os_wait_count.add(count_os_wait);
 	}
 }
@@ -672,9 +637,7 @@ rw_lock_x_lock_func(
 
 	if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
 
-		if (count_os_wait > 0) {
-			lock->count_os_wait +=
-				static_cast<uint32_t>(count_os_wait);
+		if (count_os_wait) {
 			rw_lock_stats.rw_x_os_wait_count.add(count_os_wait);
 		}
 
@@ -718,9 +681,7 @@ rw_lock_x_lock_func(
 	if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
 		sync_array_free_cell(sync_arr, cell);
 
-		if (count_os_wait > 0) {
-			lock->count_os_wait +=
-				static_cast<uint32_t>(count_os_wait);
+		if (count_os_wait) {
 			rw_lock_stats.rw_x_os_wait_count.add(count_os_wait);
 		}
 
@@ -768,12 +729,8 @@ rw_lock_sx_lock_func(
 	ut_ad(!rw_lock_own(lock, RW_LOCK_S));
 
 lock_loop:
-
 	if (rw_lock_sx_lock_low(lock, pass, file_name, line)) {
-
-		if (count_os_wait > 0) {
-			lock->count_os_wait +=
-				static_cast<uint32_t>(count_os_wait);
+		if (count_os_wait) {
 			rw_lock_stats.rw_sx_os_wait_count.add(count_os_wait);
 		}
 
@@ -819,9 +776,7 @@ rw_lock_sx_lock_func(
 
 		sync_array_free_cell(sync_arr, cell);
 
-		if (count_os_wait > 0) {
-			lock->count_os_wait +=
-				static_cast<uint32_t>(count_os_wait);
+		if (count_os_wait) {
 			rw_lock_stats.rw_sx_os_wait_count.add(count_os_wait);
 		}
 
@@ -1067,56 +1022,6 @@ bool rw_lock_own_flagged(const rw_lock_t* lock, rw_lock_flags_t flags)
 	return false;
 }
 
-/***************************************************************//**
-Prints debug info of currently locked rw-locks. */
-void
-rw_lock_list_print_info(
-/*====================*/
-	FILE*	file)		/*!< in: file where to print */
-{
-	ulint		count = 0;
-
-	mutex_enter(&rw_lock_list_mutex);
-
-	fputs("-------------\n"
-	      "RW-LATCH INFO\n"
-	      "-------------\n", file);
-
-	for (const rw_lock_t* lock = UT_LIST_GET_FIRST(rw_lock_list);
-	     lock != NULL;
-	     lock = UT_LIST_GET_NEXT(list, lock)) {
-
-		count++;
-
-		if (lock->lock_word.load(std::memory_order_relaxed) != X_LOCK_DECR) {
-
-			fprintf(file, "RW-LOCK: %p ", (void*) lock);
-
-			if (int32_t waiters= lock->waiters.load(std::memory_order_relaxed)) {
-				fprintf(file, " (%d waiters)\n", waiters);
-			} else {
-				putc('\n', file);
-			}
-
-			rw_lock_debug_t* info;
-
-			rw_lock_debug_mutex_enter();
-
-			for (info = UT_LIST_GET_FIRST(lock->debug_list);
-			     info != NULL;
-			     info = UT_LIST_GET_NEXT(list, info)) {
-
-				rw_lock_debug_print(file, info);
-			}
-
-			rw_lock_debug_mutex_exit();
-		}
-	}
-
-	fprintf(file, "Total number of rw-locks " ULINTPF "\n", count);
-	mutex_exit(&rw_lock_list_mutex);
-}
-
 /*********************************************************************//**
 Prints info of a debug struct. */
 void
diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc
index 3873e8532e7..5d7858e3cee 100644
--- a/storage/innobase/sync/sync0sync.cc
+++ b/storage/innobase/sync/sync0sync.cc
@@ -73,7 +73,6 @@ mysql_pfs_key_t rtr_active_mutex_key;
 mysql_pfs_key_t	rtr_match_mutex_key;
 mysql_pfs_key_t	rtr_path_mutex_key;
 mysql_pfs_key_t rtr_ssn_mutex_key;
-mysql_pfs_key_t	rw_lock_list_mutex_key;
 mysql_pfs_key_t	rw_lock_mutex_key;
 mysql_pfs_key_t	srv_innodb_monitor_mutex_key;
 mysql_pfs_key_t	srv_misc_tmpfile_mutex_key;
@@ -161,10 +160,6 @@ Prints info of the sync system.
 void
 sync_print(FILE* file)
 {
-#ifdef UNIV_DEBUG
-	rw_lock_list_print_info(file);
-#endif /* UNIV_DEBUG */
-
 	sync_array_print(file);
 
 	sync_print_wait_info(file);
@@ -254,15 +249,4 @@ MutexMonitor::reset()
 			(*it)->get_counter()->reset();
 		}
 	}
-
-	mutex_enter(&rw_lock_list_mutex);
-
-	for (rw_lock_t* rw_lock = UT_LIST_GET_FIRST(rw_lock_list);
-	     rw_lock != NULL;
-	     rw_lock = UT_LIST_GET_NEXT(list, rw_lock)) {
-
-		rw_lock->count_os_wait = 0;
-	}
-
-	mutex_exit(&rw_lock_list_mutex);
 }
-- 
2.20.1

