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

Side by Side Diff: Source/wtf/PartitionAlloc.cpp

Issue 254103003: PartitionAlloc: Make in-place realloc() less likely to happen (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: extended test Created 6 years, 7 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
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 return false; 803 return false;
804 804
805 // bucket->slotSize is the current size of the allocation. 805 // bucket->slotSize is the current size of the allocation.
806 size_t currentSize = page->bucket->slotSize; 806 size_t currentSize = page->bucket->slotSize;
807 if (newSize == currentSize) 807 if (newSize == currentSize)
808 return true; 808 return true;
809 809
810 char* charPtr = static_cast<char*>(partitionPageToPointer(page)); 810 char* charPtr = static_cast<char*>(partitionPageToPointer(page));
811 811
812 if (newSize < currentSize) { 812 if (newSize < currentSize) {
813 size_t mapSize = partitionPageToDirectMapExtent(page)->mapSize;
814
815 // Don't reallocate in-place if new size is less than 80 % of the full
816 // map size, to avoid holding on to too much unused address space.
817 if ((newSize / kSystemPageSize) * 5 < (mapSize / kSystemPageSize) * 4)
818 return false;
819
813 // Shrink by decommitting unneeded pages and making them inaccessible. 820 // Shrink by decommitting unneeded pages and making them inaccessible.
814 size_t decommitSize = currentSize - newSize; 821 size_t decommitSize = currentSize - newSize;
815 decommitSystemPages(charPtr + newSize, decommitSize); 822 decommitSystemPages(charPtr + newSize, decommitSize);
816 setSystemPagesInaccessible(charPtr + newSize, decommitSize); 823 setSystemPagesInaccessible(charPtr + newSize, decommitSize);
817 } else if (newSize <= partitionPageToDirectMapExtent(page)->mapSize) { 824 } else if (newSize <= partitionPageToDirectMapExtent(page)->mapSize) {
818 // Grow within the actually allocated memory. Just need to make the 825 // Grow within the actually allocated memory. Just need to make the
819 // pages accessible again. 826 // pages accessible again.
820 size_t recommitSize = newSize - currentSize; 827 size_t recommitSize = newSize - currentSize;
821 setSystemPagesAccessible(charPtr + currentSize, recommitSize); 828 setSystemPagesAccessible(charPtr + currentSize, recommitSize);
822 829
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 printf("total live: %zu bytes\n", totalLive); 947 printf("total live: %zu bytes\n", totalLive);
941 printf("total resident: %zu bytes\n", totalResident); 948 printf("total resident: %zu bytes\n", totalResident);
942 printf("total freeable: %zu bytes\n", totalFreeable); 949 printf("total freeable: %zu bytes\n", totalFreeable);
943 fflush(stdout); 950 fflush(stdout);
944 } 951 }
945 952
946 #endif // !NDEBUG 953 #endif // !NDEBUG
947 954
948 } // namespace WTF 955 } // namespace WTF
949 956
OLDNEW
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698