Align cache1d memory blocks to system page size

git-svn-id: https://svn.eduke32.com/eduke32@8072 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-09-02 05:55:32 +00:00 committed by Christoph Oelckers
parent e262135463
commit c835219de0
4 changed files with 24 additions and 5 deletions

View file

@ -1278,12 +1278,11 @@ char *Bstrlwr(char *);
char *Bstrupr(char *); char *Bstrupr(char *);
#endif #endif
////////// Miscellaneous ////////// ////////// Miscellaneous //////////
int Bgetpagesize(void);
uint32_t Bgetsysmemsize(void); uint32_t Bgetsysmemsize(void);
////////// PANICKING ALLOCATION WRAPPERS ////////// ////////// PANICKING ALLOCATION WRAPPERS //////////
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS

View file

@ -224,8 +224,9 @@ int32_t cacheFindBlock(int32_t newbytes, int32_t *besto, int32_t *bestz)
void cacheAllocateBlock(intptr_t* newhandle, int32_t newbytes, char* newlockptr) void cacheAllocateBlock(intptr_t* newhandle, int32_t newbytes, char* newlockptr)
{ {
// Make all requests a multiple of 16 bytes // Make all requests a multiple of the system page size
newbytes = (newbytes + 15) & ~0xf; int const pageSize = Bgetpagesize();
newbytes = (newbytes + pageSize-1) & ~(pageSize-1);
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
if (EDUKE32_PREDICT_FALSE(!newlockptr || *newlockptr == 0)) if (EDUKE32_PREDICT_FALSE(!newlockptr || *newlockptr == 0))

View file

@ -577,6 +577,25 @@ char *Bstrupr(char *s)
} }
#endif #endif
#define BMAXPAGESIZE 8192
int Bgetpagesize(void)
{
static int pageSize = -1;
if (pageSize == -1)
{
#ifdef _WIN32
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
pageSize = system_info.dwPageSize;
#else
pageSize = sysconf(_SC_PAGESIZE);
#endif
}
return (unsigned)pageSize < BMAXPAGESIZE ? pageSize : BMAXPAGESIZE;
}
// //
// Bgetsysmemsize() -- gets the amount of system memory in the machine // Bgetsysmemsize() -- gets the amount of system memory in the machine

View file

@ -603,7 +603,7 @@ int32_t artLoadFiles(const char *filename, int32_t askedsize)
//cachesize = min((int32_t)((Bgetsysmemsize()/100)*60),max(artsize,askedsize)); //cachesize = min((int32_t)((Bgetsysmemsize()/100)*60),max(artsize,askedsize));
cachesize = (Bgetsysmemsize() <= (uint32_t)askedsize) ? (int32_t)((Bgetsysmemsize() / 100) * 60) : askedsize; cachesize = (Bgetsysmemsize() <= (uint32_t)askedsize) ? (int32_t)((Bgetsysmemsize() / 100) * 60) : askedsize;
pic = Xaligned_alloc(16, cachesize); pic = Xaligned_alloc(Bgetpagesize(), cachesize);
cacheInitBuffer((intptr_t) pic, cachesize); cacheInitBuffer((intptr_t) pic, cachesize);
artUpdateManifest(); artUpdateManifest();