Memory Management in webMAN MOD: MAX+, MIN+, and Custom VSH Container Allocation
webMAN MOD manages PS3 VSH memory through selectable buffer-size profiles (MIN+, MAX+), a custom SDK allocator that replaces standard libc functions, and optional allocation from four VSH memory containers (app, bg, fg, debug).
The aldostools/webman-mod project runs as a plugin inside the PlayStation 3's Virtual Shell (VSH) process, where it must operate within strict memory constraints—approximately 64 MiB total VSH RAM with only about 3 MiB available for user-code allocation. To maximize stability and functionality within these limits, the implementation uses three complementary mechanisms: footprint-based buffer profiles, a redirected memory allocator, and container-specific heap isolation.
Buffer-Size Profiles: MIN+, MAX+, and Footprint Selection
The footprint value stored in webman_config->foot determines how much RAM webMAN MOD reserves for its internal caches. The function set_buffer_sizes(u8 footprint) in include/init/buffer_size.h maps this value to specific buffer dimensions for game lists, FTP caches, and DVD directories.
Understanding the MIN+ Profile (512 KB)
When footprint == 3, webMAN MOD enters the MIN+ profile, allocating a 512 KB base buffer (BUFFER_SIZE_ALL). This configuration reduces memory consumption compared to standard or MAX profiles while maintaining sufficient space for PS3 game listings. The MIN+ profile is ideal for systems running multiple concurrent plugins where VSH memory is heavily contested.
// include/init/buffer_size.h
static u32 get_buffer_size(u8 footprint)
{
if (footprint == 3) // MIN+ profile
return (_512KB_);
// ... additional profile handling
}
Understanding the MAX+ Profile (1280 KB+)
The MAX profile activates when footprint == 2 or footprint >= 4, establishing a 1280 KB base allocation. MAX+ refers to this MAX profile combined with additional per-type buffer boosts when users force larger containers (such as USE_2MB or USE_3MB flags). In this mode, webMAN MOD allocates significantly more memory to specific subsystems—up to 768 KB for individual buffers like BUFFER_SIZE_PSX or BUFFER_SIZE_PSP—while potentially reducing auxiliary buffers (such as 2× reduction for FTP and 4× for DVD lists) to maintain overall footprint constraints.
Runtime Buffer Allocation
The selected profile dynamically sizes these global buffers declared in include/init/buffer_size.h:
BUFFER_SIZE_PSX: 32 KB (MIN) → 256-768 KB (MAX+)BUFFER_SIZE_PSP: 32 KB (MIN) → 64-768 KB (MAX+)BUFFER_SIZE_PS2: 64 KB (MIN) → 128-768 KB (MAX+)BUFFER_SIZE_DVD: 64 KB (MIN) → 192-768 KB (MAX+)BUFFER_SIZE_FTP: 128 KB (fixed in MIN) → 256 KB (MAX)
These values are read at runtime via get_meminfo() and allocated through the custom allocator described below.
Custom Allocator: Routing malloc to the PS3 SDK
Rather than using the standard C library, webMAN MOD intercepts allocation calls and redirects them to the PlayStation 3 SDK's heap implementation. The header vsh/allocator.h defines macros that replace standard functions with SDK-specific symbols:
// vsh/allocator.h
extern void *allocator_759E0635(size_t size); // malloc()
#define malloc allocator_759E0635
extern void allocator_77A602DD(void *ptr); // free()
#define free allocator_77A602DD
extern void *allocator_A72A7595(size_t nitems, size_t size); // calloc()
#define calloc allocator_A72A7595
extern void *allocator_F7A14A22(void *ptr, size_t size); // realloc()
#define realloc allocator_F7A14A22
This design ensures all memory originates from the VSH heap, avoiding fragmentation and respecting the console's internal memory-limit checks. Source files call standard names (malloc, free), but the preprocessor transparently rewrites them to SDK-provided functions.
VSH Memory Container Allocation
PS3 VSH exposes four distinct memory containers: app (1), debug (2), fg (foreground, 3), and bg (background, 4). The function vsh_E7C34044(int mc_id) in vsh/vsh.h returns a handle to the requested container:
// vsh/vsh.h
extern int32_t vsh_E7C34044(int32_t mc_id);
// mc_id: 0=game, 1=app, 2=debug, 3=fg, 4=bg
Selecting Containers via vsh_mc Configuration
Users specify their preferred container through the vsh_mc field in include/init/wm_config.h. This unsigned 8-bit value maps directly to container IDs:
// include/init/wm_config.h
typedef struct {
/* ... other fields ... */
u8 vsh_mc; // 0=none, 1=app, 2=debug, 3=fg, 4=bg
/* ... */
} wm_config_t;
Setting vsh_mc = 4 forces webMAN MOD to allocate from the background container, which typically experiences less contention than foreground or application containers on heavily loaded systems.
Implementing Custom PRX Heaps
Projects requiring dedicated memory—such as the VSH Menu (vsh_menu/mem.c) or Video Recorder (video_rec/main.c)—implement container-aware initialization:
// Example from vsh_menu/mem.c
int32_t mc = vsh_E7C34044(1); // request the "app" container
if (mc >= 0)
{
// Allocate heap inside container using custom malloc
void *prx_heap = malloc(BUFFER_SIZE_ALL);
// ...
}
Summary
- MIN+ profile (
footprint = 3) allocates 512 KB base buffers for memory-constrained environments with multiple plugins. - MAX+ profile (
footprint >= 4) provides 1280 KB+ allocations with boosted per-type buffers for game lists, FTP, and DVD caches. - Custom allocator in
vsh/allocator.hredirectsmalloc,free,calloc, andreallocto PS3 SDK functions, ensuring VSH heap compatibility. - Memory containers (
app,bg,fg,debug) are selectable via thevsh_mcconfiguration field, isolating webMAN MOD's heap from other VSH components.
Frequently Asked Questions
What is the difference between MIN+ and MAX+ in webMAN MOD?
MIN+ (512 KB base) minimizes RAM usage for systems running many plugins, while MAX+ (1280 KB base) maximizes cache sizes for game lists and network operations at the cost of higher VSH memory consumption. MAX+ also enables larger per-type buffers when combined with 2 MB or 3 MB container flags.
How do I change the memory container used by webMAN MOD?
Modify the vsh_mc value in wm_config.bin (or the in-memory wm_config structure): set it to 1 for app, 2 for debug, 3 for foreground, or 4 for background. This field is defined in include/init/wm_config.h and read during PRX initialization.
Why does webMAN MOD use a custom allocator instead of standard libc?
The custom allocator defined in vsh/allocator.h routes allocations to the PS3 SDK's allocator_* functions, ensuring memory comes from the same VSH heap used by system PRXs. This prevents heap fragmentation and ensures compatibility with the console's memory protection mechanisms.
What is the maximum memory webMAN MOD can allocate on PS3?
While the PS3 VSH process has approximately 64 MiB total RAM, webMAN MOD is constrained to roughly 3 MiB of user-code allocation. The MAX+ profile with USE_3MB flags approaches this limit by allocating up to 3 MB for combined buffers, though practical limits vary based on firmware version and concurrent plugins.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →