From 5b0a86c5c045a2c24ae4fde3ba98e191f1b1dbfe Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 26 Nov 2019 11:43:47 +1100 Subject: [PATCH] define linker section for global variables POC --- include/my_compiler.h | 2 ++ sql/CMakeLists.txt | 6 +++++- sql/mysqld.ld | 21 +++++++++++++++++++++ storage/innobase/btr/btr0sea.cc | 4 ++-- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 sql/mysqld.ld diff --git a/include/my_compiler.h b/include/my_compiler.h index 2c3daee5ad0..32462534836 100644 --- a/include/my_compiler.h +++ b/include/my_compiler.h @@ -187,4 +187,6 @@ struct my_aligned_storage # define SUPPRESS_UBSAN #endif +#define MY_GLOBAL __attribute((section (".data.read_mostly"))) + #endif /* MY_COMPILER_INCLUDED */ diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 88e17c0d941..49b04311c2a 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -465,7 +465,6 @@ ADD_DEPENDENCIES(sqlgunitlib GenError) ######################### GUnit Lib ################################# - IF(WIN32) SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h message.rc) ELSE() @@ -556,6 +555,11 @@ IF(WITH_MYSQLD_LDFLAGS) "${MYSQLD_LINK_FLAGS} ${WITH_MYSQLD_LDFLAGS}") ENDIF() +IF(NOT MSVC) + SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_DEPENDS ${CMAKE_SOURCE_DIR}/sql/mysqld.ld) + TARGET_LINK_OPTIONS(mysqld BEFORE PRIVATE LINKER:-T,${CMAKE_SOURCE_DIR}/sql/mysqld.ld) +ENDIF() + # Help INSTALL_DEBUG_TARGET to locate it SET_TARGET_PROPERTIES(mysqld PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/sql/mysqld.ld b/sql/mysqld.ld new file mode 100644 index 00000000000..b7bdc64ea24 --- /dev/null +++ b/sql/mysqld.ld @@ -0,0 +1,21 @@ +/* + +Linker script to create a .data.read_mostly section with ELF linkers. + +This, with the approprate variable attributes, keeps read only variables being +linked adjacent to hot variable (like pseudo number or statistic counters). + +256 (bytes) is from the largest cache-line size (s390) on current hardware. +This ensures that the section afterwards is on a different cache line. As +we are inserting after .rodata, an initial alignment isn't needed. + +*/ + +SECTIONS +{ + .data.read_mostly : { + *(.data.read_mostly) + . = ALIGN(256); + } +} +INSERT AFTER .rodata diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 085ec33ce8b..0d53b937c02 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -55,10 +55,10 @@ Created 2/17/1996 Heikki Tuuri /** Is search system enabled. Search system is protected by array of latches. */ -char btr_search_enabled = true; +char btr_search_enabled MY_GLOBAL = true; /** Number of adaptive hash index partition. */ -ulong btr_ahi_parts = 8; +ulong btr_ahi_parts MY_GLOBAL = 8; #ifdef UNIV_SEARCH_PERF_STAT /** Number of successful adaptive hash index lookups */ -- 2.21.0