Skip to content

Commit 0d43594

Browse files
authored
Merge pull request #12364 from JiayiFeng/dev_add_FLAG_free_idle_memory
add flag to prevent unnessary memory free
2 parents 73fcfc0 + fd2d2c6 commit 0d43594

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

paddle/fluid/memory/detail/buddy_allocator.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ limitations under the License. */
1515
#include "paddle/fluid/memory/detail/buddy_allocator.h"
1616
#include "glog/logging.h"
1717

18+
DEFINE_bool(free_idle_memory, false,
19+
"If it is true, Paddle will try to free idle memory trunks during "
20+
"running time.");
21+
1822
namespace paddle {
1923
namespace memory {
2024
namespace detail {
@@ -152,13 +156,14 @@ void BuddyAllocator::Free(void* p) {
152156
pool_.insert(
153157
IndexSizeAddress(block->index(cache_), block->total_size(cache_), block));
154158

155-
// Clean up if existing too much free memory
156-
157-
// Prefer freeing fallback allocation first
158-
CleanIdleFallBackAlloc();
159+
if (FLAGS_free_idle_memory) {
160+
// Clean up if existing too much free memory
161+
// Prefer freeing fallback allocation first
162+
CleanIdleFallBackAlloc();
159163

160-
// Free normal allocation
161-
CleanIdleNormalAlloc();
164+
// Free normal allocation
165+
CleanIdleNormalAlloc();
166+
}
162167
}
163168

164169
size_t BuddyAllocator::Used() { return total_used_; }

python/paddle/fluid/__init__.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,33 @@
6262
Tensor = LoDTensor
6363

6464
__all__ = framework.__all__ + executor.__all__ + concurrency.__all__ + \
65-
trainer.__all__ + inferencer.__all__ + transpiler.__all__ + \
66-
parallel_executor.__all__ + lod_tensor.__all__ + [
67-
'io',
68-
'initializer',
69-
'layers',
70-
'contrib',
71-
'transpiler',
72-
'nets',
73-
'optimizer',
74-
'learning_rate_decay',
75-
'backward',
76-
'regularizer',
77-
'LoDTensor',
78-
'LoDTensorArray',
79-
'CPUPlace',
80-
'CUDAPlace',
81-
'CUDAPinnedPlace',
82-
'Tensor',
83-
'ParamAttr',
84-
'WeightNormParamAttr',
85-
'DataFeeder',
86-
'clip',
87-
'profiler',
88-
'unique_name',
89-
'recordio_writer',
90-
'Scope',
91-
]
65+
trainer.__all__ + inferencer.__all__ + transpiler.__all__ + \
66+
parallel_executor.__all__ + lod_tensor.__all__ + [
67+
'io',
68+
'initializer',
69+
'layers',
70+
'contrib',
71+
'transpiler',
72+
'nets',
73+
'optimizer',
74+
'learning_rate_decay',
75+
'backward',
76+
'regularizer',
77+
'LoDTensor',
78+
'LoDTensorArray',
79+
'CPUPlace',
80+
'CUDAPlace',
81+
'CUDAPinnedPlace',
82+
'Tensor',
83+
'ParamAttr',
84+
'WeightNormParamAttr',
85+
'DataFeeder',
86+
'clip',
87+
'profiler',
88+
'unique_name',
89+
'recordio_writer',
90+
'Scope',
91+
]
9292

9393

9494
def __bootstrap__():
@@ -123,7 +123,7 @@ def __bootstrap__():
123123
read_env_flags = [
124124
'use_pinned_memory', 'check_nan_inf', 'benchmark', 'warpctc_dir',
125125
'eager_delete_scope', 'use_mkldnn', 'initial_cpu_memory_in_mb',
126-
'init_allocated_mem'
126+
'init_allocated_mem', 'free_idle_memory'
127127
]
128128
if core.is_compiled_with_dist():
129129
read_env_flags.append('rpc_deadline')

0 commit comments

Comments
 (0)