[sgen] Utility function to compute number of unfaulted pages.
authorLudovic Henry <ludovic.henry@xamarin.com>
Tue, 30 Sep 2014 21:09:50 +0000 (17:09 -0400)
committerMark Probst <mark.probst@gmail.com>
Mon, 20 Oct 2014 23:24:05 +0000 (16:24 -0700)
mono/metadata/sgen-cardtable.c
mono/utils/Makefile.am
mono/utils/mono-mmap-internal.h [new file with mode: 0644]
mono/utils/mono-mmap.c

index 7ee7e07bee31616d3ee43a3e3cc6324be5e41acf..6dd91e2444261a132c8a5ed2c57bc95733a6c103 100644 (file)
@@ -479,22 +479,6 @@ mono_gc_card_table_nursery_check (void)
 }
 
 #if 0
-static void
-collect_faulted_cards (void)
-{
-#define CARD_PAGES (CARD_COUNT_IN_BYTES / 4096)
-       int i, count = 0;
-       unsigned char faulted [CARD_PAGES] = { 0 };
-       mincore (sgen_cardtable, CARD_COUNT_IN_BYTES, faulted);
-
-       for (i = 0; i < CARD_PAGES; ++i) {
-               if (faulted [i])
-                       ++count;
-       }
-
-       printf ("TOTAL card pages %d faulted %d\n", CARD_PAGES, count);
-}
-
 void
 sgen_card_table_dump_obj_card (char *object, size_t size, void *dummy)
 {
index c5464d16b168375dc3ac31375765a299ebeaa97b..c2c8a0d790caf688585dc16216fbd40474f17226 100644 (file)
@@ -32,6 +32,7 @@ monoutils_sources = \
        mono-math.c             \
        mono-mmap.c             \
        mono-mmap.h             \
+       mono-mmap-internal.h    \
        mono-mutex.c            \
        mono-mutex.h            \
        mono-networkinterfaces.c                \
diff --git a/mono/utils/mono-mmap-internal.h b/mono/utils/mono-mmap-internal.h
new file mode 100644 (file)
index 0000000..1818e5c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * mono-mmap-internal.h: Internal virtual memory stuff.
+ *
+ * Copyright (C) 2014 Xamarin Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License 2.0 as published by the Free Software Foundation;
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License 2.0 along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MONO_UTILS_MMAP_INTERNAL_H__
+#define __MONO_UTILS_MMAP_INTERNAL_H__
+
+#include "mono-compiler.h"
+
+int mono_pages_not_faulted (void *addr, size_t length) MONO_INTERNAL;
+
+#endif /* __MONO_UTILS_MMAP_INTERNAL_H__ */
+
index 60ef156b15af7ed752361b70a36a625aee3fabbc..6caf9628380f2f3ab8cab48c096dd5a913286e17 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #include "mono-mmap.h"
+#include "mono-mmap-internal.h"
 #include "mono-proclib.h"
 
 #ifndef MAP_ANONYMOUS
@@ -243,6 +244,12 @@ mono_shared_area_instances (void **array, int count)
        return 0;
 }
 
+int
+mono_pages_not_faulted (void *addr, size_t length)
+{
+       return -1;
+}
+
 #else
 #if defined(HAVE_MMAP)
 
@@ -443,6 +450,30 @@ mono_mprotect (void *addr, size_t length, int flags)
 }
 #endif // __native_client__
 
+int
+mono_pages_not_faulted (void *addr, size_t size)
+{
+       int i;
+       gint64 count;
+       int pagesize = mono_pagesize ();
+       int npages = (size + pagesize - 1) / pagesize;
+       char *faulted = g_malloc0 (sizeof (char*) * npages);
+
+       if (mincore (addr, size, faulted) != 0) {
+               count = -1;
+       } else {
+               count = 0;
+               for (i = 0; i < npages; ++i) {
+                       if (faulted [i] != 0)
+                               ++count;
+               }
+       }
+
+       g_free (faulted);
+
+       return count;
+}
+
 #else
 
 /* dummy malloc-based implementation */
@@ -481,6 +512,13 @@ mono_mprotect (void *addr, size_t length, int flags)
        }
        return 0;
 }
+
+int
+mono_pages_not_faulted (void *addr, size_t length)
+{
+       return -1;
+}
+
 #endif // HAVE_MMAP
 
 #if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS)