Andreas Klebinger pushed to branch wip/andreask/9.10.4-batch1 at Glasgow Haskell Compiler / GHC
Commits:
-
f6a2555b
by Ben Gamari at 2026-10-23T09:38:10+02:00
-
e81d64e1
by Ben Gamari at 2026-10-23T09:38:25+02:00
-
44b8c8f0
by Ben Gamari at 2026-10-23T09:38:37+02:00
2 changed files:
Changes:
| ... | ... | @@ -994,8 +994,8 @@ findPtr(P_ p, int follow) |
| 994 | 994 | {
|
| 995 | 995 | uint32_t g, n;
|
| 996 | 996 | bdescr *bd;
|
| 997 | - const int arr_size = 1024;
|
|
| 998 | - StgPtr arr[arr_size];
|
|
| 997 | +#define ARR_SIZE 1024
|
|
| 998 | + StgPtr arr[ARR_SIZE];
|
|
| 999 | 999 | int i = 0;
|
| 1000 | 1000 | searched = 0;
|
| 1001 | 1001 | |
| ... | ... | @@ -1005,24 +1005,24 @@ findPtr(P_ p, int follow) |
| 1005 | 1005 | // just before a block is used.
|
| 1006 | 1006 | for (n = 0; n < getNumCapabilities(); n++) {
|
| 1007 | 1007 | bd = nurseries[i].blocks;
|
| 1008 | - i = findPtrBlocks(p,bd,arr,arr_size,i);
|
|
| 1009 | - if (i >= arr_size) return;
|
|
| 1008 | + i = findPtrBlocks(p,bd,arr,ARR_SIZE,i);
|
|
| 1009 | + if (i >= ARR_SIZE) return;
|
|
| 1010 | 1010 | }
|
| 1011 | 1011 | #endif
|
| 1012 | 1012 | |
| 1013 | 1013 | for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
|
| 1014 | 1014 | bd = generations[g].blocks;
|
| 1015 | - i = findPtrBlocks(p,bd,arr,arr_size,i);
|
|
| 1015 | + i = findPtrBlocks(p,bd,arr,ARR_SIZE,i);
|
|
| 1016 | 1016 | bd = generations[g].large_objects;
|
| 1017 | - i = findPtrBlocks(p,bd,arr,arr_size,i);
|
|
| 1018 | - if (i >= arr_size) return;
|
|
| 1017 | + i = findPtrBlocks(p,bd,arr,ARR_SIZE,i);
|
|
| 1018 | + if (i >= ARR_SIZE) return;
|
|
| 1019 | 1019 | for (n = 0; n < getNumCapabilities(); n++) {
|
| 1020 | 1020 | i = findPtrBlocks(p, gc_threads[n]->gens[g].part_list,
|
| 1021 | - arr, arr_size, i);
|
|
| 1021 | + arr, ARR_SIZE, i);
|
|
| 1022 | 1022 | i = findPtrBlocks(p, gc_threads[n]->gens[g].todo_bd,
|
| 1023 | - arr, arr_size, i);
|
|
| 1023 | + arr, ARR_SIZE, i);
|
|
| 1024 | 1024 | }
|
| 1025 | - if (i >= arr_size) return;
|
|
| 1025 | + if (i >= ARR_SIZE) return;
|
|
| 1026 | 1026 | }
|
| 1027 | 1027 | if (follow && i == 1) {
|
| 1028 | 1028 | debugBelch("-->\n");
|
| ... | ... | @@ -585,8 +585,14 @@ void *osReserveHeapMemory(void *startAddressPtr, W_ *len) |
| 585 | 585 | }
|
| 586 | 586 | #endif
|
| 587 | 587 | |
| 588 | +#define MAX_ATTEMPTS 256
|
|
| 589 | + void *bad_allocs[MAX_ATTEMPTS];
|
|
| 590 | + size_t bad_alloc_lens[MAX_ATTEMPTS];
|
|
| 591 | + memset(bad_allocs, 0, sizeof(void*) * MAX_ATTEMPTS);
|
|
| 592 | + memset(bad_alloc_lens, 0, sizeof(size_t) * MAX_ATTEMPTS);
|
|
| 593 | + |
|
| 588 | 594 | attempt = 0;
|
| 589 | - while (1) {
|
|
| 595 | + while (attempt < MAX_ATTEMPTS) {
|
|
| 590 | 596 | *len &= ~MBLOCK_MASK;
|
| 591 | 597 | |
| 592 | 598 | if (*len < MBLOCK_SIZE) {
|
| ... | ... | @@ -611,18 +617,35 @@ void *osReserveHeapMemory(void *startAddressPtr, W_ *len) |
| 611 | 617 | } else if ((W_)at >= minimumAddress) {
|
| 612 | 618 | // Success! We were given a block of memory starting above the 8 GB
|
| 613 | 619 | // mark, which is what we were looking for.
|
| 614 | - |
|
| 615 | 620 | break;
|
| 616 | 621 | } else {
|
| 617 | 622 | // We got addressing space but it wasn't above the 8GB mark.
|
| 618 | - // Try again.
|
|
| 619 | - if (munmap(at, *len) < 0) {
|
|
| 620 | - sysErrorBelch("unable to release reserved heap");
|
|
| 623 | + // Free any portion *above* 8GB and hang on to the rest to increase
|
|
| 624 | + // the likelihood that we get a suitable allocation next iteration.
|
|
| 625 | + uintptr_t end = (W_) at + *len;
|
|
| 626 | + bad_allocs[attempt] = at;
|
|
| 627 | + if (end > minimumAddress) {
|
|
| 628 | + if (munmap((void *) minimumAddress, end - minimumAddress) < 0) {
|
|
| 629 | + sysErrorBelch("unable to release high portion of low memory reservation");
|
|
| 630 | + }
|
|
| 631 | + bad_alloc_lens[attempt] = minimumAddress - (W_) at;
|
|
| 632 | + } else {
|
|
| 633 | + bad_alloc_lens[attempt] = *len;
|
|
| 621 | 634 | }
|
| 622 | 635 | }
|
| 623 | 636 | attempt++;
|
| 624 | 637 | }
|
| 625 | 638 | |
| 639 | + for (int i=0; i < MAX_ATTEMPTS; i++) {
|
|
| 640 | + if (bad_allocs[i] != NULL && munmap(bad_allocs[i], bad_alloc_lens[i]) < 0) {
|
|
| 641 | + sysErrorBelch("unable to release reserved heap");
|
|
| 642 | + }
|
|
| 643 | + }
|
|
| 644 | + |
|
| 645 | + if (at == NULL) {
|
|
| 646 | + sysErrorBelch("failed to reserve heap memory");
|
|
| 647 | + }
|
|
| 648 | + |
|
| 626 | 649 | return at;
|
| 627 | 650 | }
|
| 628 | 651 |