Reviewers: Kasper Lund,

Description:
Partial fix for issue 173:
- Do not keep growing the zone segment size exponentially. By putting
   an upper limit on the segment size we limit the requirements for
   contiguous memory allocation.


Please review this at http://codereview.chromium.org/12984

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/zone.h
   M     src/zone.cc


Index: src/zone.cc
===================================================================
--- src/zone.cc (revision 918)
+++ src/zone.cc (working copy)
@@ -163,8 +163,23 @@
    // is to avoid excessive malloc() and free() overhead.
    Segment* head = Segment::head();
    int old_size = (head == NULL) ? 0 : head->size();
-  int new_size = sizeof(Segment) + kAlignment + size + (old_size << 1);
-  if (new_size < kMinimumSegmentSize) new_size = kMinimumSegmentSize;
+  int segment_overhead = sizeof(Segment) + kAlignment;
+  int new_size = segment_overhead + size + (old_size << 1);
+  if (new_size < kMinimumSegmentSize) {
+    new_size = kMinimumSegmentSize;
+  } else if (new_size > kMaximumSegmentSize) {
+    // Limit the size of new segments to avoid growing the segment size
+    // exponentially, thus putting pressure on contiguous virtual address
+    // space.
+    if (size > (kMaximumSegmentSize - segment_overhead)) {
+      // Make sure to allocate a segment at least large enough to hold the
+      // requested size.
+      new_size = RoundUp(size + segment_overhead, kMinimumSegmentSize);
+    } else {
+      // Allocate a new segment of maximum size.
+      new_size = kMaximumSegmentSize;
+    }
+  }
    Segment* segment = Segment::New(new_size);
    if (segment == NULL) V8::FatalProcessOutOfMemory("Zone");

Index: src/zone.h
===================================================================
--- src/zone.h  (revision 918)
+++ src/zone.h  (working copy)
@@ -74,6 +74,9 @@

    // Never allocate segments smaller than this size in bytes.
    static const int kMinimumSegmentSize = 8 * KB;
+
+  // Never allocate segments larger than this size in bytes.
+  static const int kMaximumSegmentSize = 1 * MB;

    // Never keep segments larger than this size in bytes around.
    static const int kMaximumKeptSegmentSize = 64 * KB;



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to