From 733ebe7c09404ea2e443e12143edc768a81cd415 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Tue, 17 Jul 2018 13:03:03 -0700 Subject: Merge FileMem.usage in IncRef Per the doc, usage must be kept maximally merged. Beyond that, it is simply a good idea to keep fragmentation in usage to a minimum. The glibc malloc allocator allocates one page at a time, potentially causing lots of fragmentation. However, those pages are likely to have the same number of references, often making it possible to merge ranges. PiperOrigin-RevId: 204960339 Change-Id: I03a050cf771c29a4f05b36eaf75b1a09c9465e14 --- pkg/sentry/platform/filemem/filemem.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pkg/sentry/platform') diff --git a/pkg/sentry/platform/filemem/filemem.go b/pkg/sentry/platform/filemem/filemem.go index 6c8b95578..870274ae1 100644 --- a/pkg/sentry/platform/filemem/filemem.go +++ b/pkg/sentry/platform/filemem/filemem.go @@ -547,6 +547,8 @@ func (f *FileMem) IncRef(fr platform.FileRange) { if gap.Ok() { panic(fmt.Sprintf("IncRef(%v): attempted to IncRef on unallocated pages %v:\n%v", fr, gap.Range(), &f.usage)) } + + f.usage.MergeAdjacent(fr) } // DecRef implements platform.File.DecRef. -- cgit v1.2.3