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

Side by Side Diff: src/mark-compact.cc

Issue 10629004: Adapt fragmentation heuristics for over reserved pages. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-alloc.cc » ('j') | test/cctest/test-heap.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 return static_cast<int>(ratio - ratio_threshold); 494 return static_cast<int>(ratio - ratio_threshold);
495 } 495 }
496 496
497 497
498 void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) { 498 void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) {
499 ASSERT(space->identity() == OLD_POINTER_SPACE || 499 ASSERT(space->identity() == OLD_POINTER_SPACE ||
500 space->identity() == OLD_DATA_SPACE || 500 space->identity() == OLD_DATA_SPACE ||
501 space->identity() == CODE_SPACE); 501 space->identity() == CODE_SPACE);
502 502
503 const int kMaxMaxEvacuationCandidates = 1000;
503 int number_of_pages = space->CountTotalPages(); 504 int number_of_pages = space->CountTotalPages();
504 505 int max_evacuation_candidates =
505 const int kMaxMaxEvacuationCandidates = 1000; 506 static_cast<int>(sqrt(static_cast<double>(number_of_pages / 2)) + 1);
506 int max_evacuation_candidates = Min(
507 kMaxMaxEvacuationCandidates,
508 static_cast<int>(sqrt(static_cast<double>(number_of_pages / 2)) + 1));
509 507
510 if (FLAG_stress_compaction || FLAG_always_compact) { 508 if (FLAG_stress_compaction || FLAG_always_compact) {
511 max_evacuation_candidates = kMaxMaxEvacuationCandidates; 509 max_evacuation_candidates = kMaxMaxEvacuationCandidates;
512 } 510 }
513 511
514 class Candidate { 512 class Candidate {
515 public: 513 public:
516 Candidate() : fragmentation_(0), page_(NULL) { } 514 Candidate() : fragmentation_(0), page_(NULL) { }
517 Candidate(int f, Page* p) : fragmentation_(f), page_(p) { } 515 Candidate(int f, Page* p) : fragmentation_(f), page_(p) { }
518 516
519 int fragmentation() { return fragmentation_; } 517 int fragmentation() { return fragmentation_; }
520 Page* page() { return page_; } 518 Page* page() { return page_; }
521 519
522 private: 520 private:
523 int fragmentation_; 521 int fragmentation_;
524 Page* page_; 522 Page* page_;
525 }; 523 };
526 524
527 enum CompactionMode { 525 enum CompactionMode {
528 COMPACT_FREE_LISTS, 526 COMPACT_FREE_LISTS,
529 REDUCE_MEMORY_FOOTPRINT 527 REDUCE_MEMORY_FOOTPRINT
530 }; 528 };
531 529
532 CompactionMode mode = COMPACT_FREE_LISTS; 530 CompactionMode mode = COMPACT_FREE_LISTS;
533 531
534 intptr_t reserved = number_of_pages * space->AreaSize(); 532 intptr_t reserved = number_of_pages * space->AreaSize();
535 intptr_t over_reserved = reserved - space->SizeOfObjects(); 533 intptr_t over_reserved = reserved - space->SizeOfObjects();
536 static const intptr_t kFreenessThreshold = 50; 534 intptr_t freeness_threshold = 100;
537 535
538 if (over_reserved >= 2 * space->AreaSize() && 536 if (over_reserved >= 2 * space->AreaSize()) {
539 reduce_memory_footprint_) {
540 mode = REDUCE_MEMORY_FOOTPRINT;
541 537
542 // We expect that empty pages are easier to compact so slightly bump the 538 // If reduction of memory footprint was requested, we are aggressive
543 // limit. 539 // about choosing pages to free. We expect that halve empty pages
Erik Corry 2012/06/22 08:52:54 halve empty -> half-empty
Michael Starzinger 2012/06/22 09:14:23 Done.
544 max_evacuation_candidates += 2; 540 // are easier to compact so slightly bump the limit.
541 if (reduce_memory_footprint_) {
542 mode = REDUCE_MEMORY_FOOTPRINT;
543 freeness_threshold = 50;
544 max_evacuation_candidates += 2;
545 }
545 546
546 if (FLAG_trace_fragmentation) { 547 // If over-usage is very high (more than a third of the space), we
547 PrintF("Estimated over reserved memory: %.1f MB (setting threshold %d)\n", 548 // try to free all mostly empty pages. We expect that empty pages
Erik Corry 2012/06/22 08:52:54 that empty pages -> that almost empty pages ?
Michael Starzinger 2012/06/22 09:14:23 Done.
549 // are even easier to compact so bump the limit even more.
550 if (over_reserved > reserved / 3) {
551 mode = REDUCE_MEMORY_FOOTPRINT;
552 freeness_threshold = 80;
Erik Corry 2012/06/22 08:52:54 I think we shouldn't set this so high. We might h
Michael Starzinger 2012/06/22 09:14:23 Done. Reverted it back to a constant of 50 like be
553 max_evacuation_candidates *= 2;
554 }
555
556 if (FLAG_trace_fragmentation && mode == REDUCE_MEMORY_FOOTPRINT) {
557 PrintF("Estimated over reserved memory: %.1f / %.1f MB (threshold %d)\n",
548 static_cast<double>(over_reserved) / MB, 558 static_cast<double>(over_reserved) / MB,
549 static_cast<int>(kFreenessThreshold)); 559 static_cast<double>(reserved) / MB,
560 static_cast<int>(freeness_threshold));
550 } 561 }
551 } 562 }
552 563
553 intptr_t estimated_release = 0; 564 intptr_t estimated_release = 0;
554 565
555 Candidate candidates[kMaxMaxEvacuationCandidates]; 566 Candidate candidates[kMaxMaxEvacuationCandidates];
556 567
568 max_evacuation_candidates =
569 Min(kMaxMaxEvacuationCandidates, max_evacuation_candidates);
570
557 int count = 0; 571 int count = 0;
558 int fragmentation = 0; 572 int fragmentation = 0;
559 Candidate* least = NULL; 573 Candidate* least = NULL;
560 574
561 PageIterator it(space); 575 PageIterator it(space);
562 if (it.has_next()) it.next(); // Never compact the first page. 576 if (it.has_next()) it.next(); // Never compact the first page.
563 577
564 while (it.has_next()) { 578 while (it.has_next()) {
565 Page* p = it.next(); 579 Page* p = it.next();
566 p->ClearEvacuationCandidate(); 580 p->ClearEvacuationCandidate();
(...skipping 13 matching lines...) Expand all
580 if (!p->WasSwept()) { 594 if (!p->WasSwept()) {
581 free_bytes = (p->area_size() - p->LiveBytes()); 595 free_bytes = (p->area_size() - p->LiveBytes());
582 } else { 596 } else {
583 FreeList::SizeStats sizes; 597 FreeList::SizeStats sizes;
584 space->CountFreeListItems(p, &sizes); 598 space->CountFreeListItems(p, &sizes);
585 free_bytes = sizes.Total(); 599 free_bytes = sizes.Total();
586 } 600 }
587 601
588 int free_pct = static_cast<int>(free_bytes * 100) / p->area_size(); 602 int free_pct = static_cast<int>(free_bytes * 100) / p->area_size();
589 603
590 if (free_pct >= kFreenessThreshold) { 604 if (free_pct >= freeness_threshold) {
591 estimated_release += 2 * p->area_size() - free_bytes; 605 estimated_release += 2 * p->area_size() - free_bytes;
592 fragmentation = free_pct; 606 fragmentation = free_pct;
593 } else { 607 } else {
594 fragmentation = 0; 608 fragmentation = 0;
595 } 609 }
596 610
597 if (FLAG_trace_fragmentation) { 611 if (FLAG_trace_fragmentation) {
598 PrintF("%p [%s]: %d (%.2f%%) free %s\n", 612 PrintF("%p [%s]: %d (%.2f%%) free %s\n",
599 reinterpret_cast<void*>(p), 613 reinterpret_cast<void*>(p),
600 AllocationSpaceName(space->identity()), 614 AllocationSpaceName(space->identity()),
(...skipping 3518 matching lines...) Expand 10 before | Expand all | Expand 10 after
4119 while (buffer != NULL) { 4133 while (buffer != NULL) {
4120 SlotsBuffer* next_buffer = buffer->next(); 4134 SlotsBuffer* next_buffer = buffer->next();
4121 DeallocateBuffer(buffer); 4135 DeallocateBuffer(buffer);
4122 buffer = next_buffer; 4136 buffer = next_buffer;
4123 } 4137 }
4124 *buffer_address = NULL; 4138 *buffer_address = NULL;
4125 } 4139 }
4126 4140
4127 4141
4128 } } // namespace v8::internal 4142 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-alloc.cc » ('j') | test/cctest/test-heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698