X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fpsxmem.c;h=389bdba5166e491e345080abd03a448577f5faeb;hb=38e4048faeaccf7fdc6084f64866f2ea52bb97f1;hp=14e7a9e9478faf907c19a300896ac65adbc74ca4;hpb=5e282df80d579f9a19c77a655c2c0dda6dc2c7b4;p=pcsx_rearmed.git diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 14e7a9e9..389bdba5 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -44,22 +44,35 @@ static void * psxMapDefault(unsigned long addr, size_t size, int is_fixed, enum psxMapTag tag) { -#if !HAVE_MMAP void *ptr; - - ptr = malloc(size); +#if !P_HAVE_MMAP + ptr = calloc(1, size); return ptr ? ptr : MAP_FAILED; #else int flags = MAP_PRIVATE | MAP_ANONYMOUS; - return mmap((void *)(uintptr_t)addr, size, + ptr = mmap((void *)(uintptr_t)addr, size, PROT_READ | PROT_WRITE, flags, -1, 0); +#ifdef MADV_HUGEPAGE + if (size >= 2*1024*1024) { + if (ptr != MAP_FAILED && ((uintptr_t)ptr & (2*1024*1024 - 1))) { + // try to manually realign assuming bottom-to-top alloc + munmap(ptr, size); + addr = (uintptr_t)ptr & ~(2*1024*1024 - 1); + ptr = mmap((void *)(uintptr_t)addr, size, + PROT_READ | PROT_WRITE, flags, -1, 0); + } + if (ptr != MAP_FAILED) + madvise(ptr, size, MADV_HUGEPAGE); + } +#endif + return ptr; #endif } static void psxUnmapDefault(void *ptr, size_t size, enum psxMapTag tag) { -#if !HAVE_MMAP +#if !P_HAVE_MMAP free(ptr); #else munmap(ptr, size);