Skip to content

Commit

Permalink
MDEV-17441 - InnoDB transition to C++11 atomics
Browse files Browse the repository at this point in the history
os_total_large_mem_allocated transition to Atomic_counter.
  • Loading branch information
Sergey Vojtovich committed Dec 27, 2018
1 parent dab38ce commit 4404ee2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/include/os0proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef unsigned long int os_process_id_t;

/** The total amount of memory currently allocated from the operating
system with os_mem_alloc_large(). */
extern ulint os_total_large_mem_allocated;
extern Atomic_counter<ulint> os_total_large_mem_allocated;

/** Whether to use large pages in the buffer pool */
extern my_bool os_use_large_pages;
Expand Down
21 changes: 7 additions & 14 deletions storage/innobase/os/os0proc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MAP_ANON but MAP_ANON is marked as deprecated */

/** The total amount of memory currently allocated from the operating
system with os_mem_alloc_large(). */
ulint os_total_large_mem_allocated = 0;
Atomic_counter<ulint> os_total_large_mem_allocated;

/** Whether to use large pages in the buffer pool */
my_bool os_use_large_pages;
Expand Down Expand Up @@ -100,9 +100,7 @@ os_mem_alloc_large(

if (ptr) {
*n = size;
my_atomic_addlint(
&os_total_large_mem_allocated, size);

os_total_large_mem_allocated += size;
UNIV_MEM_ALLOC(ptr, size);
return(ptr);
}
Expand All @@ -127,8 +125,7 @@ os_mem_alloc_large(
ib::info() << "VirtualAlloc(" << size << " bytes) failed;"
" Windows error " << GetLastError();
} else {
my_atomic_addlint(
&os_total_large_mem_allocated, size);
os_total_large_mem_allocated += size;
UNIV_MEM_ALLOC(ptr, size);
}
#else
Expand All @@ -143,8 +140,7 @@ os_mem_alloc_large(
" errno " << errno;
ptr = NULL;
} else {
my_atomic_addlint(
&os_total_large_mem_allocated, size);
os_total_large_mem_allocated += size;
UNIV_MEM_ALLOC(ptr, size);
}
#endif
Expand All @@ -163,8 +159,7 @@ os_mem_free_large(

#if defined HAVE_LINUX_LARGE_PAGES && defined UNIV_LINUX
if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
my_atomic_addlint(
&os_total_large_mem_allocated, -size);
os_total_large_mem_allocated -= size;
UNIV_MEM_FREE(ptr, size);
return;
}
Expand All @@ -176,8 +171,7 @@ os_mem_free_large(
ib::error() << "VirtualFree(" << ptr << ", " << size
<< ") failed; Windows error " << GetLastError();
} else {
my_atomic_addlint(
&os_total_large_mem_allocated, -lint(size));
os_total_large_mem_allocated -= size;
UNIV_MEM_FREE(ptr, size);
}
#elif !defined OS_MAP_ANON
Expand All @@ -191,8 +185,7 @@ os_mem_free_large(
ib::error() << "munmap(" << ptr << ", " << size << ") failed;"
" errno " << errno;
} else {
my_atomic_addlint(
&os_total_large_mem_allocated, -size);
os_total_large_mem_allocated -= size;
UNIV_MEM_FREE(ptr, size);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/srv/srv0srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ srv_printf_innodb_monitor(
fprintf(file,
"Total large memory allocated " ULINTPF "\n"
"Dictionary memory allocated " ULINTPF "\n",
os_total_large_mem_allocated,
ulint{os_total_large_mem_allocated},
dict_sys_get_size());

buf_print_io(file);
Expand Down

0 comments on commit 4404ee2

Please sign in to comment.