Search code examples
libcperfmemset

what is `__GI_memset`? why does it cost so much CPU resource?


I'm new to perf, and I'm trying to use it to analyse my programme.

and I got this when running perf top:

 PerfTop:     296 irqs/sec  kernel:62.8%  exact:  0.0% [1000Hz cycles:ppp],  (all, 6 CPUs)
-----------------------------------------------------------------------------------------------------------------------

    65.43%  libc-2.23.so                  [.] __GI_memset
     1.55%  libopencv_imgcodecs.so.4.4.0  [.] cv::icvCvt_BGR2RGB_8u_C3R
     1.54%  libc-2.23.so                  [.] malloc
     1.32%  libc-2.23.so                  [.] _int_free
     0.92%  [kernel]                      [k] clear_page
     0.91%  libjpeg.so.8.0.2              [.] 0x000000000001b828
     0.90%  libc-2.23.so                  [.] memcpy

so, I just wonder what cost my 65% of CPU resource, is it really just memset in libc? if it is, how come it cost this much?


Solution

  • what is __GI_memset?

    It's an internal alias for memset.

    why does it cost so much CPU resource?

    Because you call it a lot, or because you give it a lot of memory set to some value.

    Judging by your next most expensive symbol cv::icvCvt_BGR2RGB_8u_C3R, you are doing some kind of image processing, and possibly are allocating cleared images.

    One common mistake is to allocate a cleared image and immediately set it something else (thus wasting the time spent clearing it). But there is not enough info here to deduce whether you are doing that here.