mirror of
				https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
				synced 2025-10-30 17:38:51 +00:00 
			
		
		
		
	Merge pull request #14883 from analysisjp/dev_fix_memleak_new
fix prepare_tcmalloc (fix: #14227)(Fixed memory leak issue in Ubuntu 22.04 or modern linux environment)
This commit is contained in:
		
						commit
						4d46f8c25c
					
				
							
								
								
									
										36
									
								
								webui.sh
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								webui.sh
									
									
									
									
									
								
							| @ -226,30 +226,48 @@ fi | |||||||
| # Try using TCMalloc on Linux | # Try using TCMalloc on Linux | ||||||
| prepare_tcmalloc() { | prepare_tcmalloc() { | ||||||
|     if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then |     if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then | ||||||
|  |         # check glibc version | ||||||
|  |         LIBC_LIB="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -P "libc.so.6" | head -n 1)" | ||||||
|  |         LIBC_INFO=$(echo ${LIBC_LIB} | awk '{print $NF}') | ||||||
|  |         LIBC_VER=$(echo $(${LIBC_INFO} | awk 'NR==1 {print $NF}') | grep -oP '\d+\.\d+') | ||||||
|  |         echo "glibc version is $LIBC_VER" | ||||||
|  |         libc_vernum=$(expr $LIBC_VER) | ||||||
|  |         # Since 2.34 libpthread is integrated into libc.so | ||||||
|  |         libc_v234=2.34 | ||||||
|         # Define Tcmalloc Libs arrays |         # Define Tcmalloc Libs arrays | ||||||
|         TCMALLOC_LIBS=("libtcmalloc(_minimal|)\.so\.\d" "libtcmalloc\.so\.\d") |         TCMALLOC_LIBS=("libtcmalloc(_minimal|)\.so\.\d" "libtcmalloc\.so\.\d") | ||||||
| 
 |  | ||||||
|         # Traversal array |         # Traversal array | ||||||
|         for lib in "${TCMALLOC_LIBS[@]}" |         for lib in "${TCMALLOC_LIBS[@]}" | ||||||
|         do |         do | ||||||
|           #Determine which type of tcmalloc library the library supports |             # Determine which type of tcmalloc library the library supports | ||||||
|             TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -P $lib | head -n 1)" |             TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -P $lib | head -n 1)" | ||||||
|             TC_INFO=(${TCMALLOC//=>/}) |             TC_INFO=(${TCMALLOC//=>/}) | ||||||
|             if [[ ! -z "${TC_INFO}" ]]; then |             if [[ ! -z "${TC_INFO}" ]]; then | ||||||
|               echo "Using TCMalloc: ${TC_INFO}" |                 echo "Check TCMalloc: ${TC_INFO}" | ||||||
|               #Determine if the library is linked to libptthread and resolve undefined symbol: ptthread_Key_Create |                 # Determine if the library is linked to libptthread and resolve undefined symbol: ptthread_key_create | ||||||
|  |                 if [ $(echo "$libc_vernum < $libc_v234" | bc) -eq 1 ]; then | ||||||
|  |                     # glibc < 2.33 pthread_key_create into libpthead.so. check linking libpthread.so... | ||||||
|                     if ldd ${TC_INFO[2]} | grep -q 'libpthread'; then |                     if ldd ${TC_INFO[2]} | grep -q 'libpthread'; then | ||||||
|                 echo "$TC_INFO is linked with libpthread,execute LD_PRELOAD=${TC_INFO}" |                         echo "$TC_INFO is linked with libpthread,execute LD_PRELOAD=${TC_INFO[2]}" | ||||||
|                 export LD_PRELOAD="${TC_INFO}" |                         # set fullpath LD_PRELOAD (To be on the safe side) | ||||||
|  |                         export LD_PRELOAD="${TC_INFO[2]}" | ||||||
|                         break |                         break | ||||||
|                     else |                     else | ||||||
|                 echo "$TC_INFO is not linked with libpthreadand will trigger undefined symbol: ptthread_Key_Create error" |                         echo "$TC_INFO is not linked with libpthread will trigger undefined symbol: pthread_Key_create error" | ||||||
|                     fi |                     fi | ||||||
|                 else |                 else | ||||||
|               printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n" |                     # Version 2.34 of libc.so (glibc) includes the pthead library IN GLIBC. (USE ubuntu 22.04 and modern linux system and WSL) | ||||||
|  |                     # libc.so(glibc) is linked with a library that works in ALMOST ALL Linux userlands. SO NO CHECK! | ||||||
|  |                     echo "$TC_INFO is linked with libc.so,execute LD_PRELOAD=${TC_INFO[2]}" | ||||||
|  |                     # set fullpath LD_PRELOAD (To be on the safe side) | ||||||
|  |                     export LD_PRELOAD="${TC_INFO[2]}" | ||||||
|  |                     break | ||||||
|  |                 fi | ||||||
|             fi |             fi | ||||||
|         done |         done | ||||||
| 
 |         if [[ -z "${LD_PRELOAD}" ]]; then | ||||||
|  |             printf "\e[1m\e[31mCannot locate TCMalloc. Do you have tcmalloc or gperftools installed on your system? (improves CPU memory usage)\e[0m\n" | ||||||
|  |         fi | ||||||
|     fi |     fi | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 AUTOMATIC1111
						AUTOMATIC1111