Skip to content

Commit 397b6b1

Browse files
committed
MDEV-18946 munmap of 1 byte during shutdown is EINVAL
In MDEV-10814, a missing argument caused a later optional argument (bool true) to be treated as a size. The unmap of this memory occurs during shutdown and resizing innodb buffer pool. As a result the memory is lost but still allocated until shutdown is completed.
2 parents 4f41047 + a9056a2 commit 397b6b1

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

storage/innobase/buf/buf0buf.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,7 @@ buf_chunk_init(
15711571

15721572
DBUG_EXECUTE_IF("ib_buf_chunk_init_fails", return(NULL););
15731573

1574-
chunk->mem = buf_pool->allocator.allocate_large(mem_size,
1575-
&chunk->mem_pfx, true);
1574+
chunk->mem = buf_pool->allocator.allocate_large_dontdump(mem_size, &chunk->mem_pfx);
15761575

15771576
if (UNIV_UNLIKELY(chunk->mem == NULL)) {
15781577

@@ -1865,9 +1864,8 @@ buf_pool_init_instance(
18651864
&block->debug_latch));
18661865
}
18671866

1868-
buf_pool->allocator.deallocate_large(
1869-
chunk->mem, &chunk->mem_pfx, chunk->mem_size(),
1870-
true);
1867+
buf_pool->allocator.deallocate_large_dodump(
1868+
chunk->mem, &chunk->mem_pfx, chunk->mem_size());
18711869
}
18721870
ut_free(buf_pool->chunks);
18731871
buf_pool_mutex_exit(buf_pool);
@@ -2014,8 +2012,8 @@ buf_pool_free_instance(
20142012
ut_d(rw_lock_free(&block->debug_latch));
20152013
}
20162014

2017-
buf_pool->allocator.deallocate_large(
2018-
chunk->mem, &chunk->mem_pfx, true);
2015+
buf_pool->allocator.deallocate_large_dodump(
2016+
chunk->mem, &chunk->mem_pfx, chunk->mem_size());
20192017
}
20202018

20212019
for (ulint i = BUF_FLUSH_LRU; i < BUF_FLUSH_N_TYPES; ++i) {
@@ -2892,8 +2890,8 @@ buf_pool_resize()
28922890
&block->debug_latch));
28932891
}
28942892

2895-
buf_pool->allocator.deallocate_large(
2896-
chunk->mem, &chunk->mem_pfx, true);
2893+
buf_pool->allocator.deallocate_large_dodump(
2894+
chunk->mem, &chunk->mem_pfx, chunk->mem_size());
28972895

28982896
sum_freed += chunk->size;
28992897

storage/innobase/include/ut0new.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,18 @@ class ut_allocator {
653653
return(ptr);
654654
}
655655

656+
pointer
657+
allocate_large_dontdump(
658+
size_type n_elements,
659+
ut_new_pfx_t* pfx)
660+
{
661+
return allocate_large(n_elements, pfx, true);
662+
}
656663
/** Free a memory allocated by allocate_large() and trace the
657664
deallocation.
658665
@param[in,out] ptr pointer to memory to free
659666
@param[in] pfx descriptor of the memory, as returned by
660-
allocate_large().
661-
@param[in] dodump if true, advise the OS to include this
662-
memory again if a core dump occurs. */
667+
allocate_large(). */
663668
void
664669
deallocate_large(
665670
pointer ptr,
@@ -668,12 +673,8 @@ class ut_allocator {
668673
pfx
669674
#endif
670675
,
671-
size_tsize,
672-
booldodump = false)
676+
size_tsize)
673677
{
674-
if (dodump) {
675-
ut_dodump(ptr, size);
676-
}
677678
#ifdef UNIV_PFS_MEMORY
678679
if (pfx) {
679680
deallocate_trace(pfx);
@@ -683,8 +684,27 @@ class ut_allocator {
683684
os_mem_free_large(ptr, size);
684685
}
685686

687+
void
688+
deallocate_large_dodump(
689+
pointer ptr,
690+
const ut_new_pfx_t*
686691
#ifdef UNIV_PFS_MEMORY
692+
pfx
693+
#endif
694+
,
695+
size_tsize)
696+
{
697+
ut_dodump(ptr, size);
698+
deallocate_large(ptr,
699+
#ifdef UNIV_PFS_MEMORY
700+
pfx,
701+
#else
702+
NULL,
703+
#endif
704+
size);
705+
}
687706

707+
#ifdef UNIV_PFS_MEMORY
688708
/** Get the performance schema key to use for tracing allocations.
689709
@param[in] file file name of the caller or NULL if unknown
690710
@return performance schema key */

0 commit comments

Comments
 (0)