Continuous Memory Allocation Details
All modern operating systems use a very complex memory management strategy that strictly separates between physical memory, kernel memory and user memory. The memory management is based on memory pages (normally 4 kByte = 4096 Bytes). All software only sees virtual memory that is translated into physical memory addresses by a memory management unit based on the mentioned pages.
This will lead to the circumstance that although a user program allocated a larger memory block (for example 1 MByte) and it sees the whole 1 MByte as a virtually continuous memory area this memory is physically located as spread 4 kByte pages all over the physical memory. No problem for the user program as the memory management unit will simply translate the virtual continuous addresses to the physically spread pages totally transparent for the user program.
When using this virtual memory for a DMA transfer things become more complicated. The DMA engine of any hardware can only access physical addresses. As a result the DMA engine has to access each 4 kByte page separately. This is done through the Scatter-Gather list. This list is simply a linked list of the physical page addresses which represent the user buffer. All translation and set-up of the Scatter-Gather list is done inside the driver without being seen by the user. Although the Scatter-Gather DMA transfer is an advanced and powerful technology it has one disadvantage: For each transferred memory page of data it is necessary to also load one Scatter-Gather entry (which is 16 bytes on 32 bit systems and 32 bytes on 64 bit systems). The little overhead to transfer (16/32 bytes in relation to 4096 bytes, being less than one percent) isn?t critical but the fact that the continuous data transfer on the bus is broken up every 4096 bytes and some different addresses have to be accessed slow things down.
Where is it used
The continuous memory is an option for the kernel driver of a card based product. It is not available for digitizerNETBOX and generatorNETBOX products as these are Ethernet based.
The continuous buffer settings is done with the Spectrum Control Center using a setup located on the ?Support? page. Please fill in the desired continuous buffer settings as MByte. After setting up the value the system needs to be restarted as the allocation of the buffer is done during system boot time.
On Linux systems the continuous buffer setting is done via the command line argument contmem_mb when loading the kernel driver module:
insmod spcm.ko contmem_mb=4
Please note that 4 MByte is the maximum continuous memory buffer size a Linux system allows.
Why didn't I get the memory size that I programmed?
At boot time the driver tries to allocate the programmed continuous memory. The physical address space is shared between the operating system, hardware components and hardware drivers. If the operating system does not allow that size the driver cuts it by half and tries again. This is continued until the operating system grants an amount of continuous buffer. Please note that this try and error routine will need several seconds for each failed allocation try during boot up procedure.
Depending on other processes and drivers and events during boot time the result may vary although nothing has been changed on the system. An example Windows system may allow a continuous memory buffer of 256 MByte at 80% of the starts and 128 MBytes at 20% of the starts. Due to this it is not recommended to rely on a dedicated continuous memory buffer size.
What can I do to get the largest continuous memory buffer possible?
There are only a few things one can do:
- Increase the total system memory to at least 4 GByte
- Try to disable as much unused hardware components as possible like 2nd Ethernet port, sound controller, RS232 ports.
- Try different buffer settings. If 256 MByte is not likely to get at boot time and the driver is set back to 128 MByte then maybe 200 MByte is enough and you get it at every boot?
Why is continuous memory not the standard?
- The continuous memory is allocated by the driver at boot time and is not available to any other process in the system independent whether the continuous memory is used or not. If the Spectrum driver is not used the available system memory will simply be reduced by the value that has been allocated by the driver.
- The continous memory is limited (heavily limited on Linux systems) in size. If the application requires to use a GByte of software buffer it is not possible to use the continuous memory buffer.