In computing, a memory barrier is a type of ordering restraint that helps to balance the demand on the memory that is available for processing various commands and functions. Also known as "membar" or as a "memory fence," the idea is to create some sort of hierarchical order or progression to all the pending tasks that have to do with utilization of that memory. Doing so makes it possible to execute those tasks in a logical sequence and prevent the possibility of memory overload, something that could permanently damage the memory capacity of the system.
In actual practice, a memory barrier is a class or set of instructions that are designed to prevent the use of available memory in some manner that could undermine the actual function of that memory. Since the barrier or fence is hardware-based, this means it is usually associated with the function of the central processing unit (CPU), or some other device. This can often be necessary when the memory is serving more than a single machine or device and access to that memory must be allocated in some sort of logical manner. Without creating this type of memory barrier to keep functions within a logical sequence, the possibility of various tasks being executed out of order and maybe even damaging stored data is greatly enhanced.
The term itself is indicative of what actually occurs. A fence typically performs two functions at the same time, keeping something inside while also preventing something outside from entering the space, except through some sort of gate. In this manner, access to whatever is inside is kept controlled by a gatekeeper. With a memory barrier, the instructions function as that gatekeeper, only allowing access to the memory according to the ordered instructions. The end result is that data is accessed in a logical fashion, tasks are completed accurately, and the potential for overload is kept within reasonable limits.
The necessity of some sort of memory barrier has become increasingly evident as computer systems become more powerful and are used to drive a wider range of external devices that rely on the memory for their function. When the class of instructions used for the barrier are properly prepared, the hardware will respond accordingly and all devices will function as they should. In the event that the barrier should break down or cease to function, problems executing even the most simple of orders may become extremely difficult.