Skip to content

Commit 5069d91

Browse files
committed
Reduce allocation to 512MB not 1G
1 parent d857ef7 commit 5069d91

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

overlays/patches/ghc/ghc-9.6-linker-pool-allocator.patch

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ index bab2ca3..5c9608c 100644
1616
+++ b/rts/linker/Elf.c
1717
@@ -131,6 +131,56 @@
1818
https://refspecs.linuxfoundation.org/elf/gabi4+/contents.html
19-
19+
2020
*/
2121
+void * memPoolAlloc(SectionKind kind, StgWord size);
2222
+
@@ -26,21 +26,21 @@ index bab2ca3..5c9608c 100644
2626
+
2727
+void memPoolProtect( void ) {
2828
+ if(__pool != NULL) {
29-
+ mprotect(__pool, 512*1024*1024, PROT_READ | PROT_WRITE);
30-
+ mprotect((void*)((uintptr_t)__pool + 512*1024*1024), 512*1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC);
29+
+ mprotect(__pool, 256*1024*1024, PROT_READ | PROT_WRITE);
30+
+ mprotect((void*)((uintptr_t)__pool + 256*1024*1024), 256*1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC);
3131
+ }
3232
+}
3333
+
3434
+void * memPoolAlloc(SectionKind kind, StgWord size) {
3535
+ if(__pool == NULL) {
3636
+ // allocate 1 GB of virtual memory.
37-
+ __pool = mmapAnonForLinker(1024*1024*1024);
37+
+ __pool = mmapAnonForLinker(512*1024*1024);
3838
+ if(__pool == NULL) {
3939
+ printf("Failed to allocate memory pool\n");
4040
+ fflush(stdout);
4141
+ return NULL;
4242
+ }
43-
+ __pool_rw_offset = (void*)((uintptr_t)__pool + 512*1024*1024);
43+
+ __pool_rw_offset = (void*)((uintptr_t)__pool + 256*1024*1024);
4444
+ __pool_rx_offset = __pool_rw_offset;
4545
+ }
4646
+ // align to 64 bytes
@@ -51,7 +51,7 @@ index bab2ca3..5c9608c 100644
5151
+ ret = __pool_rx_offset;
5252
+ // printf("Allocated RX %p\n", ret);
5353
+ __pool_rx_offset = (void*)((uintptr_t)__pool_rx_offset + alignedSize);
54-
+ if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + 1024*1024*1024) {
54+
+ if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + 512*1024*1024) {
5555
+ printf("Out of memory pool\n");
5656
+ fflush(stdout);
5757
+ return NULL;
@@ -68,7 +68,7 @@ index bab2ca3..5c9608c 100644
6868
+ }
6969
+ return ret;
7070
+}
71-
71+
7272
#if defined(SHN_XINDEX)
7373
/* global variable which address is used to signal an uninitialised shndx_table */
7474
@@ -813,7 +863,8 @@ ocGetNames_ELF ( ObjectCode* oc )
@@ -84,11 +84,11 @@ index bab2ca3..5c9608c 100644
8484
@@ -860,7 +911,8 @@ ocGetNames_ELF ( ObjectCode* oc )
8585
unsigned nstubs = numberOfStubsForSection(oc, i);
8686
unsigned stub_space = STUB_SIZE * nstubs;
87-
87+
8888
- void * mem = mmapAnonForLinker(size+stub_space);
8989
+ void * mem = memPoolAlloc(kind, stub_space + size);
9090
+ // void * mem = mmapAnonForLinker(size+stub_space);
91-
91+
9292
if( mem == MAP_FAILED ) {
9393
barf("failed to mmap allocated memory to load section %d. "
9494
@@ -967,7 +1019,8 @@ ocGetNames_ELF ( ObjectCode* oc )
@@ -104,12 +104,12 @@ index bab2ca3..5c9608c 100644
104104
@@ -2020,7 +2073,8 @@ ocResolve_ELF ( ObjectCode* oc )
105105
ocFlushInstructionCache( oc );
106106
#endif
107-
107+
108108
- return ocMprotect_Elf(oc);
109109
+ // return ocMprotect_Elf(oc);
110110
+ return true;
111111
}
112-
112+
113113
/*
114114
diff --git a/rts/linker/Elf.h b/rts/linker/Elf.h
115115
index 2b9ad87..cf7a541 100644
@@ -120,5 +120,5 @@ index 2b9ad87..cf7a541 100644
120120
void freeNativeCode_ELF ( ObjectCode *nc );
121121
void *loadNativeObj_ELF ( pathchar *path, char **errmsg );
122122
+void memPoolProtect ( void );
123-
123+
124124
#include "EndPrivate.h"

0 commit comments

Comments
 (0)