linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Boyang <zhangboyang.id@gmail.com>
To: linux-perf-users@vger.kernel.org
Subject: Re: [BUG] JIT symbols not resolved after mprotect() combined vma
Date: Wed, 13 Jan 2021 18:57:57 +0800	[thread overview]
Message-ID: <c99426db-b696-e74b-417c-636dee0b1c8f@gmail.com> (raw)
In-Reply-To: <40d550d6-e698-fad2-be81-aab6a56c5e64@gmail.com>

Hello,

The problem had been solved. I'm using a old kernel so I encountered 
this problem. I should try my program on latest kernel first.

Here are some pointers about this problem:

https://www.spinics.net/lists/linux-perf-users/msg09833.html
https://lkml.org/lkml/2019/10/31/785

Thank you all!
Zhang Boyang

On 2021/1/9 16:59, Zhang Boyang wrote:
> Hello,
> 
>    I'm using perf to measure my LLVM jitted code performance. However, I 
> found with some condition, perf will unable to resolve or annotate JIT 
> symbols. After some debugging, I found the cause is mprotect() combined 
> two adjacent vma, and report a MMAP2 event of merged vma, confusing perf.
>    I wrote a sample program (sample.c). It creates function computing 
> factorial. First it creates test1() and exec it for 10000 times. Then, 
> it creates test2() and exec both test1() and test2() for 10000 times 
> respectively. As a result, test1() was executed 20000 times, and test2() 
> was executed 10000 times.
>    However, perf report shows:
> 
>    33.33%  a.out    jitted-10742-3.so    [.] test2
>    33.30%  a.out    jitted-10742-2.so    [.] test1
>    33.26%  a.out    [JIT] tid 10742      [.] 0x00007f4b8cb3d010 // test1
> 
>    This is because LLVM create jitted code by using mmap() and 
> mprotect(): (the address is different because of ASLR)
> 
> //// compile test1
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
> = 0x7fca1a491000
> mprotect(0x7fca1a491000, 4096, PROT_READ|PROT_EXEC) = 0
> //// compile test2
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
> = 0x7fca1a490000
> mprotect(0x7fca1a490000, 4096, PROT_READ|PROT_EXEC) = 0
> 
>    The second mprotect will merge two adjacent vma, and report a MMAP2 
> event of merged vma. The pref tool saw this:
> 
> 9547033496331 0x2510 [0x60]: PERF_RECORD_MMAP2 10742/10742: 
> [0x7f4b8cb3d000(0x2000) @ 0x7f4b8cb3d000 00:00 0 0]: r-xp //anon
> 9547033524086 0xf00 [0xb0]: PERF_RECORD_MMAP2 10742/10742: 
> [0x7f4b8cb3d000(0x18) @ 0x40 08:02 10224200 1]: --xs 
> /home/zby/src/qemuproject/qemu/.debug/jit/llvm-IR-jit-20210109-ad4573/jitted-10742-2.so 
> 
> 9553628266188 0x103898 [0x60]: PERF_RECORD_MMAP2 10742/10742: 
> [0x7f4b8cb3c000(0x3000) @ 0x7f4b8cb3c000 00:00 0 0]: r-xp //anon
> 9553628283472 0xfb0 [0xb0]: PERF_RECORD_MMAP2 10742/10742: 
> [0x7f4b8cb3c000(0x18) @ 0x40 08:02 10224201 1]: --xs 
> /home/zby/src/qemuproject/qemu/.debug/jit/llvm-IR-jit-20210109-ad4573/jitted-10742-3.so 
> 
> 
>    The event of third line, confusing perf, make it thinks test1() had 
> disappear. Then perf if unable to resolve test1() or annotate it.
> 
> 
> Thank you very much!
> Zhang Boyang

      reply	other threads:[~2021-01-13 10:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-09  8:59 [BUG] JIT symbols not resolved after mprotect() combined vma Zhang Boyang
2021-01-13 10:57 ` Zhang Boyang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c99426db-b696-e74b-417c-636dee0b1c8f@gmail.com \
    --to=zhangboyang.id@gmail.com \
    --cc=linux-perf-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).