Ignore:
Timestamp:
Mar 12, 2009, 8:33:27 PM (16 years ago)
Author:
[email protected]
Message:

<rdar://problem/6548446> TCMalloc_SystemRelease should use madvise rather than re-mmaping span of pages

  • wtf/FastMalloc.cpp:

(WTF::mergeDecommittedStates): If either of the spans has been released to the system, release the other
span as well so that the flag in the merged span is accurate.

  • wtf/Platform.h:
  • wtf/TCSystemAlloc.cpp: Track decommitted spans when using MADV_FREE_REUSABLE / MADV_FREE_REUSE.

(TCMalloc_SystemRelease): Use madvise with MADV_FREE_REUSABLE when it is available.
(TCMalloc_SystemCommit): Use madvise with MADV_FREE_REUSE when it is available.

  • wtf/TCSystemAlloc.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp

    r39809 r41660  
    382382}
    383383
     384#if HAVE(MADV_FREE_REUSE)
     385
    384386void TCMalloc_SystemRelease(void* start, size_t length)
    385387{
    386 #if HAVE(MADV_DONTNEED)
     388    while (madvise(start, length, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
     389}
     390
     391#elif HAVE(MADV_DONTNEED)
     392
     393void TCMalloc_SystemRelease(void* start, size_t length)
     394{
    387395  if (FLAGS_malloc_devmem_start) {
    388396    // It's not safe to use MADV_DONTNEED if we've been mapping
     
    415423      // NOP
    416424    }
    417     return;
    418   }
    419 #endif
    420 
    421 #if HAVE(MMAP)
     425  }
     426}
     427
     428#elif HAVE(MMAP)
     429
     430void TCMalloc_SystemRelease(void* start, size_t length)
     431{
    422432  void* newAddress = mmap(start, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
    423433  // If the mmap failed then that's ok, we just won't return the memory to the system.
    424434  ASSERT_UNUSED(newAddress, newAddress == start || newAddress == reinterpret_cast<void*>(MAP_FAILED));
    425   return;
    426 #endif
    427 
    428 #if !HAVE(MADV_DONTNEED) && !HAVE(MMAP)
    429   UNUSED_PARAM(start);
    430   UNUSED_PARAM(length);
    431 #endif
    432 }
    433 
    434 #if HAVE(VIRTUALALLOC)
     435}
     436
     437#else
     438
     439// Platforms that don't support returning memory use an empty inline version of TCMalloc_SystemRelease
     440// declared in TCSystemAlloc.h
     441
     442#endif
     443
     444#if HAVE(MADV_FREE_REUSE)
     445
     446void TCMalloc_SystemCommit(void* start, size_t length)
     447{
     448    while (madvise(start, length, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
     449}
     450
     451#elif HAVE(VIRTUALALLOC)
     452
    435453void TCMalloc_SystemCommit(void*, size_t)
    436454{
    437455}
    438 #endif
     456
     457#else
     458
     459// Platforms that don't need to explicitly commit memory use an empty inline version of TCMalloc_SystemCommit
     460// declared in TCSystemAlloc.h
     461
     462#endif
Note: See TracChangeset for help on using the changeset viewer.