the custom SAL allocator is no longer used
ever since commit bc6a5d8e79
Date: Wed Nov 15 16:52:44 2017 +0530
Disable custom allocator
which makes FORCE_SYSALLOC redundant
which makes SYS_ALLOC redundant
Change-Id: I42e1d651473e7601e2280d9fb0662c89808c88f6
Reviewed-on: https://gerrit.libreoffice.org/58263
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
committed by
Michael Meeks
parent
1de9dc5ff7
commit
db354dfad5
12
configure.ac
12
configure.ac
@@ -6639,20 +6639,8 @@ AC_SUBST(CLANGLIBDIR)
|
|||||||
# This makes --enable-lto build with clang work.
|
# This makes --enable-lto build with clang work.
|
||||||
AC_SUBST(LD_PLUGIN)
|
AC_SUBST(LD_PLUGIN)
|
||||||
|
|
||||||
dnl ===================================================================
|
|
||||||
dnl allocator
|
|
||||||
dnl ===================================================================
|
|
||||||
AC_MSG_CHECKING([which memory allocator to use])
|
|
||||||
if test "$with_alloc" = "system"; then
|
|
||||||
AC_MSG_RESULT([system])
|
|
||||||
ALLOC="SYS_ALLOC"
|
|
||||||
fi
|
|
||||||
if test "$with_alloc" = "internal" -o -z "$with_alloc"; then
|
|
||||||
AC_MSG_RESULT([internal])
|
|
||||||
fi
|
|
||||||
AC_CHECK_FUNCS(posix_fallocate, HAVE_POSIX_FALLOCATE=YES, [HAVE_POSIX_FALLOCATE=NO])
|
AC_CHECK_FUNCS(posix_fallocate, HAVE_POSIX_FALLOCATE=YES, [HAVE_POSIX_FALLOCATE=NO])
|
||||||
AC_SUBST(HAVE_POSIX_FALLOCATE)
|
AC_SUBST(HAVE_POSIX_FALLOCATE)
|
||||||
AC_SUBST(ALLOC)
|
|
||||||
|
|
||||||
dnl ===================================================================
|
dnl ===================================================================
|
||||||
dnl Custom build version
|
dnl Custom build version
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define DISABLE_DYNLOADING
|
#define DISABLE_DYNLOADING
|
||||||
#define FORCE_SYSALLOC
|
|
||||||
#define NO_CHILD_PROCESSES
|
#define NO_CHILD_PROCESSES
|
||||||
#undef SAL_LOG_INFO
|
#undef SAL_LOG_INFO
|
||||||
#undef SAL_LOG_WARN
|
#undef SAL_LOG_WARN
|
||||||
|
@@ -23,9 +23,6 @@ $(eval $(call gb_Library_add_defs,sal,\
|
|||||||
$(if $(filter FUZZERS,$(BUILD_TYPE)), \
|
$(if $(filter FUZZERS,$(BUILD_TYPE)), \
|
||||||
-DFORCE_DEFAULT_SIGNAL \
|
-DFORCE_DEFAULT_SIGNAL \
|
||||||
) \
|
) \
|
||||||
$(if $(filter SYS_ALLOC,$(ALLOC))$(filter-out XTRUE,X$(ENABLE_RUNTIME_OPTIMIZATIONS)), \
|
|
||||||
-DFORCE_SYSALLOC \
|
|
||||||
) \
|
|
||||||
$(if $(filter IOS,$(OS)), \
|
$(if $(filter IOS,$(OS)), \
|
||||||
-DNO_CHILD_PROCESSES \
|
-DNO_CHILD_PROCESSES \
|
||||||
) \
|
) \
|
||||||
|
@@ -30,12 +30,6 @@ void rtl_cache_stop_threads(void);
|
|||||||
|
|
||||||
void rtl_cache_start_threads(void);
|
void rtl_cache_start_threads(void);
|
||||||
|
|
||||||
void rtl_memory_init(void);
|
|
||||||
|
|
||||||
void rtl_memory_fini(void);
|
|
||||||
|
|
||||||
void ensureMemorySingleton(void);
|
|
||||||
|
|
||||||
void rtl_locale_init(void);
|
void rtl_locale_init(void);
|
||||||
|
|
||||||
void rtl_locale_fini(void);
|
void rtl_locale_fini(void);
|
||||||
|
@@ -131,7 +131,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID )
|
|||||||
rtl_locale_fini();
|
rtl_locale_fini();
|
||||||
|
|
||||||
/* finalize memory management */
|
/* finalize memory management */
|
||||||
rtl_memory_fini();
|
|
||||||
rtl_cache_fini();
|
rtl_cache_fini();
|
||||||
rtl_arena_fini();
|
rtl_arena_fini();
|
||||||
}
|
}
|
||||||
|
@@ -140,21 +140,6 @@ void rtl_cache_hash_rescale(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline sal_uIntPtr rtl_cache_hash_insert(
|
|
||||||
rtl_cache_type * cache,
|
|
||||||
rtl_cache_bufctl_type * bufctl
|
|
||||||
)
|
|
||||||
{
|
|
||||||
rtl_cache_bufctl_type ** ppHead;
|
|
||||||
|
|
||||||
ppHead = &(cache->m_hash_table[RTL_CACHE_HASH_INDEX(cache, bufctl->m_addr)]);
|
|
||||||
|
|
||||||
bufctl->m_next = (*ppHead);
|
|
||||||
(*ppHead) = bufctl;
|
|
||||||
|
|
||||||
return bufctl->m_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtl_cache_bufctl_type * rtl_cache_hash_remove(
|
rtl_cache_bufctl_type * rtl_cache_hash_remove(
|
||||||
rtl_cache_type * cache,
|
rtl_cache_type * cache,
|
||||||
sal_uIntPtr addr
|
sal_uIntPtr addr
|
||||||
@@ -225,49 +210,6 @@ void rtl_cache_slab_destructor(void * obj, SAL_UNUSED_PARAMETER void *)
|
|||||||
(void) slab; // avoid warnings
|
(void) slab; // avoid warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_slab_lock released.
|
|
||||||
*/
|
|
||||||
rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache)
|
|
||||||
{
|
|
||||||
rtl_cache_slab_type * slab = nullptr;
|
|
||||||
void * addr;
|
|
||||||
sal_Size size;
|
|
||||||
|
|
||||||
size = cache->m_slab_size;
|
|
||||||
addr = rtl_arena_alloc (cache->m_source, &size);
|
|
||||||
if (SAL_LIKELY(addr))
|
|
||||||
{
|
|
||||||
assert(size >= cache->m_slab_size);
|
|
||||||
|
|
||||||
if (cache->m_features & RTL_CACHE_FEATURE_HASH)
|
|
||||||
{
|
|
||||||
/* allocate slab struct from slab cache */
|
|
||||||
assert(cache != gp_cache_slab_cache);
|
|
||||||
slab = static_cast<rtl_cache_slab_type*>(rtl_cache_alloc (gp_cache_slab_cache));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* construct embedded slab struct */
|
|
||||||
slab = RTL_CACHE_SLAB(addr, cache->m_slab_size);
|
|
||||||
(void) rtl_cache_slab_constructor (slab, nullptr);
|
|
||||||
}
|
|
||||||
if (SAL_LIKELY(slab))
|
|
||||||
{
|
|
||||||
slab->m_data = reinterpret_cast<sal_uIntPtr>(addr);
|
|
||||||
|
|
||||||
/* dynamic freelist initialization */
|
|
||||||
slab->m_bp = slab->m_data;
|
|
||||||
slab->m_sp = nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rtl_arena_free (cache->m_source, addr, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return slab;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@precond cache->m_slab_lock released.
|
@precond cache->m_slab_lock released.
|
||||||
*/
|
*/
|
||||||
@@ -312,115 +254,6 @@ void rtl_cache_slab_destroy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_slab_lock acquired.
|
|
||||||
*/
|
|
||||||
bool rtl_cache_slab_populate(rtl_cache_type * cache)
|
|
||||||
{
|
|
||||||
rtl_cache_slab_type * slab;
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock));
|
|
||||||
slab = rtl_cache_slab_create (cache);
|
|
||||||
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock));
|
|
||||||
if (slab)
|
|
||||||
{
|
|
||||||
/* update buffer start addr w/ current color */
|
|
||||||
slab->m_bp += cache->m_ncolor;
|
|
||||||
|
|
||||||
/* update color for next slab */
|
|
||||||
cache->m_ncolor += cache->m_type_align;
|
|
||||||
if (cache->m_ncolor > cache->m_ncolor_max)
|
|
||||||
cache->m_ncolor = 0;
|
|
||||||
|
|
||||||
/* update stats */
|
|
||||||
cache->m_slab_stats.m_mem_total += cache->m_slab_size;
|
|
||||||
|
|
||||||
/* insert onto 'free' queue */
|
|
||||||
QUEUE_INSERT_HEAD_NAMED(&(cache->m_free_head), slab, slab_);
|
|
||||||
}
|
|
||||||
return (slab != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Allocate a buffer from slab layer; used by magazine layer.
|
|
||||||
*/
|
|
||||||
void * rtl_cache_slab_alloc (rtl_cache_type * cache)
|
|
||||||
{
|
|
||||||
void * addr = nullptr;
|
|
||||||
rtl_cache_slab_type * head;
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock));
|
|
||||||
|
|
||||||
head = &(cache->m_free_head);
|
|
||||||
if (head->m_slab_next != head || rtl_cache_slab_populate (cache))
|
|
||||||
{
|
|
||||||
rtl_cache_slab_type * slab;
|
|
||||||
rtl_cache_bufctl_type * bufctl;
|
|
||||||
|
|
||||||
slab = head->m_slab_next;
|
|
||||||
assert(slab->m_ntypes < cache->m_ntypes);
|
|
||||||
|
|
||||||
if (!slab->m_sp)
|
|
||||||
{
|
|
||||||
/* initialize bufctl w/ current 'slab->m_bp' */
|
|
||||||
assert(slab->m_bp < slab->m_data + cache->m_ntypes * cache->m_type_size + cache->m_ncolor_max);
|
|
||||||
if (cache->m_features & RTL_CACHE_FEATURE_HASH)
|
|
||||||
{
|
|
||||||
/* allocate bufctl */
|
|
||||||
assert(cache != gp_cache_bufctl_cache);
|
|
||||||
bufctl = static_cast<rtl_cache_bufctl_type*>(rtl_cache_alloc (gp_cache_bufctl_cache));
|
|
||||||
if (!bufctl)
|
|
||||||
{
|
|
||||||
/* out of memory */
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bufctl->m_addr = slab->m_bp;
|
|
||||||
bufctl->m_slab = reinterpret_cast<sal_uIntPtr>(slab);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* embedded bufctl */
|
|
||||||
bufctl = reinterpret_cast<rtl_cache_bufctl_type*>(slab->m_bp);
|
|
||||||
}
|
|
||||||
bufctl->m_next = nullptr;
|
|
||||||
|
|
||||||
/* update 'slab->m_bp' to next free buffer */
|
|
||||||
slab->m_bp += cache->m_type_size;
|
|
||||||
|
|
||||||
/* assign bufctl to freelist */
|
|
||||||
slab->m_sp = bufctl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pop front */
|
|
||||||
bufctl = slab->m_sp;
|
|
||||||
slab->m_sp = bufctl->m_next;
|
|
||||||
|
|
||||||
/* increment usage, check for full slab */
|
|
||||||
if ((slab->m_ntypes += 1) == cache->m_ntypes)
|
|
||||||
{
|
|
||||||
/* remove from 'free' queue */
|
|
||||||
QUEUE_REMOVE_NAMED(slab, slab_);
|
|
||||||
|
|
||||||
/* insert onto 'used' queue (tail) */
|
|
||||||
QUEUE_INSERT_TAIL_NAMED(&(cache->m_used_head), slab, slab_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update stats */
|
|
||||||
cache->m_slab_stats.m_alloc += 1;
|
|
||||||
cache->m_slab_stats.m_mem_alloc += cache->m_type_size;
|
|
||||||
|
|
||||||
if (cache->m_features & RTL_CACHE_FEATURE_HASH)
|
|
||||||
addr = reinterpret_cast<void*>(rtl_cache_hash_insert (cache, bufctl));
|
|
||||||
else
|
|
||||||
addr = bufctl;
|
|
||||||
}
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock));
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return a buffer to slab layer; used by magazine layer.
|
Return a buffer to slab layer; used by magazine layer.
|
||||||
*/
|
*/
|
||||||
@@ -528,22 +361,6 @@ void rtl_cache_magazine_clear(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_depot_lock acquired.
|
|
||||||
*/
|
|
||||||
inline void rtl_cache_depot_enqueue(
|
|
||||||
rtl_cache_depot_type * depot,
|
|
||||||
rtl_cache_magazine_type * mag
|
|
||||||
)
|
|
||||||
{
|
|
||||||
/* enqueue empty magazine */
|
|
||||||
mag->m_mag_next = depot->m_mag_next;
|
|
||||||
depot->m_mag_next = mag;
|
|
||||||
|
|
||||||
/* update depot stats */
|
|
||||||
depot->m_mag_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@precond cache->m_depot_lock acquired.
|
@precond cache->m_depot_lock acquired.
|
||||||
*/
|
*/
|
||||||
@@ -571,77 +388,6 @@ inline rtl_cache_magazine_type * rtl_cache_depot_dequeue(
|
|||||||
return mag;
|
return mag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_depot_lock acquired.
|
|
||||||
*/
|
|
||||||
inline rtl_cache_magazine_type * rtl_cache_depot_exchange_alloc(
|
|
||||||
rtl_cache_type * cache,
|
|
||||||
rtl_cache_magazine_type * empty
|
|
||||||
)
|
|
||||||
{
|
|
||||||
rtl_cache_magazine_type * full;
|
|
||||||
|
|
||||||
assert(!empty || empty->m_mag_used == 0);
|
|
||||||
|
|
||||||
/* dequeue full magazine */
|
|
||||||
full = rtl_cache_depot_dequeue (&(cache->m_depot_full));
|
|
||||||
if (full && empty)
|
|
||||||
{
|
|
||||||
/* enqueue empty magazine */
|
|
||||||
rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!full || (full->m_mag_used > 0));
|
|
||||||
|
|
||||||
return full;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_depot_lock acquired.
|
|
||||||
*/
|
|
||||||
inline rtl_cache_magazine_type * rtl_cache_depot_exchange_free(
|
|
||||||
rtl_cache_type * cache,
|
|
||||||
rtl_cache_magazine_type * full
|
|
||||||
)
|
|
||||||
{
|
|
||||||
rtl_cache_magazine_type * empty;
|
|
||||||
|
|
||||||
assert(!full || (full->m_mag_used > 0));
|
|
||||||
|
|
||||||
/* dequeue empty magazine */
|
|
||||||
empty = rtl_cache_depot_dequeue (&(cache->m_depot_empty));
|
|
||||||
if (empty && full)
|
|
||||||
{
|
|
||||||
/* enqueue full magazine */
|
|
||||||
rtl_cache_depot_enqueue (&(cache->m_depot_full), full);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!empty || (empty->m_mag_used == 0));
|
|
||||||
|
|
||||||
return empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@precond cache->m_depot_lock acquired.
|
|
||||||
*/
|
|
||||||
bool rtl_cache_depot_populate(rtl_cache_type * cache)
|
|
||||||
{
|
|
||||||
rtl_cache_magazine_type * empty = nullptr;
|
|
||||||
|
|
||||||
if (cache->m_magazine_cache)
|
|
||||||
{
|
|
||||||
/* allocate new empty magazine */
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
|
|
||||||
empty = static_cast<rtl_cache_magazine_type*>(rtl_cache_alloc (cache->m_magazine_cache));
|
|
||||||
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock));
|
|
||||||
if (empty)
|
|
||||||
{
|
|
||||||
/* enqueue (new) empty magazine */
|
|
||||||
rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (empty != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtl_cache_constructor(void * obj)
|
void rtl_cache_constructor(void * obj)
|
||||||
{
|
{
|
||||||
@@ -991,73 +737,13 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C()
|
|||||||
if (!cache)
|
if (!cache)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (alloc_mode == AllocMode::SYSTEM)
|
obj = rtl_allocateMemory(cache->m_type_size);
|
||||||
|
if (obj && cache->m_constructor)
|
||||||
{
|
{
|
||||||
obj = rtl_allocateMemory(cache->m_type_size);
|
|
||||||
if (obj && cache->m_constructor)
|
|
||||||
{
|
|
||||||
if (!(cache->m_constructor)(obj, cache->m_userarg))
|
|
||||||
{
|
|
||||||
/* construction failure */
|
|
||||||
rtl_freeMemory(obj);
|
|
||||||
obj = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock));
|
|
||||||
if (SAL_LIKELY(cache->m_cpu_curr))
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
/* take object from magazine layer */
|
|
||||||
rtl_cache_magazine_type *curr, *prev, *temp;
|
|
||||||
|
|
||||||
curr = cache->m_cpu_curr;
|
|
||||||
if (curr && (curr->m_mag_used > 0))
|
|
||||||
{
|
|
||||||
obj = curr->m_objects[--curr->m_mag_used];
|
|
||||||
cache->m_cpu_stats.m_alloc += 1;
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
prev = cache->m_cpu_prev;
|
|
||||||
if (prev && (prev->m_mag_used > 0))
|
|
||||||
{
|
|
||||||
temp = cache->m_cpu_curr;
|
|
||||||
cache->m_cpu_curr = cache->m_cpu_prev;
|
|
||||||
cache->m_cpu_prev = temp;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = rtl_cache_depot_exchange_alloc (cache, prev);
|
|
||||||
if (temp)
|
|
||||||
{
|
|
||||||
cache->m_cpu_prev = cache->m_cpu_curr;
|
|
||||||
cache->m_cpu_curr = temp;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no full magazine: fall through to slab layer */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
|
|
||||||
|
|
||||||
/* alloc buffer from slab layer */
|
|
||||||
obj = rtl_cache_slab_alloc (cache);
|
|
||||||
if (obj && (cache->m_constructor))
|
|
||||||
{
|
|
||||||
/* construct object */
|
|
||||||
if (!(cache->m_constructor)(obj, cache->m_userarg))
|
if (!(cache->m_constructor)(obj, cache->m_userarg))
|
||||||
{
|
{
|
||||||
/* construction failure */
|
/* construction failure */
|
||||||
rtl_cache_slab_free (cache, obj);
|
rtl_freeMemory(obj);
|
||||||
obj = nullptr;
|
obj = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1071,73 +757,12 @@ void SAL_CALL rtl_cache_free(
|
|||||||
{
|
{
|
||||||
if (obj && cache)
|
if (obj && cache)
|
||||||
{
|
{
|
||||||
if (alloc_mode == AllocMode::SYSTEM)
|
|
||||||
{
|
|
||||||
if (cache->m_destructor)
|
|
||||||
{
|
|
||||||
/* destruct object */
|
|
||||||
(cache->m_destructor)(obj, cache->m_userarg);
|
|
||||||
}
|
|
||||||
rtl_freeMemory(obj);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock));
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
/* return object to magazine layer */
|
|
||||||
rtl_cache_magazine_type *curr, *prev, *temp;
|
|
||||||
|
|
||||||
curr = cache->m_cpu_curr;
|
|
||||||
if (curr && (curr->m_mag_used < curr->m_mag_size))
|
|
||||||
{
|
|
||||||
curr->m_objects[curr->m_mag_used++] = obj;
|
|
||||||
cache->m_cpu_stats.m_free += 1;
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
prev = cache->m_cpu_prev;
|
|
||||||
if (prev && (prev->m_mag_used == 0))
|
|
||||||
{
|
|
||||||
temp = cache->m_cpu_curr;
|
|
||||||
cache->m_cpu_curr = cache->m_cpu_prev;
|
|
||||||
cache->m_cpu_prev = temp;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = rtl_cache_depot_exchange_free (cache, prev);
|
|
||||||
if (temp)
|
|
||||||
{
|
|
||||||
cache->m_cpu_prev = cache->m_cpu_curr;
|
|
||||||
cache->m_cpu_curr = temp;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rtl_cache_depot_populate(cache))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no empty magazine: fall through to slab layer */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
|
|
||||||
|
|
||||||
/* no space for constructed object in magazine layer */
|
|
||||||
if (cache->m_destructor)
|
if (cache->m_destructor)
|
||||||
{
|
{
|
||||||
/* destruct object */
|
/* destruct object */
|
||||||
(cache->m_destructor)(obj, cache->m_userarg);
|
(cache->m_destructor)(obj, cache->m_userarg);
|
||||||
}
|
}
|
||||||
|
rtl_freeMemory(obj);
|
||||||
/* return buffer to slab layer */
|
|
||||||
rtl_cache_slab_free (cache, obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,28 +21,6 @@
|
|||||||
|
|
||||||
#include <rtllifecycle.h>
|
#include <rtllifecycle.h>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
struct rtlMemorySingleton
|
|
||||||
{
|
|
||||||
rtlMemorySingleton()
|
|
||||||
{
|
|
||||||
rtl_memory_init();
|
|
||||||
}
|
|
||||||
~rtlMemorySingleton()
|
|
||||||
{
|
|
||||||
rtl_memory_fini();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
class theMemorySingleton
|
|
||||||
: public rtl::Static<rtlMemorySingleton, theMemorySingleton>{};
|
|
||||||
}
|
|
||||||
|
|
||||||
void ensureMemorySingleton()
|
|
||||||
{
|
|
||||||
theMemorySingleton::get();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct rtlCacheSingleton
|
struct rtlCacheSingleton
|
||||||
|
@@ -30,239 +30,12 @@
|
|||||||
#include <rtllifecycle.h>
|
#include <rtllifecycle.h>
|
||||||
#include <oslmemory.h>
|
#include <oslmemory.h>
|
||||||
|
|
||||||
AllocMode alloc_mode = AllocMode::UNSET;
|
|
||||||
|
|
||||||
#if !defined(FORCE_SYSALLOC)
|
|
||||||
static void determine_alloc_mode()
|
|
||||||
{
|
|
||||||
assert(alloc_mode == AllocMode::UNSET);
|
|
||||||
alloc_mode = AllocMode::SYSTEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const sal_Size g_alloc_sizes[] =
|
|
||||||
{
|
|
||||||
/* powers of 2**(1/4) */
|
|
||||||
4 * 4, 6 * 4,
|
|
||||||
4 * 8, 5 * 8, 6 * 8, 7 * 8,
|
|
||||||
4 * 16, 5 * 16, 6 * 16, 7 * 16,
|
|
||||||
4 * 32, 5 * 32, 6 * 32, 7 * 32,
|
|
||||||
4 * 64, 5 * 64, 6 * 64, 7 * 64,
|
|
||||||
4 * 128, 5 * 128, 6 * 128, 7 * 128,
|
|
||||||
4 * 256, 5 * 256, 6 * 256, 7 * 256,
|
|
||||||
4 * 512, 5 * 512, 6 * 512, 7 * 512,
|
|
||||||
4 * 1024, 5 * 1024, 6 * 1024, 7 * 1024,
|
|
||||||
4 * 2048, 5 * 2048, 6 * 2048, 7 * 2048,
|
|
||||||
4 * 4096
|
|
||||||
};
|
|
||||||
|
|
||||||
#define RTL_MEMORY_CACHED_LIMIT 4 * 4096
|
|
||||||
#define RTL_MEMORY_CACHED_SIZES (SAL_N_ELEMENTS(g_alloc_sizes))
|
|
||||||
|
|
||||||
static rtl_cache_type * g_alloc_caches[RTL_MEMORY_CACHED_SIZES] =
|
|
||||||
{
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define RTL_MEMALIGN 8
|
|
||||||
#define RTL_MEMALIGN_SHIFT 3
|
|
||||||
|
|
||||||
static rtl_cache_type * g_alloc_table[RTL_MEMORY_CACHED_LIMIT >> RTL_MEMALIGN_SHIFT] =
|
|
||||||
{
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
static rtl_arena_type * gp_alloc_arena = nullptr;
|
|
||||||
|
|
||||||
void * rtl_allocateMemory_CUSTOM(sal_Size n) SAL_THROW_EXTERN_C()
|
|
||||||
{
|
|
||||||
void * p = nullptr;
|
|
||||||
if (n > 0)
|
|
||||||
{
|
|
||||||
char * addr;
|
|
||||||
sal_Size size = RTL_MEMORY_ALIGN(n + RTL_MEMALIGN, RTL_MEMALIGN);
|
|
||||||
|
|
||||||
assert(RTL_MEMALIGN >= sizeof(sal_Size));
|
|
||||||
if (n >= SAL_MAX_SIZE - (RTL_MEMALIGN + RTL_MEMALIGN - 1))
|
|
||||||
{
|
|
||||||
/* requested size too large for roundup alignment */
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
try_alloc:
|
|
||||||
if (size <= RTL_MEMORY_CACHED_LIMIT)
|
|
||||||
addr = static_cast<char*>(rtl_cache_alloc(g_alloc_table[(size - 1) >> RTL_MEMALIGN_SHIFT]));
|
|
||||||
else
|
|
||||||
addr = static_cast<char*>(rtl_arena_alloc (gp_alloc_arena, &size));
|
|
||||||
|
|
||||||
if (addr)
|
|
||||||
{
|
|
||||||
reinterpret_cast<sal_Size*>(addr)[0] = size;
|
|
||||||
p = addr + RTL_MEMALIGN;
|
|
||||||
}
|
|
||||||
else if (!gp_alloc_arena)
|
|
||||||
{
|
|
||||||
ensureMemorySingleton();
|
|
||||||
if (gp_alloc_arena)
|
|
||||||
{
|
|
||||||
/* try again */
|
|
||||||
goto try_alloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C()
|
|
||||||
{
|
|
||||||
if (p)
|
|
||||||
{
|
|
||||||
char * addr = static_cast<char*>(p) - RTL_MEMALIGN;
|
|
||||||
sal_Size size = reinterpret_cast<sal_Size*>(addr)[0];
|
|
||||||
|
|
||||||
if (size <= RTL_MEMORY_CACHED_LIMIT)
|
|
||||||
rtl_cache_free(g_alloc_table[(size - 1) >> RTL_MEMALIGN_SHIFT], addr);
|
|
||||||
else
|
|
||||||
rtl_arena_free (gp_alloc_arena, addr, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void * rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
|
|
||||||
{
|
|
||||||
if (n > 0)
|
|
||||||
{
|
|
||||||
if (p)
|
|
||||||
{
|
|
||||||
void * p_old = p;
|
|
||||||
sal_Size n_old = reinterpret_cast<sal_Size*>( static_cast<char*>(p) - RTL_MEMALIGN )[0] - RTL_MEMALIGN;
|
|
||||||
|
|
||||||
p = rtl_allocateMemory (n);
|
|
||||||
if (p)
|
|
||||||
{
|
|
||||||
memcpy (p, p_old, std::min(n, n_old));
|
|
||||||
rtl_freeMemory (p_old);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = rtl_allocateMemory (n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (p)
|
|
||||||
{
|
|
||||||
rtl_freeMemory (p);
|
|
||||||
p = nullptr;
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void rtl_memory_init()
|
|
||||||
{
|
|
||||||
#if !defined(FORCE_SYSALLOC)
|
|
||||||
{
|
|
||||||
/* global memory arena */
|
|
||||||
assert(!gp_alloc_arena);
|
|
||||||
|
|
||||||
gp_alloc_arena = rtl_arena_create (
|
|
||||||
"rtl_alloc_arena",
|
|
||||||
2048, /* quantum */
|
|
||||||
0, /* w/o quantum caching */
|
|
||||||
nullptr, /* default source */
|
|
||||||
rtl_arena_alloc,
|
|
||||||
rtl_arena_free,
|
|
||||||
0 /* flags */
|
|
||||||
);
|
|
||||||
assert(gp_alloc_arena);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
sal_Size size;
|
|
||||||
int i, n = RTL_MEMORY_CACHED_SIZES;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
char name[RTL_CACHE_NAME_LENGTH + 1];
|
|
||||||
(void) snprintf (name, sizeof(name), "rtl_alloc_%" SAL_PRIuUINTPTR, g_alloc_sizes[i]);
|
|
||||||
g_alloc_caches[i] = rtl_cache_create (name, g_alloc_sizes[i], 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
size = RTL_MEMALIGN;
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
while (size <= g_alloc_sizes[i])
|
|
||||||
{
|
|
||||||
g_alloc_table[(size - 1) >> RTL_MEMALIGN_SHIFT] = g_alloc_caches[i];
|
|
||||||
size += RTL_MEMALIGN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtl_memory_fini()
|
|
||||||
{
|
|
||||||
#if !defined(FORCE_SYSALLOC)
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
/* clear g_alloc_table */
|
|
||||||
// cppcheck-suppress sizeofwithsilentarraypointer
|
|
||||||
memset (g_alloc_table, 0, sizeof(g_alloc_table));
|
|
||||||
|
|
||||||
/* cleanup g_alloc_caches */
|
|
||||||
for (i = 0, n = RTL_MEMORY_CACHED_SIZES; i < n; i++)
|
|
||||||
{
|
|
||||||
if (g_alloc_caches[i])
|
|
||||||
{
|
|
||||||
rtl_cache_destroy (g_alloc_caches[i]);
|
|
||||||
g_alloc_caches[i] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cleanup gp_alloc_arena */
|
|
||||||
if (gp_alloc_arena)
|
|
||||||
{
|
|
||||||
rtl_arena_destroy (gp_alloc_arena);
|
|
||||||
gp_alloc_arena = nullptr;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void * rtl_allocateMemory_SYSTEM(sal_Size n)
|
|
||||||
{
|
|
||||||
return malloc (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtl_freeMemory_SYSTEM(void * p)
|
|
||||||
{
|
|
||||||
free (p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void * rtl_reallocateMemory_SYSTEM(void * p, sal_Size n)
|
|
||||||
{
|
|
||||||
return realloc (p, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* SAL_CALL rtl_allocateMemory(sal_Size n) SAL_THROW_EXTERN_C()
|
void* SAL_CALL rtl_allocateMemory(sal_Size n) SAL_THROW_EXTERN_C()
|
||||||
{
|
{
|
||||||
SAL_WARN_IF(
|
SAL_WARN_IF(
|
||||||
n >= SAL_MAX_INT32, "sal.rtl",
|
n >= SAL_MAX_INT32, "sal.rtl",
|
||||||
"suspicious massive alloc " << n);
|
"suspicious massive alloc " << n);
|
||||||
#if !defined(FORCE_SYSALLOC)
|
return malloc (n);
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (alloc_mode == AllocMode::CUSTOM)
|
|
||||||
{
|
|
||||||
return rtl_allocateMemory_CUSTOM(n);
|
|
||||||
}
|
|
||||||
if (alloc_mode == AllocMode::SYSTEM)
|
|
||||||
{
|
|
||||||
return rtl_allocateMemory_SYSTEM(n);
|
|
||||||
}
|
|
||||||
determine_alloc_mode();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return rtl_allocateMemory_SYSTEM(n);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SAL_CALL rtl_reallocateMemory(void * p, sal_Size n) SAL_THROW_EXTERN_C()
|
void* SAL_CALL rtl_reallocateMemory(void * p, sal_Size n) SAL_THROW_EXTERN_C()
|
||||||
@@ -270,44 +43,12 @@ void* SAL_CALL rtl_reallocateMemory(void * p, sal_Size n) SAL_THROW_EXTERN_C()
|
|||||||
SAL_WARN_IF(
|
SAL_WARN_IF(
|
||||||
n >= SAL_MAX_INT32, "sal.rtl",
|
n >= SAL_MAX_INT32, "sal.rtl",
|
||||||
"suspicious massive alloc " << n);
|
"suspicious massive alloc " << n);
|
||||||
#if !defined(FORCE_SYSALLOC)
|
return realloc (p, n);
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (alloc_mode == AllocMode::CUSTOM)
|
|
||||||
{
|
|
||||||
return rtl_reallocateMemory_CUSTOM(p,n);
|
|
||||||
}
|
|
||||||
if (alloc_mode == AllocMode::SYSTEM)
|
|
||||||
{
|
|
||||||
return rtl_reallocateMemory_SYSTEM(p,n);
|
|
||||||
}
|
|
||||||
determine_alloc_mode();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return rtl_reallocateMemory_SYSTEM(p,n);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAL_CALL rtl_freeMemory(void * p) SAL_THROW_EXTERN_C()
|
void SAL_CALL rtl_freeMemory(void * p) SAL_THROW_EXTERN_C()
|
||||||
{
|
{
|
||||||
#if !defined(FORCE_SYSALLOC)
|
free (p);
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (alloc_mode == AllocMode::CUSTOM)
|
|
||||||
{
|
|
||||||
rtl_freeMemory_CUSTOM(p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (alloc_mode == AllocMode::SYSTEM)
|
|
||||||
{
|
|
||||||
rtl_freeMemory_SYSTEM(p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
determine_alloc_mode();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
rtl_freeMemory_SYSTEM(p);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void * SAL_CALL rtl_allocateZeroMemory(sal_Size n) SAL_THROW_EXTERN_C()
|
void * SAL_CALL rtl_allocateZeroMemory(sal_Size n) SAL_THROW_EXTERN_C()
|
||||||
|
@@ -212,10 +212,6 @@ typedef CRITICAL_SECTION rtl_memory_lock_type;
|
|||||||
*/
|
*/
|
||||||
#define RTL_CACHE_FLAG_NOMAGAZINE (1 << 13) /* w/o magazine layer */
|
#define RTL_CACHE_FLAG_NOMAGAZINE (1 << 13) /* w/o magazine layer */
|
||||||
|
|
||||||
enum class AllocMode { CUSTOM, SYSTEM, UNSET };
|
|
||||||
|
|
||||||
extern AllocMode alloc_mode;
|
|
||||||
|
|
||||||
#endif // INCLUDED_SAL_RTL_ALLOC_IMPL_HXX
|
#endif // INCLUDED_SAL_RTL_ALLOC_IMPL_HXX
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user