Skip to content

PARI: use PROT_NONE for unused virtual stack memory #21582

@jdemeyer

Description

@jdemeyer

This ticket is meant to improve support for Linux with vm.overcommit = 2.

In Sage, the PARI stack takes a large amount of virtual memory but only a small part is usually used.

When allocating memory, this memory is "committed" which means that it is made available as virtual memory. However, as long as a program is not using that memory, this costs nothing because the kernel does not need to make available actual memory (physical or swap) for it. This is different with vm.overcommit = 2: then all committed memory is counted. In that case, even unused virtual memory means that the system will have less memory available.

This can be solved by using the PROT_NONE flag of mmap(2). This means that the memory cannot be read nor written. In this case, the kernel does not commit this memory (it does show up as virtual memory in top). Note that this is not actually documented anywhere, but that is how it works.

This branch adds a PARI patch which implements this PROT_NONE trick. We first allocate the PARI stack in the usual way (so the maximum stack size is limited by the available virtual memory, which makes sense) but then uncommit most of the stack by reallocating it with PROT_NONE.

Finally, note that this patch does not functionally affect PARI (but I did run doctests just in case).

Upstream report: http://pari.math.u-bordeaux.fr/archives/pari-dev-1609/msg00008.html

Release manager: merge with #21637

Upstream: Reported upstream. Developers acknowledge bug.

CC: @sagetrac-bober @nexttime

Component: packages: standard

Author: Jeroen Demeyer

Branch: ccd9c1e

Reviewer: Jonathan Bober

Issue created by migration from https://trac.sagemath.org/ticket/21582

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions