Skip to content

GHCi allocates a new adjustor on every keystroke

While debugging a linker issue I noticed that mmapForLinker maps a fresh page on every REPL keystroke. The backtrace is:

Thread 1 "ghc" hit Breakpoint 2, mmapForLinker (bytes=4096, prot=3, flags=32, fd=-1, offset=0) at rts/Linker.c:1077
1077       void *map_addr = NULL;
(gdb) bt
#0  mmapForLinker (bytes=4096, prot=3, flags=32, fd=-1, offset=0) at rts/Linker.c:1077
#1  0x0000000004a5e6b1 in mmapAnonForLinker (bytes=4096) at rts/Linker.c:1195
#2  0x0000000004a527c4 in allocateExecPage () at rts/ExecPage.c:13
#3  0x0000000004aac85d in createAdjustor (cconv=1, hptr=0x27, wptr=0x3bd4350 <zdterminfozm0zi4zi1zi4zdSystemziConsoleziTerminfoziBasezdterminfozzm0zzi4zzi1zzi4zuSystemzziConsolezziTerminfozziBasezumkCallback>, typeString=0x4be6de5 "W")
    at rts/adjustor/NativeAmd64.c:268
#4  0x0000000003bd0da5 in ?? ()
#5  0x0000004200419248 in ?? ()
#6  0x0000000000000000 in ?? ()

That is, terminfo allocates a new adjustor (and therefore a whole page of memory) with every keystroke. This seems quite rough.

Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information