mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
MoonchildProductions#1251 - Part 7: All the posix_m* memory-related stuff, gathered together.
https://bugzilla.mozilla.org/show_bug.cgi?id=1158445 https://bugzilla.mozilla.org/show_bug.cgi?id=963983 https://bugzilla.mozilla.org/show_bug.cgi?id=1542758 Solaris madvise and malign don't perfectly map to their POSIX counterparts, and some Linux versions (especially Android) don't define the POSIX counterparts at all, so options are limited. Ideally posix_madvise and posix_malign should be the safer and more portable options for all platforms.
This commit is contained in:
@@ -58,6 +58,9 @@ def jemalloc_os_define(jemalloc, target):
|
||||
return 'MOZ_MEMORY_DARWIN'
|
||||
if target.kernel in ('kFreeBSD', 'FreeBSD', 'NetBSD'):
|
||||
return 'MOZ_MEMORY_BSD'
|
||||
if target.kernel == 'SunOS':
|
||||
return 'MOZ_MEMORY_SOLARIS'
|
||||
|
||||
die('--enable-jemalloc is not supported on %s', target.kernel)
|
||||
|
||||
set_define(jemalloc_os_define, '1')
|
||||
|
||||
@@ -678,7 +678,11 @@ MarkPagesUnused(void* p, size_t size)
|
||||
return false;
|
||||
|
||||
MOZ_ASSERT(OffsetFromAligned(p, pageSize) == 0);
|
||||
int result = madvise(p, size, MADV_DONTNEED);
|
||||
#if defined(XP_SOLARIS)
|
||||
int result = posix_madvise(p, size, POSIX_MADV_DONTNEED);
|
||||
#else
|
||||
int result = madvise(p, size, MADV_DONTNEED);
|
||||
#endif
|
||||
return result != -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -413,8 +413,8 @@ void *_mmap(void *addr, size_t length, int prot, int flags,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MOZ_MEMORY_SOLARIS && defined(MAP_ALIGN) && !defined(JEMALLOC_NEVER_USES_MAP_ALIGN)
|
||||
#define JEMALLOC_USES_MAP_ALIGN /* Required on Solaris 10. Might improve performance elsewhere. */
|
||||
#if defined(MOZ_MEMORY_SOLARIS) && defined(MAP_ALIGN) && !defined(JEMALLOC_NEVER_USES_MAP_ALIGN)
|
||||
#define JEMALLOC_USES_MAP_ALIGN /* Required on Solaris 10. Might improve performance elsewhere. */
|
||||
#endif
|
||||
|
||||
#ifndef __DECONST
|
||||
@@ -1043,7 +1043,7 @@ static const bool config_recycle = false;
|
||||
* will abort.
|
||||
* Platform specific page size conditions copied from js/public/HeapAPI.h
|
||||
*/
|
||||
#if (defined(__FreeBSD__)) && \
|
||||
#if (defined(SOLARIS) || defined(__FreeBSD__)) && \
|
||||
(defined(__sparc) || defined(__sparcv9) || defined(__ia64))
|
||||
#define pagesize_2pow ((size_t) 13)
|
||||
#elif defined(__powerpc64__)
|
||||
@@ -2651,8 +2651,13 @@ pages_purge(void *addr, size_t length)
|
||||
# define JEMALLOC_MADV_PURGE MADV_FREE
|
||||
# define JEMALLOC_MADV_ZEROS false
|
||||
# endif
|
||||
#ifdef MOZ_MEMORY_SOLARIS
|
||||
int err = posix_madvise(addr, length, JEMALLOC_MADV_PURGE);
|
||||
unzeroed = (JEMALLOC_MADV_ZEROS == false || err != 0);
|
||||
#else
|
||||
int err = madvise(addr, length, JEMALLOC_MADV_PURGE);
|
||||
unzeroed = (JEMALLOC_MADV_ZEROS == false || err != 0);
|
||||
#endif
|
||||
# undef JEMALLOC_MADV_PURGE
|
||||
# undef JEMALLOC_MADV_ZEROS
|
||||
# endif
|
||||
@@ -3608,9 +3613,14 @@ arena_purge(arena_t *arena, bool all)
|
||||
#endif
|
||||
|
||||
#ifndef MALLOC_DECOMMIT
|
||||
#ifdef MOZ_MEMORY_SOLARIS
|
||||
posix_madvise((void*)((uintptr_t)chunk + (i << pagesize_2pow)),
|
||||
(npages << pagesize_2pow),MADV_FREE);
|
||||
#else
|
||||
madvise((void *)((uintptr_t)chunk + (i <<
|
||||
pagesize_2pow)), (npages << pagesize_2pow),
|
||||
MADV_FREE);
|
||||
#endif
|
||||
# ifdef MALLOC_DOUBLE_PURGE
|
||||
madvised = true;
|
||||
# endif
|
||||
@@ -5136,7 +5146,7 @@ malloc_ncpus(void)
|
||||
static inline unsigned
|
||||
malloc_ncpus(void)
|
||||
{
|
||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||
}
|
||||
#elif (defined(MOZ_MEMORY_WINDOWS))
|
||||
static inline unsigned
|
||||
|
||||
@@ -129,7 +129,11 @@ ReleaseRegion(void* aRegion, uintptr_t aSize)
|
||||
static bool
|
||||
ProbeRegion(uintptr_t aRegion, uintptr_t aSize)
|
||||
{
|
||||
#ifdef XP_SOLARIS
|
||||
if (posix_madvise(reinterpret_cast<void*>(aRegion), aSize, POSIX_MADV_NORMAL)) {
|
||||
#else
|
||||
if (madvise(reinterpret_cast<void*>(aRegion), aSize, MADV_NORMAL)) {
|
||||
#endif
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -266,7 +266,11 @@ ReleaseRegion(void* aPage)
|
||||
static bool
|
||||
ProbeRegion(uintptr_t aPage)
|
||||
{
|
||||
#ifdef XP_SOLARIS
|
||||
return !!posix_madvise(reinterpret_cast<void*>(aPage), PageSize(), POSIX_MADV_NORMAL);
|
||||
#else
|
||||
return !!madvise(reinterpret_cast<void*>(aPage), PageSize(), MADV_NORMAL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -688,7 +688,9 @@ MOZ_WIN_MEM_TRY_BEGIN
|
||||
// Success means optimized jar layout from bug 559961 is in effect
|
||||
uint32_t readaheadLength = xtolong(startp);
|
||||
if (readaheadLength) {
|
||||
#if defined(XP_UNIX)
|
||||
#if defined(XP_SOLARIS)
|
||||
posix_madvise(const_cast<uint8_t*>(startp), readaheadLength, POSIX_MADV_WILLNEED);
|
||||
#elif defined(XP_UNIX)
|
||||
madvise(const_cast<uint8_t*>(startp), readaheadLength, MADV_WILLNEED);
|
||||
#elif defined(XP_WIN)
|
||||
if (aFd) {
|
||||
|
||||
Reference in New Issue
Block a user