cartesi / machine-emulator

The off-chain implementation of the Cartesi Machine
GNU Lesser General Public License v3.0
58 stars 32 forks source link

Use Sv39 address spacing by default to support nodejs and improve performance #196

Closed edubart closed 4 months ago

edubart commented 4 months ago

Currently the machine is using Sv57 virtual memory address spacing (5 level), however nodejs does not work with Sv57, furthermore address translation with a 5 level has more overhead on TLB misses than Sv39 which only has 3 levels.

I checked there is only two ways to force using Sv39 in recent kernel:

  1. Add no4lvl to bootargs
  2. Disable Sv48 and Sv57 modes in satp CSR.

While option 2. would be optimal in terms of performance, I decided to go for 1. in case a dapp wants to remove no4lvl from bootargs to map more 512GB to virtual memory.

Looks like mmu-type: riscv,sv39 in DTB is ignored in recent kernels, but I left the entry there to keep supporting old kernels.