[前][次][番号順一覧][スレッド一覧]

ruby-changes:66062

From: Peter <ko1@a...>
Date: Thu, 6 May 2021 06:54:43 +0900 (JST)
Subject: [ruby-changes:66062] b655a3fa5b (master): Fall back to sysconf to determine page size during runtime

https://git.ruby-lang.org/ruby.git/commit/?id=b655a3fa5b

From b655a3fa5b8d1a30565e19425c28a1cfd8631165 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Wed, 5 May 2021 21:06:56 +0000
Subject: Fall back to sysconf to determine page size during runtime

On some platforms the PAGE_SIZE macro does not exist so we can fall back
to `sysconf` to determine the page size at runtime.
---
 gc.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gc.c b/gc.c
index 721e244..90446d1 100644
--- a/gc.c
+++ b/gc.c
@@ -835,10 +835,12 @@ enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L835
 #define HEAP_PAGE_ALIGN (1 << HEAP_PAGE_ALIGN_LOG)
 #define HEAP_PAGE_SIZE HEAP_PAGE_ALIGN
 
-#if defined(HAVE_MMAP) && defined(PAGE_SIZE)
+#ifdef HAVE_MMAP
 # if HAVE_CONST_PAGE_SIZE
+/* If we have the HEAP_PAGE and it is a constant, then we can directly use it. */
 #  define USE_MMAP_ALIGNED_ALLOC (PAGE_SIZE <= HEAP_PAGE_SIZE)
 # else
+/* Otherwise, fall back to determining if we can use mmap during runtime. */
 #  define USE_MMAP_ALIGNED_ALLOC (use_mmap_aligned_alloc != false)
 
 static bool use_mmap_aligned_alloc;
@@ -3208,8 +3210,18 @@ Init_heap(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L3210
 {
     rb_objspace_t *objspace = &rb_objspace;
 
-#if defined(HAVE_MMAP) && defined(PAGE_SIZE) && !HAVE_CONST_PAGE_SIZE
+#if defined(HAVE_MMAP) && !HAVE_CONST_PAGE_SIZE
+    /* Need to determine if we can use mmap at runtime. */
+# ifdef PAGE_SIZE
+    /* If the PAGE_SIZE macro can be used. */
     use_mmap_aligned_alloc = PAGE_SIZE <= HEAP_PAGE_SIZE;
+# elif defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
+    /* If we can use sysconf to determine the page size. */
+    use_mmap_aligned_alloc = sysconf(_SC_PAGE_SIZE) <= HEAP_PAGE_SIZE;
+# else
+    /* Otherwise we can't determine the system page size, so don't use mmap. */
+    use_mmap_aligned_alloc = FALSE;
+# endif
 #endif
 
 #if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]