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

Masatake YAMATO yamato at redhat.com
Fri Feb 16 19:37:13 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 f49d6f56..5b42590f 100644
--- a/defs.h
+++ b/defs.h
@@ -755,6 +755,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 a3367027..bb474b1f 100644
--- a/mmap_cache.c
+++ b/mmap_cache.c
@@ -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
diff --git a/syscall.c b/syscall.c
index 66d91022..c3d5f66e 100644
--- a/syscall.c
+++ b/syscall.c
@@ -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;
diff --git a/unwind.c b/unwind.c
index 3457ec84..ea7ae353 100644
--- a/unwind.c
+++ b/unwind.c
@@ -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
-- 
2.14.3





More information about the Strace-devel mailing list