Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does the linux kernel avoid deadlocks?

How does the linux kernel avoids deadlocks in user processes? Does it have a built-in mechanism that prevents them, or one that recognizes and kills them?

And, is there anything similar for kernel programming?

like image 527
Gergely Avatar asked Mar 04 '14 11:03

Gergely


People also ask

How does Linux handle deadlock?

Commonly used methods for handling deadlocks within systems are (i) deadlock detection, (ii) deadlock prevention, or (iii) deadlock avoidance. Most existing static and dynamic deadlock detection tools focus on specific lock class types (e.g., pthread locks) and require an instrumentation of the code.

How does Linux detect deadlock?

If you suspect a deadlock, do a ps aux | grep <exe name> , if in output, the PROCESS STATE CODE is D (Uninterruptible sleep) means it is a deadlock.

What is deadlock in Linux kernel?

Deadlock: A situation in which a set of process exists, each of which is blocked awaiting a resource that is already allocated to another process in that set. Resource: Hardware or software entity allocated to a particular process.

How are deadlocks avoided?

Deadlock can be prevented by eliminating any of the four necessary conditions, which are mutual exclusion, hold and wait, no preemption, and circular wait. Mutual exclusion, hold and wait and no preemption cannot be violated practically. Circular wait can be feasibly eliminated by assigning a priority to each resource.


1 Answers

The kernel does not avoid deadlocks of user-space locks (because often it doesn't even know about them).

Deadlocks of kernel locks are avoided by writing code that is correct. This is greatly helped by lockdep, which can prove the correctness of locking operations.

(The lockdep code has been ported to user space, but it helps only for programs that bother to use it.)

like image 51
CL. Avatar answered Sep 25 '22 09:09

CL.