0

I am trying to understand the reason for 3rd point - and most importantly the must condition from the link below :

https://www.freebsd.org/cgi/man.cgi?locking(9)

Giant

Giant is a special mutex used to protect data structures that do not yet have their own locks. Since it provides semantics akin to the old spl(9) interface, Giant has special characteristics:

 1.   It is recursive.

 2.   Drivers can request that Giant be locked around them by not marking
  themselves MPSAFE.  Note that infrastructure to do this is slowly
  going away as non-MPSAFE drivers either became properly locked or
  disappear.

 3.   Giant must be locked before other non-sleepable locks.

 4.   Giant is dropped during unbounded sleeps and reacquired after
  wakeup.

 5.   There are places in the kernel that drop Giant and pick it back up
  again.  Sleep locks will do this before sleeping.  Parts of the net-
  work or VM code may do this as well.  This means that you cannot
  count on Giant keeping other code from running if your code sleeps,
  even if you want it to.
0andriy
  • 4,183
  • 1
  • 24
  • 37
ultimate cause
  • 2,264
  • 4
  • 27
  • 44

1 Answers1

1

John Baldwin provides a little bit more detailed explanation for this rule in his BSDcon paper:

No lock is allowed to be held while acquiring Giant. This ensures that other locks can always be safely acquired whether or not Giant is held. This in turn allows subsystems that have their own locks to be called directly without Giant being held, and to be called by other subsystems that still require Giant.

  • Thanks for help +1, however I did not understand the significance yet. This seems to be a soft rule that imposes exclusivity with other locks. I don't see anything in code that causes acquisition of Giant to fail if others have been held already. So this more or less seems to be a guideline to preserve lock ordering? – ultimate cause Oct 16 '17 at 01:14
  • 1
    Kind of yes, this might be related to lock ordering, as per the next paragraph. Though, I agree, it would be better to have more eloquent examples showing the effect of not releasing locks prior acquisition of Giant. –  Oct 16 '17 at 08:17
  • I guess there is no effect other than lock ordering - what it wants to suggest is simply that, if you need to have giant at some point take it just before other spin-locks, because anyways with spin-locks you can't sleep or preempt. But if you don't need Giant, you can happily enjoy your spin-locks alone. +1 Thanks. – ultimate cause Oct 16 '17 at 15:13