From f941dd5a9f80616fc1461625bead4774da8ab9ae Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 6 May 2021 12:09:57 +0900 Subject: Reuse sysconf result --- gc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gc.c') diff --git a/gc.c b/gc.c index a1ed084d23..dcdc8fd4c8 100644 --- a/gc.c +++ b/gc.c @@ -3213,6 +3213,17 @@ Init_heap(void) { rb_objspace_t *objspace = &rb_objspace; +#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE) + /* If Ruby's heap pages are not a multiple of the system page size, we + * cannot use mprotect for the read barrier, so we must disable automatic + * compaction. */ + int pagesize; + pagesize = (int)sysconf(_SC_PAGE_SIZE); + if ((HEAP_PAGE_SIZE % pagesize) != 0) { + ruby_enable_autocompact = 0; + } +#endif + #if defined(HAVE_MMAP) && !HAVE_CONST_PAGE_SIZE && !defined(PAGE_MAX_SIZE) /* Need to determine if we can use mmap at runtime. */ # ifdef PAGE_SIZE @@ -3220,24 +3231,13 @@ Init_heap(void) 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; + use_mmap_aligned_alloc = pagesize <= 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) - /* If Ruby's heap pages are not a multiple of the system page size, we - * cannot use mprotect for the read barrier, so we must disable automatic - * compaction. */ - int pagesize; - pagesize = (int)sysconf(_SC_PAGE_SIZE); - if ((HEAP_PAGE_SIZE % pagesize) != 0) { - ruby_enable_autocompact = 0; - } -#endif - objspace->next_object_id = INT2FIX(OBJ_ID_INITIAL); objspace->id_to_obj_tbl = st_init_table(&object_id_hash_type); objspace->obj_to_id_tbl = st_init_numtable(); -- cgit v1.2.3