[PATCH] Core: monitoring anonymous map on Darwin platform
David Carlier
devnexen at gmail.com
Fri Aug 23 05:00:29 UTC 2019
# HG changeset patch
# User David Carlier <devnexen at gmail.com>
# Date 1566493379 -3600
# Thu Aug 22 18:02:59 2019 +0100
# Node ID adc68231e590554860b11ee851b293e46ba652db
# Parent 9f1f9d6e056a4f85907957ef263f78a426ae4f9c
Core: monitoring anonymous map on Darwin platform.
Allows to highligh those pages from nginx process with
this identifier.
diff -r 9f1f9d6e056a -r adc68231e590 auto/os/darwin
--- a/auto/os/darwin Mon Aug 19 15:16:06 2019 +0300
+++ b/auto/os/darwin Thu Aug 22 18:02:59 2019 +0100
@@ -118,3 +118,21 @@
ngx_feature_test="int32_t lock = 0;
if (!OSAtomicCompareAndSwap32Barrier(0, 1, &lock)) return 1"
. auto/feature
+
+# Darwin can tag anonymous pages to be tracked
+# with tools like vmmap
+# free ID are guaranteed to be free from 240 to 255
+# for userland applications
+
+ngx_feature="Darwin tags anonymous pages"
+ngx_feature_name=NGX_HAVE_MAP_ANON_TAG
+ngx_feature_run=yes
+ngx_feature_incs="#include <sys/mman.h>
+ #include <mach/vm_statistics.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="void *p = mmap(NULL, 16, PROT_READ, MAP_PRIVATE|MAP_ANON, VM_MAKE_TAG(240), 0);
+ if (p == MAP_FAILED) return 1;
+ munmap(p, 16)"
+
+. auto/feature
diff -r 9f1f9d6e056a -r adc68231e590 src/os/unix/ngx_darwin_config.h
--- a/src/os/unix/ngx_darwin_config.h Mon Aug 19 15:16:06 2019 +0300
+++ b/src/os/unix/ngx_darwin_config.h Thu Aug 22 18:02:59 2019 +0100
@@ -76,6 +76,10 @@
#include <sys/event.h>
#endif
+#if (NGX_HAVE_MAP_ANON_TAG)
+#include <mach/vm_statistics.h>
+#endif
+
#define NGX_LISTEN_BACKLOG -1
diff -r 9f1f9d6e056a -r adc68231e590 src/os/unix/ngx_shmem.c
--- a/src/os/unix/ngx_shmem.c Mon Aug 19 15:16:06 2019 +0300
+++ b/src/os/unix/ngx_shmem.c Thu Aug 22 18:02:59 2019 +0100
@@ -14,9 +14,16 @@
ngx_int_t
ngx_shm_alloc(ngx_shm_t *shm)
{
+ ngx_fd_t fd;
+
+#if (NGX_HAVE_MAP_ANON_TAG)
+ fd = VM_MAKE_TAG(246);
+#else
+ fd = -1;
+#endif
shm->addr = (u_char *) mmap(NULL, shm->size,
PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_SHARED, -1, 0);
+ MAP_ANON|MAP_SHARED, fd, 0);
if (shm->addr == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
More information about the nginx-devel
mailing list