From 5a3a9b1ea8fd5fe4f5a94277ec909f5e64151b10 Mon Sep 17 00:00:00 2001 From: Christopher Olston Date: Tue, 12 Jul 2016 09:45:21 -0800 Subject: Adds an interface for asking malloc to release free memory back to the OS. Change: 127216353 --- tensorflow/core/platform/mem.h | 9 +++++++++ tensorflow/core/platform/posix/port.cc | 4 ++++ 2 files changed, 13 insertions(+) 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) { -- cgit v1.2.3