aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfuchen.ljl <yjqqqqdx_01@163.com>2023-12-06 12:23:56 +0000
committerGitHub <noreply@github.com>2023-12-06 12:23:56 +0000
commit4d56383025f2cbd00dc6296161e31a896624ab75 (patch)
treea1669206b4a517d9730bcd4666c69cbc877e52df
parent42dbcad3efb704475306474a79fd8e95dd977c54 (diff)
downloadstable-diffusion-webui-gfx803-4d56383025f2cbd00dc6296161e31a896624ab75.tar.gz
stable-diffusion-webui-gfx803-4d56383025f2cbd00dc6296161e31a896624ab75.tar.bz2
stable-diffusion-webui-gfx803-4d56383025f2cbd00dc6296161e31a896624ab75.zip
Long distance memory overflow issue
Problem: The memory will slowly increase with the drawing until restarting. Observation: GC analysis shows that no occupation has occurred, so it is suspected to be a problem with the underlying allocator. Reason: Under Linux, glibc is used to allocate memory. glibc uses brk and mmap to allocate memory, and the memory allocated by brk cannot be released until the high-address memory is released. That is to say, if you apply for two pieces of memory A and B through brk, it is impossible to release A before B is released, and it is still occupied by the process. Check the suspected "memory leak" through TOP. So I replaced TCMalloc, but found that libtcmalloc_minimal could not find ptthread_Key_Create. After analysis, it was found that pthread was not entered during compilation.
-rwxr-xr-xwebui.sh30
1 files changed, 23 insertions, 7 deletions
diff --git a/webui.sh b/webui.sh
index 3d0f87ee..081624c4 100755
--- a/webui.sh
+++ b/webui.sh
@@ -222,13 +222,29 @@ fi
# Try using TCMalloc on Linux
prepare_tcmalloc() {
if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
- TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -Po "libtcmalloc(_minimal|)\.so\.\d" | head -n 1)"
- if [[ ! -z "${TCMALLOC}" ]]; then
- echo "Using TCMalloc: ${TCMALLOC}"
- export LD_PRELOAD="${TCMALLOC}"
- else
- printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
- fi
+ # Define Tcmalloc Libs arrays
+ TCMALLOC_LIBS=("libtcmalloc(_minimal|)\.so\.\d" "libtcmalloc\.so\.\d")
+
+ # Traversal array
+ for lib in "${TCMALLOC_LIBS[@]}"
+ do
+ #Determine which type of tcmalloc library the library supports
+ TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -P $lib | head -n 1)"
+ TC_INFO=(${TCMALLOC//=>/})
+ if [[ ! -z "${TC_INFO}" ]]; then
+ echo "Using TCMalloc: ${TC_INFO}"
+ #Determine if the library is linked to libptthread and resolve undefined symbol: ptthread_Key_Create
+ if ldd ${TC_INFO[2]} | grep -q 'libpthread'; then
+ echo "$TC_INFO is linked with libpthread,execute LD_PRELOAD=${TC_INFO}"
+ export LD_PRELOAD="${TC_INFO}"
+ break
+ else
+ echo "$TC_INFO is not linked with libpthreadand will trigger undefined symbol: ptthread_Key_Create error"
+ fi
+ else
+ printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
+ fi
+ done
fi
}