Skip to content

Commit 472d2d0

Browse files
grooverdansvoj
authored andcommitted
my_large_free_int merge into my_large_free
1 parent 4ac7693 commit 472d2d0

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

mysys/my_largepage.c

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static void my_get_large_page_sizes(size_t sizes[]);
6060
static inline my_bool my_is_2pow(size_t n) { return !((n) & ((n) - 1)); }
6161

6262
static uchar* my_large_malloc_int(size_t *size, myf my_flags);
63-
static my_bool my_large_free_int(void *ptr, size_t size);
6463

6564
#ifdef HAVE_LARGE_PAGES
6665

@@ -222,12 +221,40 @@ void my_large_free(void *ptr, size_t size)
222221
DBUG_ENTER("my_large_free");
223222

224223
/*
225-
my_large_free_int() can only fail if ptr was not allocated with
224+
The following implementations can only fail if ptr was not allocated with
226225
my_large_malloc_int(), i.e. my_malloc_lock() was used so we should free it
227226
with my_free_lock()
228227
*/
229-
if (!my_large_free_int(ptr, size))
228+
#if defined(HAVE_MMAP) && !defined(_WIN32)
229+
if (munmap(ptr, size))
230+
{
231+
/*
232+
This occurs when the original allocation fell back to conventional
233+
memory so ignore the EINVAL error.
234+
*/
235+
if (errno == EINVAL)
236+
{
237+
my_free_lock(ptr);
238+
}
239+
else
240+
{
241+
fprintf(stderr, "Warning: Failed to unmap %zu bytes, errno %d\n", size, errno);
242+
}
243+
}
244+
#elif defined(_WIN32)
245+
/*
246+
When RELEASE memory, the size parameter must be 0.
247+
Do not use MEM_RELEASE with MEM_DECOMMIT.
248+
*/
249+
if (ptr && !VirtualFree(ptr, 0, MEM_RELEASE))
250+
{
251+
fprintf(stderr,
252+
"Error: VirtualFree(%p, %zu) failed; Windows error %lu\n", ptr, size, GetLastError());
230253
my_free_lock(ptr);
254+
}
255+
#else
256+
#error No my_large_free implementation for this OS
257+
#endif
231258
/*
232259
For ASAN, we need to explicitly unpoison this memory region because the OS
233260
may reuse that memory for some TLS or stack variable. It will remain
@@ -384,27 +411,6 @@ static void my_get_large_page_sizes(size_t sizes[my_large_page_sizes_length])
384411
}
385412
#endif
386413

387-
#if defined(HAVE_MMAP) && !defined(_WIN32)
388-
389-
/* mmap and Linux-specific large pages deallocator */
390-
391-
my_bool my_large_free_int(void *ptr, size_t size)
392-
{
393-
DBUG_ENTER("my_large_free_int");
394-
395-
if (munmap(ptr, size))
396-
{
397-
/* This occurs when the original allocation fell back to conventional memory so ignore the EINVAL error */
398-
if (errno != EINVAL)
399-
{
400-
fprintf(stderr, "Warning: Failed to unmap %zu bytes, errno %d\n", size, errno);
401-
}
402-
DBUG_RETURN(0);
403-
}
404-
DBUG_RETURN(1);
405-
}
406-
#endif /* HAVE_MMAP */
407-
408414
#if defined(HAVE_MMAP) && !defined(__linux__) && !defined(MAP_ALIGNED) \
409415
&& !defined(_WIN32)
410416

@@ -490,23 +496,5 @@ uchar* my_large_malloc_int(size_t *size, myf my_flags)
490496
DBUG_RETURN(ptr);
491497
}
492498

493-
/* Windows-specific large pages deallocator */
494-
495-
my_bool my_large_free_int(void *ptr, size_t size)
496-
{
497-
DBUG_ENTER("my_large_free_int");
498-
/*
499-
When RELEASE memory, the size parameter must be 0.
500-
Do not use MEM_RELEASE with MEM_DECOMMIT.
501-
*/
502-
if (ptr && !VirtualFree(ptr, 0, MEM_RELEASE))
503-
{
504-
fprintf(stderr,
505-
"Error: VirtualFree(%p, %zu) failed; Windows error %lu\n", ptr, size, GetLastError());
506-
DBUG_RETURN(0);
507-
}
508-
509-
DBUG_RETURN(1);
510-
}
511499
#endif /* _WIN32 */
512500

0 commit comments

Comments
 (0)