From 118aee6f2b0d3b57f26cb93c181961339d3bfc5d Mon Sep 17 00:00:00 2001 From: zhangbo9674 <82555433+zhangbo9674@users.noreply.github.com> Date: Tue, 31 Jan 2023 14:51:46 +0800 Subject: [PATCH] not use shm cache default (#50089) --- paddle/phi/core/flags.cc | 4 ++-- .../fluid/dataloader/dataloader_iter.py | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/paddle/phi/core/flags.cc b/paddle/phi/core/flags.cc index 526457499c..680661c890 100644 --- a/paddle/phi/core/flags.cc +++ b/paddle/phi/core/flags.cc @@ -1198,11 +1198,11 @@ PADDLE_DEFINE_EXPORTED_bool(trt_ibuilder_cache, * mmap_allocator related FLAG * Name: use_shm_cache * Since Version: 2.5.0 - * Value Range: bool, default=true + * Value Range: bool, default=false * Example: * Note: . If True, mmap_allocator will cache shm file to decrease munmap * operation. */ PADDLE_DEFINE_EXPORTED_bool(use_shm_cache, - true, + false, "Use shm cache in mmap_allocator."); diff --git a/python/paddle/fluid/dataloader/dataloader_iter.py b/python/paddle/fluid/dataloader/dataloader_iter.py index c7c49c794a..66c6dff6c1 100644 --- a/python/paddle/fluid/dataloader/dataloader_iter.py +++ b/python/paddle/fluid/dataloader/dataloader_iter.py @@ -410,13 +410,22 @@ class _DataLoaderIterMultiProcess(_DataLoaderIterBase): # Note(zhangbo): shm_buffer_size is used for MemoryMapAllocationPool. # MemoryMapAllocationPool is used to cache and reuse shm, thus reducing munmap in dataloader. # For more details, please see: paddle/fluid/memory/allocation/mmap_allocator.h - try: - self._worker_shm_buffer_size = (2 + 1) * len(self._dataset[0]) - except: + if os.environ.get('FLAGS_use_shm_cache', False) in [ + 1, + '1', + True, + 'True', + 'true', + ]: + try: + self._worker_shm_buffer_size = (2 + 1) * len(self._dataset[0]) + except: + self._worker_shm_buffer_size = 0 + warnings.warn( + "Setting the shm cache buffer size to 0, equivalent to not using the shm cache policy." + ) + else: self._worker_shm_buffer_size = 0 - warnings.warn( - "Setting the shm cache buffer size to 0, equivalent to not using the shm cache policy." - ) self._main_thread_shm_buffer_size = ( (self._worker_shm_buffer_size) * 2 * self._num_workers ) -- GitLab