[pypy-commit] stmgc default: Add a #define USE_REMAP_FILE_PAGES which can be turned off.
arigo
noreply at buildbot.pypy.org
Thu May 8 15:01:45 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1203:31f9797a356c
Date: 2014-05-08 15:01 +0200
http://bitbucket.org/pypy/stmgc/changeset/31f9797a356c/
Log: Add a #define USE_REMAP_FILE_PAGES which can be turned off.
diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -209,6 +209,7 @@
};
static char *stm_object_pages;
+static int stm_object_pages_fd;
static stm_thread_local_t *stm_all_thread_locals = NULL;
static uint8_t write_locks[WRITELOCK_END - WRITELOCK_START];
diff --git a/c7/stm/forksupport.c b/c7/stm/forksupport.c
--- a/c7/stm/forksupport.c
+++ b/c7/stm/forksupport.c
@@ -8,14 +8,10 @@
static char *fork_big_copy = NULL;
+static int fork_big_copy_fd;
static stm_thread_local_t *fork_this_tl;
static bool fork_was_in_transaction;
-static char *setup_mmap(char *reason); /* forward, in setup.c */
-static void setup_protection_settings(void); /* forward, in setup.c */
-static pthread_t *_get_cpth(stm_thread_local_t *);/* forward, in setup.c */
-
-
static bool page_is_null(char *p)
{
long *q = (long *)p;
@@ -74,7 +70,8 @@
/* Make a new mmap at some other address, but of the same size as
the standard mmap at stm_object_pages
*/
- char *big_copy = setup_mmap("stmgc's fork support");
+ int big_copy_fd;
+ char *big_copy = setup_mmap("stmgc's fork support", &big_copy_fd);
/* Copy each of the segment infos into the new mmap, nurseries,
and associated read markers
@@ -139,6 +136,7 @@
assert(fork_big_copy == NULL);
fork_big_copy = big_copy;
+ fork_big_copy_fd = big_copy_fd;
fork_this_tl = this_tl;
fork_was_in_transaction = was_in_transaction;
@@ -163,6 +161,7 @@
assert(fork_big_copy != NULL);
munmap(fork_big_copy, TOTAL_MEMORY);
fork_big_copy = NULL;
+ close_fd_mmap(fork_big_copy_fd);
bool was_in_transaction = fork_was_in_transaction;
s_mutex_unlock();
@@ -214,6 +213,8 @@
if (res != stm_object_pages)
stm_fatalerror("after fork: mremap failed: %m");
fork_big_copy = NULL;
+ close_fd_mmap(stm_object_pages_fd);
+ stm_object_pages_fd = fork_big_copy_fd;
/* Unregister all other stm_thread_local_t, mostly as a way to free
the memory used by the shadowstacks
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -81,9 +81,18 @@
can only be remapped to page N in another segment */
assert(((addr - stm_object_pages) / 4096UL - pgoff) % NB_PAGES == 0);
+#ifdef USE_REMAP_FILE_PAGES
int res = remap_file_pages(addr, size, 0, pgoff, 0);
if (UNLIKELY(res < 0))
stm_fatalerror("remap_file_pages: %m");
+#else
+ char *res = mmap(addr, size,
+ PROT_READ | PROT_WRITE,
+ (MAP_PAGES_FLAGS & ~MAP_ANONYMOUS) | MAP_FIXED,
+ stm_object_pages_fd, pgoff * 4096UL);
+ if (UNLIKELY(res != addr))
+ stm_fatalerror("mmap (remapping page): %m");
+#endif
}
static void pages_initialize_shared(uintptr_t pagenum, uintptr_t count)
@@ -169,6 +178,7 @@
static void pages_setup_readmarkers_for_nursery(void)
{
+#ifdef USE_REMAP_FILE_PAGES
/* The nursery page's read markers are never read, but must still
be writeable. We'd like to map the pages to a general "trash
page"; missing one, we remap all the pages over to the same one.
@@ -187,4 +197,5 @@
/* errors here ignored */
}
}
+#endif
}
diff --git a/c7/stm/pages.h b/c7/stm/pages.h
--- a/c7/stm/pages.h
+++ b/c7/stm/pages.h
@@ -19,6 +19,8 @@
#define PAGE_FLAG_START END_NURSERY_PAGE
#define PAGE_FLAG_END NB_PAGES
+#define USE_REMAP_FILE_PAGES
+
struct page_shared_s {
#if NB_SEGMENTS <= 8
uint8_t by_segment;
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -3,7 +3,8 @@
#endif
-static char *setup_mmap(char *reason)
+#ifdef USE_REMAP_FILE_PAGES
+static char *setup_mmap(char *reason, int *ignored)
{
char *result = mmap(NULL, TOTAL_MEMORY,
PROT_READ | PROT_WRITE,
@@ -13,6 +14,45 @@
return result;
}
+static void close_fd_mmap(int ignored)
+{
+}
+#else
+#include <fcntl.h> /* For O_* constants */
+static char *setup_mmap(char *reason, int *map_fd)
+{
+ char name[128];
+ sprintf(name, "/stmgc-c7-bigmem-%ld-%.18e",
+ (long)getpid(), get_stm_time());
+
+ /* Create the big shared memory object, and immediately unlink it.
+ There is a small window where if this process is killed the
+ object is left around. It doesn't seem possible to do anything
+ about it...
+ */
+ int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
+ shm_unlink(name);
+
+ if (fd == -1) {
+ stm_fatalerror("%s failed (stm_open): %m", reason);
+ }
+ if (ftruncate(fd, TOTAL_MEMORY) != 0) {
+ stm_fatalerror("%s failed (ftruncate): %m", reason);
+ }
+ char *result = mmap(NULL, TOTAL_MEMORY,
+ PROT_READ | PROT_WRITE,
+ MAP_PAGES_FLAGS & ~MAP_ANONYMOUS, fd, 0);
+ if (result == MAP_FAILED) {
+ stm_fatalerror("%s failed (mmap): %m", reason);
+ }
+ *map_fd = fd;
+ return result;
+}
+static void close_fd_mmap(int map_fd)
+{
+ close(map_fd);
+}
+#endif
static void setup_protection_settings(void)
{
@@ -56,7 +96,8 @@
(FIRST_READMARKER_PAGE * 4096UL));
assert(_STM_FAST_ALLOC <= NB_NURSERY_PAGES * 4096);
- stm_object_pages = setup_mmap("initial stm_object_pages mmap()");
+ stm_object_pages = setup_mmap("initial stm_object_pages mmap()",
+ &stm_object_pages_fd);
setup_protection_settings();
long i;
@@ -127,6 +168,7 @@
munmap(stm_object_pages, TOTAL_MEMORY);
stm_object_pages = NULL;
+ close_fd_mmap(stm_object_pages_fd);
teardown_core();
teardown_sync();
diff --git a/c7/stm/setup.h b/c7/stm/setup.h
new file mode 100644
--- /dev/null
+++ b/c7/stm/setup.h
@@ -0,0 +1,5 @@
+
+static char *setup_mmap(char *reason, int *map_fd);
+static void close_fd_mmap(int map_fd);
+static void setup_protection_settings(void);
+static pthread_t *_get_cpth(stm_thread_local_t *);
diff --git a/c7/stmgc.c b/c7/stmgc.c
--- a/c7/stmgc.c
+++ b/c7/stmgc.c
@@ -7,6 +7,7 @@
#include "stm/pages.h"
#include "stm/gcpage.h"
#include "stm/sync.h"
+#include "stm/setup.h"
#include "stm/largemalloc.h"
#include "stm/nursery.h"
#include "stm/contention.h"
More information about the pypy-commit
mailing list