简体   繁体   中英

what is the difference when linking against tcmalloc or not

This is a linkage question rather than a uwsgi question. But I will explain the story.

I am using uwsgi to host my flask app. After running some weeks on production, I found that my app have some slight memory leak; its RSS size reported by uswgitop is increasing. Although it is a not big deal as it is only around 50MiB to 60MiB, I want to find out why it is increasing.

After some work, I found that it might due to memory fragmentation of the malloc implementation in libc.

So I am considering using tcmalloc or jemalloc, which is famous for the memory fragmentation management.

Then I came to build uwsgi on my own. It produced the following linking command.

x86_64-linux-gnu-gcc -pthread -o uwsgi -L/usr/lib -Wl,-rpath,/usr/lib .......tons of object files 
-lpthread -lm -rdynamic -ldl -lz -ltcmalloc
-L/home/alex/local/lib -lpcre -lssl -lcrypto -lxml2 -lpthread -ldl -lutil -lm -lpython2.7 -lcrypt

As you can see from the comand, it explicitly links against tcmalloc, which is a dynamic link not a static one. As far as I know, tcmalloc implements the standard posix malloc interface, that is also why we can use LD_PRELOAD to hook into one application to replace its malloc implementation.

My question here is:

Why we need to explicitly specify to link against tcmalloc when we can use LD_PRELOAD to do so?

If you are interesting only in standard API, there is no difference.

But tcmalloc has more than that, like heap checking, heap profiling, allocation functions hooks etc. Natural way to use it is linking with libtcmalloc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM