Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ AC_MSG_RESULT([$ABI])
AC_SUBST([ABI])



dnl
dnl Miscellaneous tools
dnl
Expand Down Expand Up @@ -195,6 +194,44 @@ AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([long long])


dnl Despite being 64-bit, the RISC-V architecture supports hardware
dnl MMUs and virtual memory layouts with fewer than the traditional
dnl 48 addressable bits:
dnl
dnl https://www.kernel.org/doc/html/next/riscv/vm-layout.html
dnl
dnl Here we detect only the most limited (SV39) of these, as GASMAN
dnl must be made aware of the limitation.
AS_CASE([$host], [riscv64*], [
AC_MSG_CHECKING([[for SV39 MMU (RISC-V)]])
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#define _BSD_SOURCE
#include <asm/hwprobe.h>
#include <sys/syscall.h>
#include <unistd.h>

int main(void) {
struct riscv_hwprobe p = {
.key = RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS,
};
if ((syscall(__NR_riscv_hwprobe, &p, 1, 0, NULL, 0) == 0)
&& (p.key != -1)
&& ((void*)p.value == (void*)0x4000000000)) {
return 0;
}
return 1;
}
]])], [
AC_MSG_RESULT([yes])
GAP_DEFINE([HAVE_SV39_MMU=1])
], [
AC_MSG_RESULT([no])
], [
AC_MSG_RESULT([no (cross-compiling)])
])
])


dnl
dnl User settings
Expand Down
9 changes: 9 additions & 0 deletions src/sysmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,18 @@ static void * SyAnonMMap(size_t size)
void *result;
size = SyRoundUpToPagesize(size);
#ifdef SYS_IS_64_BIT
#ifdef HAVE_SV39_MMU
/* On Linux (the only place we check for it), this MMU can only
* address 38 bits of virtual memory. The hint supplied to mmap()
* therefore needs to be much smaller than the default 16TB. Trial
* and error shows that 96GB works well enough. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's on your 128 GB machine though, isn't it? But will it still work if run in e.g. a 16 GB machine, or a 256 GB machine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only the offset within the virtual space and should not depend on the amount of physical RAM in the system. (I certainly don't have 16TB installed on the x86_64 box.)

I first tried 128GB (the halfway point in my VM space) but 96GB allowed me to extend the workspace much further. There is a trade-off between how much space to reserve for GASMAN vs. how much to leave for extensions to malloc. By choosing 96GB, I am limiting extensions to 96GB of usable RAM even though the machine has more available. But presently I find that less likely than the 100% chance that the images test suite wants to allocate 128GB.

The fact that this box has so much RAM on an SV39 MMU is an oddity. I don't know what the board designers were thinking, but the firmware is limited to 128GB, and I would guess that future boards (that can handle more physical RAM) will have more capable MMUs.

result = mmap((void *) (96L*1024*1024*1024), size,
PROT_READ|PROT_WRITE, GAP_MMAP_FLAGS, -1, 0);
#else
// The following is at 16 Terabyte:
result = mmap((void *) (16L*1024*1024*1024*1024), size,
PROT_READ|PROT_WRITE, GAP_MMAP_FLAGS, -1, 0);
#endif
if (result == MAP_FAILED) {
result = mmap(NULL, size, PROT_READ|PROT_WRITE,
GAP_MMAP_FLAGS, -1, 0);
Expand Down
Loading