summaryrefslogtreecommitdiffstats
path: root/base/memory
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2015-04-01 08:15:29 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-01 15:19:59 +0000
commitf2580f56cb770069af82eb10e8e2a58a2f4f72d7 (patch)
tree682cdac7406961a36ab574ba6206d75789487e94 /base/memory
parentb90c82e7e3160fb335870918a4d30b9e3a7466cd (diff)
downloadchromium_src-f2580f56cb770069af82eb10e8e2a58a2f4f72d7.zip
chromium_src-f2580f56cb770069af82eb10e8e2a58a2f4f72d7.tar.gz
chromium_src-f2580f56cb770069af82eb10e8e2a58a2f4f72d7.tar.bz2
Revert of base: Replace PurgeAndTruncate with Shrink function. (patchset #5 id:80001 of https://codereview.chromium.org/1018743003/)
Reason for revert: Suspecting that this might be related to crbug.com/471188. Original issue's description: > base: Replace PurgeAndTruncate with Shrink function. > > This cleans up the API a bit and allows the code to be unit tested. > > This also prevents ftruncate from being used on Android where > shared memory is backed by Ashmem. Ashmem doesn't support ftruncate. > > BUG=466509 > TEST=base_unittests --gtest_filter=DiscardableSharedMemoryTest.Shrink > > Committed: https://crrev.com/2d15df9ef3f9b982aef650d0be0be64a1c5d34a5 > Cr-Commit-Position: refs/heads/master@{#322207} TBR=avi@chromium.org,danakj@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=466509 Review URL: https://codereview.chromium.org/1057493005 Cr-Commit-Position: refs/heads/master@{#323240}
Diffstat (limited to 'base/memory')
-rw-r--r--base/memory/discardable_shared_memory.cc36
-rw-r--r--base/memory/discardable_shared_memory.h18
-rw-r--r--base/memory/discardable_shared_memory_unittest.cc16
3 files changed, 22 insertions, 48 deletions
diff --git a/base/memory/discardable_shared_memory.cc b/base/memory/discardable_shared_memory.cc
index 830d6b9..49e93cd 100644
--- a/base/memory/discardable_shared_memory.cc
+++ b/base/memory/discardable_shared_memory.cc
@@ -325,6 +325,22 @@ bool DiscardableSharedMemory::Purge(Time current_time) {
return true;
}
+bool DiscardableSharedMemory::PurgeAndTruncate(Time current_time) {
+ if (!Purge(current_time))
+ return false;
+
+#if defined(OS_POSIX)
+ // Truncate shared memory to size of SharedState.
+ SharedMemoryHandle handle = shared_memory_.handle();
+ if (SharedMemory::IsHandleValid(handle)) {
+ if (HANDLE_EINTR(ftruncate(handle.fd, sizeof(SharedState))) != 0)
+ DPLOG(ERROR) << "ftruncate() failed";
+ }
+#endif
+
+ return true;
+}
+
bool DiscardableSharedMemory::IsMemoryResident() const {
DCHECK(shared_memory_.memory());
@@ -341,26 +357,6 @@ void DiscardableSharedMemory::Close() {
mapped_size_ = 0;
}
-#if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
-void DiscardableSharedMemory::Shrink() {
-#if defined(OS_POSIX)
- SharedMemoryHandle handle = shared_memory_.handle();
- if (!SharedMemory::IsHandleValid(handle))
- return;
-
- // Truncate shared memory to size of SharedState.
- if (HANDLE_EINTR(
- ftruncate(handle.fd, AlignToPageSize(sizeof(SharedState)))) != 0) {
- DPLOG(ERROR) << "ftruncate() failed";
- return;
- }
- mapped_size_ = 0;
-#else
- NOTIMPLEMENTED();
-#endif
-}
-#endif
-
Time DiscardableSharedMemory::Now() const {
return Time::Now();
}
diff --git a/base/memory/discardable_shared_memory.h b/base/memory/discardable_shared_memory.h
index 892d556..e3b437c 100644
--- a/base/memory/discardable_shared_memory.h
+++ b/base/memory/discardable_shared_memory.h
@@ -15,12 +15,6 @@
#include <set>
#endif
-// Define DISCARDABLE_SHARED_MEMORY_SHRINKING if platform supports shrinking
-// of discardable shared memory segments.
-#if defined(OS_POSIX) && !defined(OS_ANDROID)
-#define DISCARDABLE_SHARED_MEMORY_SHRINKING
-#endif
-
namespace base {
// Platform abstraction for discardable shared memory.
@@ -99,6 +93,12 @@ class BASE_EXPORT DiscardableSharedMemory {
// each call.
bool Purge(Time current_time);
+ // Purge and release as much memory as possible to the OS.
+ // Note: The amount of memory that can be released to the OS is platform
+ // specific. Best case, all but one page is released. Worst case, nothing
+ // is released.
+ bool PurgeAndTruncate(Time current_time);
+
// Returns true if memory is still resident.
bool IsMemoryResident() const;
@@ -116,12 +116,6 @@ class BASE_EXPORT DiscardableSharedMemory {
return shared_memory_.ShareToProcess(process_handle, new_handle);
}
-#if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
- // Release as much memory as possible to the OS. The change in size will
- // be reflected by the return value of mapped_size().
- void Shrink();
-#endif
-
private:
// Virtual for tests.
virtual Time Now() const;
diff --git a/base/memory/discardable_shared_memory_unittest.cc b/base/memory/discardable_shared_memory_unittest.cc
index ae7235d..74d19a6 100644
--- a/base/memory/discardable_shared_memory_unittest.cc
+++ b/base/memory/discardable_shared_memory_unittest.cc
@@ -311,21 +311,5 @@ TEST(DiscardableSharedMemoryTest, MappedSize) {
EXPECT_EQ(0u, memory.mapped_size());
}
-#if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
-TEST(DiscardableSharedMemoryTest, Shrink) {
- const uint32 kDataSize = 1024;
-
- TestDiscardableSharedMemory memory;
- bool rv = memory.CreateAndMap(kDataSize);
- ASSERT_TRUE(rv);
-
- EXPECT_NE(0u, memory.mapped_size());
-
- // Mapped size should be 0 after shrinking memory segment.
- memory.Shrink();
- EXPECT_EQ(0u, memory.mapped_size());
-}
-#endif
-
} // namespace
} // namespace base