Changeset 192595 in webkit


Ignore:
Timestamp:
Nov 18, 2015, 3:48:48 PM (10 years ago)
Author:
akling@apple.com
Message:

ResourceUsageOverlay should have better accounting for reclaimable memory.
<https://webkit.org/b/151407>

Reviewed by Anders Carlsson.

Add code to inspect the purgeable state of VM regions when traversing the
web process VM map, and track reclaimable regions of memory separately.

Memory categories that have some amount of reclaimable memory are now
displayed with the reclaimable amount in brackets, e.g "123.45 MB [56.78MB]"

  • page/ResourceUsageOverlay.h:
  • page/cocoa/ResourceUsageOverlayCocoa.mm:

(WebCore::ResourceUsageOverlay::platformDraw):
(WebCore::TagInfo::TagInfo):
(WebCore::pagesPerVMTag):
(WebCore::runSamplerThread):
(WebCore::dirtyPagesPerVMTag): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r192592 r192595  
     12015-11-18  Andreas Kling  <akling@apple.com>
     2
     3        ResourceUsageOverlay should have better accounting for reclaimable memory.
     4        <https://webkit.org/b/151407>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Add code to inspect the purgeable state of VM regions when traversing the
     9        web process VM map, and track reclaimable regions of memory separately.
     10
     11        Memory categories that have some amount of reclaimable memory are now
     12        displayed with the reclaimable amount in brackets, e.g "123.45 MB [56.78MB]"
     13
     14        * page/ResourceUsageOverlay.h:
     15        * page/cocoa/ResourceUsageOverlayCocoa.mm:
     16        (WebCore::ResourceUsageOverlay::platformDraw):
     17        (WebCore::TagInfo::TagInfo):
     18        (WebCore::pagesPerVMTag):
     19        (WebCore::runSamplerThread):
     20        (WebCore::dirtyPagesPerVMTag): Deleted.
     21
    1222015-11-18  Joseph Pecoraro  <pecoraro@apple.com>
    223
  • trunk/Source/WebCore/page/ResourceUsageOverlay.h

    r192056 r192595  
    8282#endif
    8383
    84     static const int normalWidth = 550;
     84    static const int normalWidth = 570;
    8585    static const int normalHeight = 130;
    8686};
  • trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm

    r192056 r192595  
    147147    RetainPtr<CGColorRef> color;
    148148    RingBuffer<size_t> history;
     149    RingBuffer<size_t> reclaimableHistory;
    149150    bool isSubcategory { false };
    150151    unsigned type { MemoryCategory::NumberOfCategories };
     
    412413    float y = 50;
    413414    for (auto& category : data.categories) {
     415        String label = String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(category.history.last()).ascii().data());
     416        size_t reclaimable = category.reclaimableHistory.last();
     417        if (reclaimable)
     418            label = label + String::format(" [%s]", formatByteNumber(reclaimable).ascii().data());
     419
    414420        // FIXME: Show size/capacity of GC heap.
    415         showText(context, 10, y, category.color.get(), String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(category.history.last()).ascii().data()));
     421        showText(context, 10, y, category.color.get(), label);
    416422        y += 10;
    417423    }
     
    425431}
    426432
    427 static std::array<size_t, 256> dirtyPagesPerVMTag()
    428 {
    429     std::array<size_t, 256> dirty;
    430     dirty.fill(0);
     433struct TagInfo {
     434    TagInfo() { }
     435    size_t dirty { 0 };
     436    size_t reclaimable { 0 };
     437};
     438
     439static std::array<TagInfo, 256> pagesPerVMTag()
     440{
     441    std::array<TagInfo, 256> tags;
    431442    task_t task = mach_task_self();
    432443    mach_vm_size_t size;
     
    435446    mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
    436447    for (mach_vm_address_t addr = 0; ; addr += size) {
     448        int purgeableState;
     449        if (mach_vm_purgable_control(task, addr, VM_PURGABLE_GET_STATE, &purgeableState) != KERN_SUCCESS)
     450            purgeableState = VM_PURGABLE_DENY;
     451
    437452        kern_return_t kr = mach_vm_region_recurse(task, &addr, &size, &depth, (vm_region_info_t)&info, &count);
    438453        if (kr != KERN_SUCCESS)
    439454            break;
    440         dirty[info.user_tag] += info.pages_dirtied;
    441     }
    442     return dirty;
     455
     456        if (purgeableState == VM_PURGABLE_VOLATILE) {
     457            tags[info.user_tag].reclaimable += info.pages_resident;
     458            continue;
     459        }
     460
     461        if (purgeableState == VM_PURGABLE_EMPTY) {
     462            static size_t vmPageSize = getpagesize();
     463            tags[info.user_tag].reclaimable += size / vmPageSize;
     464            continue;
     465        }
     466
     467        bool anonymous = !info.external_pager;
     468        if (anonymous) {
     469            tags[info.user_tag].dirty += info.pages_resident - info.pages_reusable;
     470            tags[info.user_tag].reclaimable += info.pages_reusable;
     471        } else
     472            tags[info.user_tag].dirty += info.pages_dirtied;
     473    }
     474
     475    return tags;
    443476}
    444477
     
    505538    while (1) {
    506539        float cpu = cpuUsage();
    507         auto dirtyPages = dirtyPagesPerVMTag();
     540        auto tags = pagesPerVMTag();
    508541        Vector<CALayer *, 8> layers;
    509542
     
    512545            data.cpuHistory.append(cpu);
    513546
    514             std::array<size_t, MemoryCategory::NumberOfCategories> dirtyPagesPerCategory;
    515             dirtyPagesPerCategory.fill(0);
     547            std::array<TagInfo, MemoryCategory::NumberOfCategories> pagesPerCategory;
    516548
    517549            size_t totalDirtyPages = 0;
    518550            for (unsigned i = 0; i < 256; ++i) {
    519                 dirtyPagesPerCategory[categoryForVMTag(i)] += dirtyPages[i];
    520                 totalDirtyPages += dirtyPages[i];
     551                pagesPerCategory[categoryForVMTag(i)].dirty += tags[i].dirty;
     552                pagesPerCategory[categoryForVMTag(i)].reclaimable += tags[i].reclaimable;
     553                totalDirtyPages += tags[i].dirty;
    521554            }
    522555
     
    524557                if (category.isSubcategory) // Only do automatic tallying for top-level categories.
    525558                    continue;
    526                 category.history.append(dirtyPagesPerCategory[category.type] * vmPageSize);
     559                category.history.append(pagesPerCategory[category.type].dirty * vmPageSize);
     560                category.reclaimableHistory.append(pagesPerCategory[category.type].reclaimable * vmPageSize);
    527561            }
    528562            data.totalDirty.append(totalDirtyPages * vmPageSize);
Note: See TracChangeset for help on using the changeset viewer.