Bill Allombert on Wed, 12 Oct 2016 23:11:09 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Use PROT_NONE for unused virtual stack memory


On Sat, Sep 24, 2016 at 08:33:28AM +0200, Jeroen Demeyer wrote:
> Hello pari-dev,
> 
> In attachment you find a patch to change the way how stack memory is
> allocated with mmap(). It is meant to improve support for Linux with
> vm.overcommit = 2 [1] and still allow a reasonably large parisizemax in that
> case.
> diff --git a/src/language/init.c b/src/language/init.c
> index 439e279..be87a79 100644
> --- a/src/language/init.c
> +++ b/src/language/init.c
> @@ -624,14 +624,11 @@ pari_add_defaults_module(entree *ep)
>  #ifndef MAP_ANONYMOUS
>  #define MAP_ANONYMOUS MAP_ANON
>  #endif
> -#ifndef MAP_NORESERVE
> -#define MAP_NORESERVE 0
> -#endif
>  static void *
>  pari_mainstack_malloc(size_t size)
>  {
>    void *b = mmap(NULL, size, PROT_READ|PROT_WRITE,
> -                             MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,-1,0);
> +                             MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
>    return (b == MAP_FAILED) ? NULL: b;
>  }

Is it correct ? It seems to me that we want to use PROT_NONE here as
well, as you do in config/has_mmap.c.

Also, I think I would prefer if your patch would keep the
function 'pari_mainstack_mreset' which would do something like
mmap(s, size, PROT_NONE, MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
and maybe add a function 'pari_mainstack_mextend'
that would do
mprotect(s, size(void*)alignbot, st->top - alignbot, PROT_READ|PROT_WRITE))

Cheers,
Bill.