linux scull defects

.. Let's take a quick look at some scull memory management code in the depths of writing logic, scull must decide whether it has requested memory allocation code to handle this task are:

 

if (!dptr->data[s_pos]) {

dptr->data[s_pos] = kmalloc(quantum, GFP_KERNEL); if (!dptr->data[s_pos])

goto out;

}

 

Suppose there are two processes (we will call them "A" and "B") attempts to write the same offset independently schull same device. Each process simultaneously arrive first if the test line segments above. If test pointer is NULL, each process will determine the allocation of memory, and each copy will result pointer to dptr-> datat [s_pos]. because the two processes are assigned to the same position, apparently only an assignment successfully.

 

Of course, the occurrence of the first two to complete the assignment process will "win" if the process A assignment before its assignment would be covered by process B in this, scull will simply forget about memory A allocated;.. It only points to memory B, pointer. a pointer is allocated, therefore, will be lost and no longer returned to the system.

 

This sequence of events is to demonstrate a competitive situation. Competition is the result of uncontrolled shared data access. When access mode error occurred, resulting in unwanted stuff. Competition cases discussed here, the result is a memory leak. this is bad enough, but competition often leads to system crashes and data corruption. programmer might be tempted to ignore the competition is fairly low probability event, but in the computer world, one in a million event It will occur every few seconds, and the consequences will be serious.

 

Soon we will remove the competition scull, but first of all we need to do a more general concurrent review.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11141633.html