This documentation is specific to VxWorks.
The erl_set_memory_block function/command initiates custom memory allocation for the Erlang emulator. It has to be called before the Erlang emulator is started and makes Erlang use one single large memory block for all memory allocation.
The memory within the block can be utilized by other tasks than Erlang. This is accomplished by calling the functions sys_alloc, sys_realloc and sys_free instead of malloc, realloc and free respectively.
The purpose of this is to avoid problems inherent in the VxWorks systems malloc library. The memory allocation within the large memory block avoids fragmentation by using an "address order first fit" algorithm. Another advantage of using a separate memory block is that resource reclamation can be made more easily when Erlang is stopped.
The erl_set_memory_block function is callable from any C program as an ordinary 10 argument function as well as from the commandline.
The function is called before Erlang is started to specify a large memory block where Erlang can maintain memory internally.
Parameters:
Return Value:
Returns 0 (OK) on success, otherwise a value <> 0.
Return Value:
Returns 0 (OK) on success, otherwise a value <> 0.
int erl_mem_info_get(MEM_PART_STATS *stats)
Parameter:
Return Value:
Returns 0 (OK) on success, otherwise a value <> 0
The memory block used by Erlang actually does not need to be inside the area known to ordinary malloc. It is possible to set the USER_RESERVED_MEM preprocessor symbol when compiling the wind kernel and then use user reserved memory for Erlang. Erlang can therefor utilize memory above the 32 Mb limit of VxWorks on the PowerPC architecture.
Example:
In config.h for the wind kernel:
#undef LOCAL_MEM_AUTOSIZE #undef LOCAL_MEM_SIZE #undef USER_RESERVED_MEM #define LOCAL_MEM_SIZE 0x05000000 #define USER_RESERVED_MEM 0x03000000
In the start-up script/code for the VxWorks node:
erl_set_memory_block(sysPhysMemTop()-sysMemTop(),sysMemTop(),0,0,1);
Setting the use_reclaim flag decreases performance of the system, but makes programming much easier. Other similar facilities are present in the Erlang system even without using a separate memory block. The routines called save_malloc, save_realloc and save_free provide the same facilities by using VxWorks own malloc. Similar routines exist for files, see the file reclaim.h in the distribution.