mmap_cache: add function to enable mmap_cache

mmap_cache was enabled indirectly via unwind feature.  As now mmap_cache
can be used by other part of strace, a way to enable mmap_cache directly
is needed.

* defs.h (mmap_cache_enable, mmap_cache_is_enabled): New function
prototypes.
* mmap_cache.c (use_mmap_cache): New file local variable.
(mmap_cache_enable, mmap_cache_is_enabled): New functions.
* syscall.c (syscall_exiting_decode): Use mmap_cache_is_enabled()
instead of stack_trace_enabled.
* unwind.c (unwind_init): Invoke mmap_cache_enable.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
This commit is contained in:
Masatake YAMATO 2018-02-17 04:37:13 +09:00 committed by Dmitry V. Levin
parent 7f041ed0d9
commit c4e4ca97bc
4 changed files with 15 additions and 3 deletions

2
defs.h
View File

@ -756,6 +756,8 @@ enum mmap_cache_rebuild_result {
MMAP_CACHE_REBUILD_RENEWED,
};
extern void mmap_cache_enable(void);
extern bool mmap_cache_is_enabled(void);
extern void mmap_cache_invalidate(struct tcb *tcp);
extern void mmap_cache_delete(struct tcb *tcp, const char *caller);
extern enum mmap_cache_rebuild_result mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller);

View File

@ -41,6 +41,17 @@
#endif
static unsigned int mmap_cache_generation;
static bool use_mmap_cache;
extern void mmap_cache_enable(void)
{
use_mmap_cache = true;
}
extern bool mmap_cache_is_enabled(void)
{
return use_mmap_cache;
}
/*
* caching of /proc/ID/maps for each process to speed up stack tracing

View File

@ -728,12 +728,10 @@ syscall_exiting_decode(struct tcb *tcp, struct timeval *ptv)
if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp)))
gettimeofday(ptv, NULL);
#ifdef USE_LIBUNWIND
if (stack_trace_enabled) {
if (mmap_cache_is_enabled()) {
if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
mmap_cache_invalidate(tcp);
}
#endif
if (filtered(tcp) || hide_log(tcp))
return 0;

View File

@ -74,6 +74,7 @@ unwind_init(void)
if (!libunwind_as)
error_msg_and_die("failed to create address space for stack tracing");
unw_set_caching_policy(libunwind_as, UNW_CACHE_GLOBAL);
mmap_cache_enable();
}
void