Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDEV-20684: innodb/query cache use madvise CORE/NOCORE on FreeBSD
This applies to large allocations.

This maps to the way Linux does it in MDEV-10814 except FreeBSD uses
different constants.

Adjust error string to match to implementation.

Tested on FreeBSD-12.0
  • Loading branch information
grooverdan authored and Sergey Vojtovich committed Oct 2, 2019
1 parent 7e44c45 commit 716c748
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions include/my_global.h
Expand Up @@ -445,6 +445,20 @@ C_MODE_END
#if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
extern "C" int madvise(void *addr, size_t len, int behav);
#endif
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
/** FreeBSD equivalent */
#if defined(MADV_CORE) && !defined(MADV_DODUMP)
#define MADV_DODUMP MADV_CORE
#define MADV_DONTDUMP MADV_NOCORE
#define DODUMP_STR "MADV_CORE"
#define DONTDUMP_STR "MADV_NOCORE"
#else
#define DODUMP_STR "MADV_DODUMP"
#define DONTDUMP_STR "MADV_DONTDUMP"
#endif


#define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
#define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_cache.cc
Expand Up @@ -2662,7 +2662,7 @@ size_t Query_cache::init_cache()
#if defined(DBUG_OFF) && defined(HAVE_MADVISE) && defined(MADV_DONTDUMP)
if (madvise(cache, query_cache_size+additional_data_size, MADV_DONTDUMP))
{
DBUG_PRINT("warning", ("coudn't mark query cache memory as MADV_DONTDUMP: %s",
DBUG_PRINT("warning", ("coudn't mark query cache memory as " DONTDUMP_STR ": %s",
strerror(errno)));
}
#endif
Expand Down Expand Up @@ -2831,7 +2831,7 @@ void Query_cache::free_cache()
#if defined(DBUG_OFF) && defined(HAVE_MADVISE) && defined(MADV_DODUMP)
if (madvise(cache, query_cache_size+additional_data_size, MADV_DODUMP))
{
DBUG_PRINT("warning", ("coudn't mark query cache memory as MADV_DODUMP: %s",
DBUG_PRINT("warning", ("coudn't mark query cache memory as " DODUMP_STR ": %s",
strerror(errno)));
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/ut0new.h
Expand Up @@ -252,7 +252,7 @@ static inline void ut_allocate_trace_dontdump(void *ptr, size_t bytes,

#if defined(DBUG_OFF) && defined(HAVE_MADVISE) && defined(MADV_DONTDUMP)
if (dontdump && madvise(ptr, bytes, MADV_DONTDUMP)) {
ib::warn() << "Failed to set memory to DONTDUMP: "
ib::warn() << "Failed to set memory to " DONTDUMP_STR ": "
<< strerror(errno)
<< " ptr " << ptr
<< " size " << bytes;
Expand All @@ -270,7 +270,7 @@ static inline void ut_allocate_trace_dontdump(void *ptr, size_t bytes,
static inline void ut_dodump(void* ptr, size_t m_size)
{
if (ptr && madvise(ptr, m_size, MADV_DODUMP)) {
ib::warn() << "Failed to set memory to DODUMP: "
ib::warn() << "Failed to set memory to " DODUMP_STR ": "
<< strerror(errno)
<< " ptr " << ptr
<< " size " << m_size;
Expand Down

0 comments on commit 716c748

Please sign in to comment.