[PATCH 6/8] mmap_cache: add function to enable mmap_cache

Masatake YAMATO yamato at redhat.com
Fri Jan 26 20:36:42 UTC 2018


mmap_cache was enabled indirectly via unwind feature.  Now mmap_cache
can be used other part of strace. So the way to enable mmap_cache
directly is needed.

* mmap_cache (mmap_cache_enable, mmap_cache_is_enabled): New functions.
(use_mmap_cache): New file local variable.

* syscall.c (syscall_exiting_decode): Use mmap_cache_is_enabled.

* unwind.c (unwind_init): Call mmap_cache_enable.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 defs.h       |  2 ++
 mmap_cache.c | 11 +++++++++++
 syscall.c    |  4 +---
 unwind.c     |  1 +
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/defs.h b/defs.h
index 093acc3f..6c5f293d 100644
--- a/defs.h
+++ b/defs.h
@@ -738,6 +738,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);
diff --git a/mmap_cache.c b/mmap_cache.c
index a121b852..336bbdcd 100644
--- a/mmap_cache.c
+++ b/mmap_cache.c
@@ -39,6 +39,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
diff --git a/syscall.c b/syscall.c
index 4d11e7ed..431d799e 100644
--- a/syscall.c
+++ b/syscall.c
@@ -731,12 +731,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;
diff --git a/unwind.c b/unwind.c
index 9e9d43a1..84676257 100644
--- a/unwind.c
+++ b/unwind.c
@@ -70,6 +70,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
-- 
2.14.3





More information about the Strace-devel mailing list