@@ -60,7 +60,6 @@ static void my_get_large_page_sizes(size_t sizes[]);
60
60
static inline my_bool my_is_2pow (size_t n ) { return !((n ) & ((n ) - 1 )); }
61
61
62
62
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 );
64
63
65
64
#ifdef HAVE_LARGE_PAGES
66
65
@@ -222,12 +221,40 @@ void my_large_free(void *ptr, size_t size)
222
221
DBUG_ENTER ("my_large_free" );
223
222
224
223
/*
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
226
225
my_large_malloc_int(), i.e. my_malloc_lock() was used so we should free it
227
226
with my_free_lock()
228
227
*/
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 ());
230
253
my_free_lock (ptr );
254
+ }
255
+ #else
256
+ #error No my_large_free implementation for this OS
257
+ #endif
231
258
/*
232
259
For ASAN, we need to explicitly unpoison this memory region because the OS
233
260
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])
384
411
}
385
412
#endif
386
413
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
-
408
414
#if defined(HAVE_MMAP ) && !defined(__linux__ ) && !defined(MAP_ALIGNED ) \
409
415
&& !defined(_WIN32 )
410
416
@@ -490,23 +496,5 @@ uchar* my_large_malloc_int(size_t *size, myf my_flags)
490
496
DBUG_RETURN (ptr );
491
497
}
492
498
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
- }
511
499
#endif /* _WIN32 */
512
500
0 commit comments