ruby-changes:63528
From: Aaron <ko1@a...>
Date: Fri, 6 Nov 2020 01:52:09 +0900 (JST)
Subject: [ruby-changes:63528] 68a3a2d90f (master): take VM lock when mutating the heap
https://git.ruby-lang.org/ruby.git/commit/?id=68a3a2d90f From 68a3a2d90f96b46e5c20659ea3eef3f554fbf542 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 5 Nov 2020 08:51:40 -0800 Subject: take VM lock when mutating the heap diff --git a/gc.c b/gc.c index abc311a..1c7945a 100644 --- a/gc.c +++ b/gc.c @@ -8524,29 +8524,33 @@ gc_sort_heap_by_empty_slots(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L8524 gc_rest(objspace); - list_for_each(&heap_eden->pages, page, page_node) { - page_list[i++] = page; - GC_ASSERT(page != NULL); - } - GC_ASSERT(total_pages > 0); - GC_ASSERT((size_t)i == total_pages); + RB_VM_LOCK_ENTER(); + { + list_for_each(&heap_eden->pages, page, page_node) { + page_list[i++] = page; + GC_ASSERT(page != NULL); + } + GC_ASSERT(total_pages > 0); + GC_ASSERT((size_t)i == total_pages); - /* Sort the heap so "filled pages" are first. `heap_add_page` adds to the - * head of the list, so empty pages will end up at the start of the heap */ - ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_free_slots, NULL); + /* Sort the heap so "filled pages" are first. `heap_add_page` adds to the + * head of the list, so empty pages will end up at the start of the heap */ + ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_free_slots, NULL); - /* Reset the eden heap */ - list_head_init(&objspace->eden_heap.pages); - heap_eden->free_pages = NULL; + /* Reset the eden heap */ + list_head_init(&objspace->eden_heap.pages); + heap_eden->free_pages = NULL; - for (i = 0; i < total_pages; i++) { - list_add(&heap_eden->pages, &page_list[i]->page_node); - if (page_list[i]->free_slots != 0) { - heap_add_freepage(heap_eden, page_list[i]); + for (i = 0; i < total_pages; i++) { + list_add(&heap_eden->pages, &page_list[i]->page_node); + if (page_list[i]->free_slots != 0) { + heap_add_freepage(heap_eden, page_list[i]); + } } - } - free(page_list); + free(page_list); + } + RB_VM_LOCK_LEAVE(); return Qnil; } @@ -8556,7 +8560,11 @@ gc_double_heap_size(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L8560 { rb_objspace_t *objspace = &rb_objspace; - heap_add_pages(objspace, heap_eden, heap_allocated_pages); + RB_VM_LOCK_ENTER(); + { + heap_add_pages(objspace, heap_eden, heap_allocated_pages); + } + RB_VM_LOCK_LEAVE(); return Qnil; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/