From 925a27c0234a984062525c5d4e10de3ba884561e Mon Sep 17 00:00:00 2001 From: "iposva@chromium.org" Date: Fri, 5 Dec 2008 17:37:12 +0000 Subject: [PATCH] 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. Review URL: http://codereview.chromium.org/12984 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@926 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/zone.cc | 19 +++++++++++++++++-- src/zone.h | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/zone.cc b/src/zone.cc index cfa161a..4eac3d3 100644 --- a/src/zone.cc +++ b/src/zone.cc @@ -163,8 +163,23 @@ Address Zone::NewExpand(int size) { // 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; + static const int kSegmentOverhead = sizeof(Segment) + kAlignment; + int new_size = kSegmentOverhead + 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 - kSegmentOverhead)) { + // Make sure to allocate a segment at large enough to hold the requested + // size. + new_size = kSegmentOverhead + size; + } else { + // Allocate a new segment of maximum size. + new_size = kMaximumSegmentSize; + } + } Segment* segment = Segment::New(new_size); if (segment == NULL) V8::FatalProcessOutOfMemory("Zone"); diff --git a/src/zone.h b/src/zone.h index 612819e..ab64abb 100644 --- a/src/zone.h +++ b/src/zone.h @@ -74,6 +74,9 @@ class Zone { // 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; -- 2.7.4