Re: Limiting malloc to the low 2GB?
On Tue, 29 Nov 2022, Valery Ushakov wrote: Me too :) But that works for now. Will need to RTFS. Would setrlimit(RLIMIT_AS), setrlimit(RLIMIT_DATA) work for you? -RVP
Re: Limiting malloc to the low 2GB?
On Mon, Nov 28, 2022 at 23:22:08 +, RVP wrote: > On Tue, 29 Nov 2022, Valery Ushakov wrote: > > > Turns out you can use MALLOC_CONF="dss:primary" to make (the new) > > jemalloc prefer sbrk(2). > > Yes, I saw that, but, I wasn't sure if that setting meant a) always > use sbrk() or b) prefer sbrk(), then, fall-back to mmap() (typically > for very large allocations). Me too :) But that works for now. Will need to RTFS. -uwe
Re: Limiting malloc to the low 2GB?
On Tue, 29 Nov 2022, Valery Ushakov wrote: Turns out you can use MALLOC_CONF="dss:primary" to make (the new) jemalloc prefer sbrk(2). Yes, I saw that, but, I wasn't sure if that setting meant a) always use sbrk() or b) prefer sbrk(), then, fall-back to mmap() (typically for very large allocations). -RVP
Re: Limiting malloc to the low 2GB?
On Mon, Nov 28, 2022 at 21:45:40 +, RVP wrote: > On Mon, 28 Nov 2022, Valery Ushakov wrote: > > > Do we have a way to tell malloc on a 32-bit system to allocate memory > > only below the 2GB boundary (on i386, including when run under amd64)? > > I'm trying to port a(n old) program that wants to use the sign bit for > > its internal purposes. I guess one option would be to prevent malloc > > from using mmap (and disable alsr?) so that only sbrk (in the low 2GB) > > is used. > > The standard jemalloc in the system has a compile-time flag to do this > `--with-lg-vaddr=31'. No run-time setting possible from what I can see. > Or, you could compile the program against the old `src/lib/libbsdmalloc' > which only uses sbrk(). Turns out you can use MALLOC_CONF="dss:primary" to make (the new) jemalloc prefer sbrk(2). He man page documents that you can aslo use const char *malloc_conf = "..."; in your program, but the variable you actually have to use is __je_malloc_conf. There is __weak_alias(malloc_conf, __je_malloc_conf) but that doesn't work across DSO boundaries, I guess. -uwe
Re: Limiting malloc to the low 2GB?
On Mon, 28 Nov 2022, Valery Ushakov wrote: Do we have a way to tell malloc on a 32-bit system to allocate memory only below the 2GB boundary (on i386, including when run under amd64)? I'm trying to port a(n old) program that wants to use the sign bit for its internal purposes. I guess one option would be to prevent malloc from using mmap (and disable alsr?) so that only sbrk (in the low 2GB) is used. The standard jemalloc in the system has a compile-time flag to do this `--with-lg-vaddr=31'. No run-time setting possible from what I can see. Or, you could compile the program against the old `src/lib/libbsdmalloc' which only uses sbrk(). -RVP
Re: Limiting malloc to the low 2GB?
In article , Valery Ushakov wrote: >Do we have a way to tell malloc on a 32-bit system to allocate memory >only below the 2GB boundary (on i386, including when run under amd64)? >I'm trying to port a(n old) program that wants to use the sign bit for >its internal purposes. I guess one option would be to prevent malloc >from using mmap (and disable alsr?) so that only sbrk (in the low 2GB) >is used. > >Suggestions are appreciated. Perhaps this is also affected by uvm TOPDOWN. I think that this might need kernel support... christos
Limiting malloc to the low 2GB?
Do we have a way to tell malloc on a 32-bit system to allocate memory only below the 2GB boundary (on i386, including when run under amd64)? I'm trying to port a(n old) program that wants to use the sign bit for its internal purposes. I guess one option would be to prevent malloc from using mmap (and disable alsr?) so that only sbrk (in the low 2GB) is used. Suggestions are appreciated. -uwe