xash3d-fwgs
xash3d-fwgs copied to clipboard
Use mmap to reduce memory usage
https://github.com/FWGS/xash3d-fwgs/blob/ddc4d7666874ce050d33ba6cc5781f08180776c5/engine/common/mod_studio.c#L1093-L1096
Every model file loaded into memory with read+malloc+memcpy can be replaced with mmap, which helps to reduce physical memory usage for huge mods.
In theory, we could use MAP_PRIVATE here, but I'm unsure about compatibility issues it can bring.
We could make testing branch with such changes, but then why you even need to make models this big?
It can be useful in multiplayer mods with many weapon models like Counter Strike.
Our 1.6 GB apk has tons of models and sprites to load. Peak memory usage is 6GB (PSS) on Android and 2.6GB (Xcode) on iOS. Newest phone including even chinese phones with 8GB+ RAM can crash by OOM. We had tried these ways to reduce memory usage:
- mmap as titled to reduce physical RAM
- load textures only when bound to opengl to reduce VRAM and swap them out when unused
- calloc instead of malloc+memset to avoid all-zero dirty pages
- vm_copy instead of memcpy to kill redundant pages (darwin only)
- convert RGBA textures to ASTC format Maybe the most useful way is mmap here.