Skip to content

Commit

Permalink
vmalloc: better detect default region size on Linux
Browse files Browse the repository at this point in the history
This is a Linux-specific fix for vmalloc from OpenSUSE, for what
that's still worth; we're not going to keep using vmalloc long term.
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-vm.dif
  • Loading branch information
McDutchie committed Feb 2, 2021
1 parent e2c2753 commit 3002c41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/libast/vmalloc/vmhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ extern void _vmmessage _ARG_((const char*, long, const char*, long));
#endif /*DEBUG*/

#define VMPAGESIZE 8192
#if defined(__linux__) && !defined(_lib_getpagesize)
#define _lib_getpagesize 1
#endif
#if _lib_getpagesize
#define GETPAGESIZE(x) ((x) ? (x) : ((x)=getpagesize()) )
#else
Expand Down
11 changes: 11 additions & 0 deletions src/lib/libast/vmalloc/vmmopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ void _STUB_vmmapopen(){}
/* magic word signaling file/segment is ready */
#define MM_MAGIC ((unsigned int)(('P'<<24) | ('&'<<16) | ('N'<<8) | ('8')) )

#ifndef __linux__
/* default minimum region size */
#define MM_MINSIZE (64*_Vmpagesize)
#endif

/* macros to get the data section and size */
#define MMHEAD(file) ROUND(sizeof(Mmvm_t)+strlen(file), ALIGN)
Expand Down Expand Up @@ -167,9 +169,18 @@ static int mminit(Mmdisc_t* mmdc)
if(mmdc->mmvm) /* already done this */
return 0;

#ifndef __linux__
/* fixed size region so make it reasonably large */
if((size = mmdc->size) < MM_MINSIZE )
size = MM_MINSIZE;
#else /* on Linux */
if (sizeof(void*) > 32)
extent = ROUND(0x80000,_Vmpagesize);
else
extent = ROUND(0x40000,_Vmpagesize);
if((size = mmdc->size) < extent)
size = extent;
#endif
size += MMHEAD(mmdc->file) + ALIGN;
size = ROUND(size, _Vmpagesize);

Expand Down

0 comments on commit 3002c41

Please sign in to comment.