[pypy-commit] stmgc c8-small-uniform: Backed out changeset: a20e5e7e942c. I receive SIGBUS before running out of memory using the pwrite()-atomic-privatization. Investigate at some point.
Raemi
noreply at buildbot.pypy.org
Tue Sep 16 14:38:36 CEST 2014
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: c8-small-uniform
Changeset: r1388:7d8934d22965
Date: 2014-09-16 14:40 +0200
http://bitbucket.org/pypy/stmgc/changeset/7d8934d22965/
Log: Backed out changeset: a20e5e7e942c. I receive SIGBUS before running
out of memory using the pwrite()-atomic-privatization. Investigate
at some point.
diff --git a/c8/stm/core.h b/c8/stm/core.h
--- a/c8/stm/core.h
+++ b/c8/stm/core.h
@@ -32,6 +32,8 @@
#define FIRST_OLD_RM_PAGE (OLD_RM_START / 4096UL)
#define NB_READMARKER_PAGES (FIRST_OBJECT_PAGE - FIRST_READMARKER_PAGE)
+#define TMP_COPY_PAGE 1 /* HACK */
+
enum /* stm_flags */ {
GCFLAG_WRITE_BARRIER = _STM_GCFLAG_WRITE_BARRIER,
GCFLAG_HAS_SHADOW = 0x02,
diff --git a/c8/stm/pagecopy.h b/c8/stm/pagecopy.h
--- a/c8/stm/pagecopy.h
+++ b/c8/stm/pagecopy.h
@@ -1,2 +1,2 @@
-static void pagecopy(void *dest, const void *src) __attribute__((unused)); // 4096 bytes
+static void pagecopy(void *dest, const void *src); // 4096 bytes
diff --git a/c8/stm/pages.c b/c8/stm/pages.c
--- a/c8/stm/pages.c
+++ b/c8/stm/pages.c
@@ -1,8 +1,8 @@
#ifndef _STM_CORE_H_
# error "must be compiled via stmgc.c"
#endif
+#include <signal.h>
-#include <unistd.h>
/************************************************************/
static void setup_pages(void)
@@ -34,14 +34,21 @@
/* assert remappings follow the rule that page N in one segment
can only be remapped to page N in another segment */
- assert(((addr - stm_object_pages) / 4096UL - pgoff) % NB_PAGES == 0);
+ assert(IMPLY(((addr - stm_object_pages) / 4096UL) != TMP_COPY_PAGE,
+ ((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
}
@@ -108,15 +115,14 @@
attempt to group together many calls to d_remap_file_pages() in
succession) */
uintptr_t pagenum_in_file = NB_PAGES * segnum + pagenum;
+ char *tmp_page = stm_object_pages + TMP_COPY_PAGE * 4096UL;
+ /* first remap to TMP_PAGE, then copy stuff there (to the underlying
+ file page), then remap this file-page hopefully atomically to the
+ segnum's virtual page */
+ d_remap_file_pages(tmp_page, 4096, pagenum_in_file);
+ pagecopy(tmp_page, initialize_from);
+ write_fence();
+
char *new_page = stm_object_pages + pagenum_in_file * 4096UL;
-
- /* first write to the file page directly: */
- ssize_t written = pwrite(stm_object_pages_fd, initialize_from, 4096UL,
- pagenum_in_file * 4096UL);
- if (written != 4096)
- stm_fatalerror("pwrite didn't write the whole page: %zd", written);
-
- /* now remap virtual page in segment to the new file page */
- write_fence();
d_remap_file_pages(new_page, 4096, pagenum_in_file);
}
diff --git a/c8/stm/pages.h b/c8/stm/pages.h
--- a/c8/stm/pages.h
+++ b/c8/stm/pages.h
@@ -21,6 +21,7 @@
#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
diff --git a/c8/stm/setup.c b/c8/stm/setup.c
--- a/c8/stm/setup.c
+++ b/c8/stm/setup.c
@@ -2,11 +2,27 @@
# error "must be compiled via stmgc.c"
#endif
+#include <signal.h>
+#ifdef USE_REMAP_FILE_PAGES
+static char *setup_mmap(char *reason, int *ignored)
+{
+ char *result = mmap(NULL, TOTAL_MEMORY,
+ PROT_READ | PROT_WRITE,
+ MAP_PAGES_FLAGS, -1, 0);
+ if (result == MAP_FAILED)
+ stm_fatalerror("%s failed: %m", reason);
+
+ 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] = "/__stmgc_c8__";
+ char name[128];
/* Create the big shared memory object, and immediately unlink it.
There is a small window where if this process is killed the
@@ -35,6 +51,7 @@
{
close(map_fd);
}
+#endif
static void setup_protection_settings(void)
{
@@ -46,13 +63,19 @@
NULL accesses land. We mprotect it so that accesses fail. */
mprotect(segment_base, 4096, PROT_NONE);
+ /* TMP_COPY_PAGE is used for atomic privatization */
+ mprotect(segment_base + TMP_COPY_PAGE * 4096UL,
+ 4096UL, PROT_READ|PROT_WRITE);
+
/* Pages in range(2, FIRST_READMARKER_PAGE) are never used */
- if (FIRST_READMARKER_PAGE > 2)
- mprotect(segment_base + 2 * 4096,
- (FIRST_READMARKER_PAGE - 2) * 4096UL,
+ if (FIRST_READMARKER_PAGE > TMP_COPY_PAGE + 1)
+ mprotect(segment_base + (TMP_COPY_PAGE + 1) * 4096,
+ (FIRST_READMARKER_PAGE - TMP_COPY_PAGE - 1) * 4096UL,
PROT_NONE);
- /* STM_SEGMENT is in page 1 */
+ /* STM_SEGMENT */
+ mprotect(segment_base + ((uintptr_t)STM_SEGMENT / 4096UL) * 4096UL,
+ 4096UL, PROT_READ|PROT_WRITE);
}
}
@@ -60,11 +83,13 @@
void stm_setup(void)
{
/* Check that some values are acceptable */
- assert(4096 <= ((uintptr_t)STM_SEGMENT));
+ assert(TMP_COPY_PAGE > 0 && TMP_COPY_PAGE <= 1);
+ assert(TMP_COPY_PAGE * 4096 + 4096 <= ((uintptr_t)STM_SEGMENT));
assert((uintptr_t)STM_SEGMENT == (uintptr_t)STM_PSEGMENT);
assert(((uintptr_t)STM_PSEGMENT) + sizeof(*STM_PSEGMENT) <= FIRST_READMARKER_PAGE*4096);
assert(NB_SEGMENTS <= NB_SEGMENTS_MAX);
+ assert(TMP_COPY_PAGE < FIRST_READMARKER_PAGE);
assert(FIRST_READMARKER_PAGE * 4096UL <= READMARKER_START);
assert(READMARKER_START < READMARKER_END);
assert(READMARKER_END <= 4096UL * FIRST_OBJECT_PAGE);
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -34,7 +34,7 @@
uintptr_t nursery_end;
struct stm_thread_local_s *running_thread;
};
-#define STM_SEGMENT ((stm_segment_info_t *)4352)
+#define STM_SEGMENT ((stm_segment_info_t *)8192)
struct stm_shadowentry_s {
More information about the pypy-commit
mailing list