aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Christopher Olston <olston@google.com>2016-07-12 09:45:21 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-07-12 11:03:31 -0700
commit5a3a9b1ea8fd5fe4f5a94277ec909f5e64151b10 (patch)
tree66d96d7b1a09a91577f83e9f949fd0e972992d8e
parentf2aaead7ce18dcd01dd13e9c15d4e60846568f08 (diff)
Adds an interface for asking malloc to release free memory back to the OS.
Change: 127216353
-rw-r--r--tensorflow/core/platform/mem.h9
-rw-r--r--tensorflow/core/platform/posix/port.cc4
2 files changed, 13 insertions, 0 deletions
diff --git a/tensorflow/core/platform/mem.h b/tensorflow/core/platform/mem.h
index 3383d031d8..8e7a18c55d 100644
--- a/tensorflow/core/platform/mem.h
+++ b/tensorflow/core/platform/mem.h
@@ -37,6 +37,15 @@ namespace port {
void* aligned_malloc(size_t size, int minimum_alignment);
void aligned_free(void* aligned_memory);
+// Tries to release num_bytes of free memory back to the operating
+// system for reuse. Use this routine with caution -- to get this
+// memory back may require faulting pages back in by the OS, and
+// that may be slow.
+//
+// Currently, if a malloc implementation does not support this
+// routine, this routine is a no-op.
+void MallocExtension_ReleaseToSystem(std::size_t num_bytes);
+
// Returns the actual number N of bytes reserved by the malloc for the
// pointer p. This number may be equal to or greater than the number
// of bytes requested when p was allocated.
diff --git a/tensorflow/core/platform/posix/port.cc b/tensorflow/core/platform/posix/port.cc
index 1877dfeddc..c8c57753b7 100644
--- a/tensorflow/core/platform/posix/port.cc
+++ b/tensorflow/core/platform/posix/port.cc
@@ -77,6 +77,10 @@ void* aligned_malloc(size_t size, int minimum_alignment) {
void aligned_free(void* aligned_memory) { free(aligned_memory); }
+void MallocExtension_ReleaseToSystem(std::size_t num_bytes) {
+ // No-op.
+}
+
std::size_t MallocExtension_GetAllocatedSize(const void* p) { return 0; }
void AdjustFilenameForLogging(string* filename) {