The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #11046 from gasche/minor_heap_decommit_fix

minor bugfix in caml_reallocate_minor_heap

authored by

Gabriel Scherer and committed by
GitHub
a8bec243 e23c7c37

+45 -3
+45 -3
runtime/domain.c
··· 346 346 return Wsize_bsize(bs); 347 347 } 348 348 349 + /* The current minor heap layout is as follows: 350 + 351 + - A contiguous memory block of size [Minor_heap_max * Max_domains] 352 + is reserved by [caml_init_domains]. The boundaries of this 353 + reserved area are stored in the globals 354 + [caml_minor_heaps_base] 355 + and 356 + [caml_minor_heaps_base_end}. 357 + 358 + - Each domain gets a reserved section of this block of size 359 + [Minor_heap_max], whose boundaries are stored as 360 + [domain_self->minor_heap_base] 361 + and 362 + [domain_self->minor_heap_base_end] 363 + 364 + - Each domain then commits a segment of size 365 + [domain_state->minor_heap_wsz] 366 + starting at 367 + [domain_state->minor_heap_base] 368 + that it actually uses. 369 + 370 + This is done below in 371 + [caml_reallocate_minor_heap] 372 + which is called both at domain-initialization (by [create_domain]) 373 + and if a request comes to change the minor heap size. 374 + 375 + The boundaries of this committed memory area are 376 + [domain_state->young_start] 377 + and 378 + [domain_state->young_end]. 379 + */ 349 380 int caml_reallocate_minor_heap(asize_t wsize) 350 381 { 351 382 caml_domain_state* domain_state = Caml_state; 352 383 CAMLassert(domain_state->young_ptr == domain_state->young_end); 353 384 385 + CAMLassert( 386 + (/* unitialized minor heap */ 387 + domain_state->young_start == NULL 388 + && domain_state->young_end == NULL) 389 + || 390 + (/* initialized minor heap */ 391 + domain_state->young_start == (value*)domain_self->minor_heap_area 392 + && domain_state->young_end < (value*)domain_self->minor_heap_area_end)); 393 + 354 394 /* free old minor heap. 355 395 instead of unmapping the heap, we decommit it, so there's 356 396 no race whereby other code could attempt to reuse the memory. */ 357 397 caml_mem_decommit( 358 398 (void*)domain_self->minor_heap_area, 359 - domain_self->minor_heap_area_end - domain_self->minor_heap_area); 399 + (char*)domain_state->young_end - (char*)domain_state->young_start); 360 400 361 401 wsize = caml_norm_minor_heap_size(wsize); 362 402 ··· 482 522 goto init_signal_stack_failure; 483 523 } 484 524 485 - domain_state->young_start = domain_state->young_end = 486 - domain_state->young_ptr = 0; 525 + domain_state->young_start = 526 + domain_state->young_end = 527 + domain_state->young_ptr = NULL; 528 + 487 529 domain_state->minor_tables = caml_alloc_minor_tables(); 488 530 if(domain_state->minor_tables == NULL) { 489 531 goto alloc_minor_tables_failure;