Dillon's comments on FreeBSD/DFly's VM
Well, this is fun. There are over 460 files in the 5.x source tree (360 in DFly) that make calls to malloc(… M_NOWAIT), and so far about 80% of the calls that I’ve reviewed generate inappropriate side effects when/if a failure occurs. CAM is the biggest violator… it even has a few panic() conditionals if a malloc(… M_NOWAIT) fails. Not Fun!
In particular, Dillon said that most of M_NOWAIT flag was used inappropriately in FreeBSD and DFly. Dillon then wrote this in DFly’s list:
I think I’ve come up with a solution! The reason M_NOWAIT is used is primarily because an interrupt thread may be preempting a normal thread and cannot safely manipulate ‘cache’ pages in the VM page queues. This is because reusing a cache page requires messing around with the VM Object the cache page resides in. So M_NOWAIT causes kmem_malloc() to only pull pages out of the VM ‘free’ page queue. At the same time it is allowed to actually exhaust the free page queue whereas normal allocations are not allowed to completely exhaust the free page queue.
More discussion seemed to be related to junsu’s bug report. So I am interested in this thread.