[PATCH 1/4] ldv/unwind: enable cache feature of libunwind

enh enh at google.com
Wed Apr 9 18:11:02 UTC 2014


i don't know whether you care, but Android recently switched to
libunwind and we had to rewrite the caching because it's so leaky.
we've also found libunwind copes badly with processes that are
crashed/crashing --- there are no sanity checks before dereferences.
we [think we've] fixed this locally, but we haven't managed to get
much upstreamed yet.

you can see our local changes here:

https://android-review.googlesource.com/#/q/project:platform/external/libunwind

On Wed, Apr 9, 2014 at 9:52 AM, Masatake YAMATO <yamato at redhat.com> wrote:
> With turning on cache feature of libunwind, stack tracing
> becomes two times faster(in my small test).
>
> Target program:
>
>     #include <unistd.h>
>     #include <sys/types.h>
>
>     #define N 0xfff
>
>     int
>     main(void)
>     {
>       uid_t uid;
>       int i;
>
>       for (i = 0; i < N; i++)
>         getuid();
>
>       return 0;
>     }
>
> With enabling cache of libunwind:
>
>     % /usr/bin/time ./strace -o /dev/null -e'getuid' -k ./a.out
>     0.61user 1.33system 0:01.97elapsed 98%CPU (0avgtext+0avgdata 1376maxresident)k
>     0inputs+0outputs (0major+590269minor)pagefaults 0swaps
>
> Without enabling cache of libunwind:
>
>     % /usr/bin/time ./strace -o /dev/null -e'getuid' -k ./a.out
>     0.80user 2.61system 0:03.46elapsed 98%CPU (0avgtext+0avgdata 1372maxresident)k
>     0inputs+0outputs (0major+639381minor)pagefaults 0swaps
>
> Signed-off-by: Masatake YAMATO <yamato at redhat.com>
> ---
>  unwind.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/unwind.c b/unwind.c
> index 4cb6325..ed2d141 100644
> --- a/unwind.c
> +++ b/unwind.c
> @@ -80,6 +80,7 @@ init_unwind_addr_space(void)
>         libunwind_as = unw_create_addr_space(&_UPT_accessors, 0);
>         if (!libunwind_as)
>                 error_msg_and_die("failed to create address space for stack tracing");
> +       unw_set_caching_policy(libunwind_as, UNW_CACHE_GLOBAL);
>  }
>
>  static void
> @@ -135,6 +136,8 @@ build_mmap_cache(struct tcb *tcp)
>         struct mmap_cache_t *cache_head;
>         FILE *fp;
>
> +       unw_flush_cache (libunwind_as, 0, 0);
> +
>         sprintf(filename, "/proc/%d/maps", tcp->pid);
>         fp = fopen(filename, "r");
>         if (!fp) {
> --
> 1.8.5.3
>
>
> ------------------------------------------------------------------------------
> Put Bad Developers to Shame
> Dominate Development with Jenkins Continuous Integration
> Continuously Automate Build, Test & Deployment
> Start a new project now. Try Jenkins in the cloud.
> http://p.sf.net/sfu/13600_Cloudbees
> _______________________________________________
> Strace-devel mailing list
> Strace-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/strace-devel



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Java i18n/JNI/NIO, or bionic questions? Mail me/drop by/add me as a reviewer.




More information about the Strace-devel mailing list