Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: src/heap/spaces.cc

Issue 2032393002: [heap] Uncommit unused large object page memory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/spaces.h" 5 #include "src/heap/spaces.h"
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/base/platform/semaphore.h" 9 #include "src/base/platform/semaphore.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // TODO(gc) make code_range part of memory allocator? 412 // TODO(gc) make code_range part of memory allocator?
413 // Code which is part of the code-range does not have its own VirtualMemory. 413 // Code which is part of the code-range does not have its own VirtualMemory.
414 DCHECK(code_range() == NULL || 414 DCHECK(code_range() == NULL ||
415 !code_range()->contains(static_cast<Address>(reservation->address()))); 415 !code_range()->contains(static_cast<Address>(reservation->address())));
416 DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid() || 416 DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid() ||
417 reservation->size() <= Page::kPageSize); 417 reservation->size() <= Page::kPageSize);
418 418
419 reservation->Release(); 419 reservation->Release();
420 } 420 }
421 421
422 void MemoryAllocator::PartialFreeMemory(base::VirtualMemory* reservation,
423 Executability executable,
ulan 2016/06/06 13:44:22 Maybe completely disallow the function for executa
Hannes Payer (out of office) 2016/06/06 14:42:44 I added checks to the lower level functions.
424 Address free_start, size_t size) {
425 // TODO(gc) make code_range part of memory allocator?
426 // Code which is part of the code-range does not have its own VirtualMemory.
427 DCHECK(code_range() == NULL ||
428 !code_range()->contains(static_cast<Address>(reservation->address())));
429 DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid() ||
430 reservation->size() <= Page::kPageSize);
431
432 reservation->ReleasePartial(free_start, size);
433 }
422 434
423 void MemoryAllocator::FreeMemory(Address base, size_t size, 435 void MemoryAllocator::FreeMemory(Address base, size_t size,
424 Executability executable) { 436 Executability executable) {
425 // TODO(gc) make code_range part of memory allocator? 437 // TODO(gc) make code_range part of memory allocator?
426 if (code_range() != NULL && 438 if (code_range() != NULL &&
427 code_range()->contains(static_cast<Address>(base))) { 439 code_range()->contains(static_cast<Address>(base))) {
428 DCHECK(executable == EXECUTABLE); 440 DCHECK(executable == EXECUTABLE);
429 code_range()->FreeRawMemory(base, size); 441 code_range()->FreeRawMemory(base, size);
430 } else { 442 } else {
431 DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid()); 443 DCHECK(executable == NOT_EXECUTABLE || !code_range()->valid());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 CodeRange* code_range = heap_->memory_allocator()->code_range(); 589 CodeRange* code_range = heap_->memory_allocator()->code_range();
578 DCHECK(code_range->valid() && IsFlagSet(IS_EXECUTABLE)); 590 DCHECK(code_range->valid() && IsFlagSet(IS_EXECUTABLE));
579 if (!code_range->UncommitRawMemory(start, length)) return false; 591 if (!code_range->UncommitRawMemory(start, length)) return false;
580 } 592 }
581 } 593 }
582 594
583 area_end_ = area_start_ + requested; 595 area_end_ = area_start_ + requested;
584 return true; 596 return true;
585 } 597 }
586 598
599 size_t MemoryChunk::CommittedPhysicalMemory() {
600 if (!base::VirtualMemory::HasLazyCommits() || owner()->identity() == LO_SPACE)
601 return size();
602 return high_water_mark_.Value();
603 }
587 604
588 void MemoryChunk::InsertAfter(MemoryChunk* other) { 605 void MemoryChunk::InsertAfter(MemoryChunk* other) {
589 MemoryChunk* other_next = other->next_chunk(); 606 MemoryChunk* other_next = other->next_chunk();
590 607
591 set_next_chunk(other_next); 608 set_next_chunk(other_next);
592 set_prev_chunk(other); 609 set_prev_chunk(other);
593 other_next->set_prev_chunk(this); 610 other_next->set_prev_chunk(this);
594 other->set_next_chunk(this); 611 other->set_next_chunk(this);
595 } 612 }
596 613
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 return MemoryChunk::Initialize(heap, base, chunk_size, area_start, area_end, 761 return MemoryChunk::Initialize(heap, base, chunk_size, area_start, area_end,
745 executable, owner, &reservation); 762 executable, owner, &reservation);
746 } 763 }
747 764
748 765
749 void Page::ResetFreeListStatistics() { 766 void Page::ResetFreeListStatistics() {
750 wasted_memory_ = 0; 767 wasted_memory_ = 0;
751 available_in_free_list_ = 0; 768 available_in_free_list_ = 0;
752 } 769 }
753 770
771 void MemoryAllocator::PartialFreeMemory(MemoryChunk* chunk,
772 Address start_free) {
773 intptr_t size;
774 base::VirtualMemory* reservation = chunk->reserved_memory();
775 if (reservation->IsReserved()) {
776 size = static_cast<intptr_t>(reservation->size());
777 } else {
778 size = static_cast<intptr_t>(chunk->size());
779 }
780
781 size_t to_free_size = size - (start_free - chunk->address());
782
783 DCHECK(size_.Value() >= static_cast<intptr_t>(to_free_size));
784 size_.Increment(-static_cast<intptr_t>(to_free_size));
785 isolate_->counters()->memory_allocated()->Decrement(
786 static_cast<int>(to_free_size));
787 chunk->set_size(size - to_free_size);
788
789 if (chunk->executable() == EXECUTABLE) {
790 DCHECK(size_executable_.Value() >= static_cast<intptr_t>(to_free_size));
791 size_executable_.Increment(-static_cast<intptr_t>(to_free_size));
792 }
793
794 if (reservation->IsReserved()) {
795 PartialFreeMemory(reservation, chunk->executable(), start_free,
796 to_free_size);
797 } else {
798 FreeMemory(start_free, to_free_size, chunk->executable());
799 }
800 }
801
754 void MemoryAllocator::PreFreeMemory(MemoryChunk* chunk) { 802 void MemoryAllocator::PreFreeMemory(MemoryChunk* chunk) {
755 DCHECK(!chunk->IsFlagSet(MemoryChunk::PRE_FREED)); 803 DCHECK(!chunk->IsFlagSet(MemoryChunk::PRE_FREED));
756 LOG(isolate_, DeleteEvent("MemoryChunk", chunk)); 804 LOG(isolate_, DeleteEvent("MemoryChunk", chunk));
757 805
758 isolate_->heap()->RememberUnmappedPage(reinterpret_cast<Address>(chunk), 806 isolate_->heap()->RememberUnmappedPage(reinterpret_cast<Address>(chunk),
759 chunk->IsEvacuationCandidate()); 807 chunk->IsEvacuationCandidate());
760 808
761 intptr_t size; 809 intptr_t size;
762 base::VirtualMemory* reservation = chunk->reserved_memory(); 810 base::VirtualMemory* reservation = chunk->reserved_memory();
763 if (reservation->IsReserved()) { 811 if (reservation->IsReserved()) {
(...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 #endif 2925 #endif
2878 } 2926 }
2879 2927
2880 // ----------------------------------------------------------------------------- 2928 // -----------------------------------------------------------------------------
2881 // MapSpace implementation 2929 // MapSpace implementation
2882 2930
2883 #ifdef VERIFY_HEAP 2931 #ifdef VERIFY_HEAP
2884 void MapSpace::VerifyObject(HeapObject* object) { CHECK(object->IsMap()); } 2932 void MapSpace::VerifyObject(HeapObject* object) { CHECK(object->IsMap()); }
2885 #endif 2933 #endif
2886 2934
2935 Address LargePage::GetAddressToShrink() {
2936 HeapObject* object = GetObject();
2937 CodeRange* code_range = heap()->memory_allocator()->code_range();
2938 if (code_range != NULL && code_range->contains(object->address())) {
2939 return 0;
2940 }
2941 size_t used_size = RoundUp((object->address() - address()) + object->Size(),
2942 base::OS::CommitPageSize());
2943 if (used_size < CommittedPhysicalMemory()) {
2944 return address() + used_size;
2945 }
2946 return 0;
2947 }
2887 2948
2888 // ----------------------------------------------------------------------------- 2949 // -----------------------------------------------------------------------------
2889 // LargeObjectIterator 2950 // LargeObjectIterator
2890 2951
2891 LargeObjectIterator::LargeObjectIterator(LargeObjectSpace* space) { 2952 LargeObjectIterator::LargeObjectIterator(LargeObjectSpace* space) {
2892 current_ = space->first_page_; 2953 current_ = space->first_page_;
2893 } 2954 }
2894 2955
2895 2956
2896 HeapObject* LargeObjectIterator::Next() { 2957 HeapObject* LargeObjectIterator::Next() {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3027 HeapObject* object = current->GetObject(); 3088 HeapObject* object = current->GetObject();
3028 MarkBit mark_bit = Marking::MarkBitFrom(object); 3089 MarkBit mark_bit = Marking::MarkBitFrom(object);
3029 DCHECK(Marking::IsBlack(mark_bit)); 3090 DCHECK(Marking::IsBlack(mark_bit));
3030 Marking::BlackToWhite(mark_bit); 3091 Marking::BlackToWhite(mark_bit);
3031 Page::FromAddress(object->address())->ResetProgressBar(); 3092 Page::FromAddress(object->address())->ResetProgressBar();
3032 Page::FromAddress(object->address())->ResetLiveBytes(); 3093 Page::FromAddress(object->address())->ResetLiveBytes();
3033 current = current->next_page(); 3094 current = current->next_page();
3034 } 3095 }
3035 } 3096 }
3036 3097
3037
3038 void LargeObjectSpace::FreeUnmarkedObjects() { 3098 void LargeObjectSpace::FreeUnmarkedObjects() {
3039 LargePage* previous = NULL; 3099 LargePage* previous = NULL;
3040 LargePage* current = first_page_; 3100 LargePage* current = first_page_;
3041 while (current != NULL) { 3101 while (current != NULL) {
3042 HeapObject* object = current->GetObject(); 3102 HeapObject* object = current->GetObject();
3043 MarkBit mark_bit = Marking::MarkBitFrom(object); 3103 MarkBit mark_bit = Marking::MarkBitFrom(object);
3044 DCHECK(!Marking::IsGrey(mark_bit)); 3104 DCHECK(!Marking::IsGrey(mark_bit));
3045 if (Marking::IsBlack(mark_bit)) { 3105 if (Marking::IsBlack(mark_bit)) {
3106 Address free_start;
3107 if ((free_start = current->GetAddressToShrink()) != 0) {
3108 // TODO(hpayer): Perform partial free concurrently.
3109 heap()->memory_allocator()->PartialFreeMemory(current, free_start);
3110 }
3046 previous = current; 3111 previous = current;
3047 current = current->next_page(); 3112 current = current->next_page();
3048 } else { 3113 } else {
3049 LargePage* page = current; 3114 LargePage* page = current;
3050 // Cut the chunk out from the chunk list. 3115 // Cut the chunk out from the chunk list.
3051 current = current->next_page(); 3116 current = current->next_page();
3052 if (previous == NULL) { 3117 if (previous == NULL) {
3053 first_page_ = current; 3118 first_page_ = current;
3054 } else { 3119 } else {
3055 previous->set_next_page(current); 3120 previous->set_next_page(current);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 object->ShortPrint(); 3263 object->ShortPrint();
3199 PrintF("\n"); 3264 PrintF("\n");
3200 } 3265 }
3201 printf(" --------------------------------------\n"); 3266 printf(" --------------------------------------\n");
3202 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3267 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3203 } 3268 }
3204 3269
3205 #endif // DEBUG 3270 #endif // DEBUG
3206 } // namespace internal 3271 } // namespace internal
3207 } // namespace v8 3272 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698