Re: Just a question about sys/kern/subr_witness.c where witness_watch may be flipped to -1

From: Dennis Clarke <dclarke_at_blastwave.org>
Date: Tue, 20 May 2025 15:34:00 UTC
On 5/20/25 01:51, Mark Millard wrote:
> Dennis Clarke <dclarke_at_blastwave.org> wrote on
> Date: Tue, 20 May 2025 02:33:58 UTC:
> 
>> Just an odd message to see on the console :
>>
>>       # witness_lock_list_get: witness exhausted
>>
>> Looking at https://cgit.freebsd.org/src/tree/sys/kern/subr_witness.c it
>> seems that the comment at line 370 is very clear :
>>
>> /*
>>    * If set to 0, lock order checking is disabled.  If set to -1,
>>    * witness is completely disabled.  Otherwise witness performs full
>>    * lock order checking for all locks.  At runtime, lock order checking
>>    * may be toggled.  However, witness cannot be reenabled once it is
>>    * completely disabled.
>>    */
>> static int witness_watch = 1;
>>
>> So I wonder how I managed to get that message "witness exhausted" ?
>>
>> At line 2203 I see :
>>
>> static struct lock_list_entry *
>> witness_lock_list_get(void)
>> {
>> 	struct lock_list_entry *lle;
>>
>> 	if (witness_watch == -1)
>> 		return (NULL);
>> 	mtx_lock_spin(&w_mtx);
>> 	lle = w_lock_list_free;
>> 	if (lle == NULL) {
> 
> Looks to me like "out of required resources, cannot
> continue with the mode of use" code: an empty free
> list so no node is available to put to use to
> continue with the witness handling.
> 

Seems like a strange feature that simply gives up and goes away if the
system gets a bit busy. This system was running a poudriere build of
kde when the message appeared on the console. There was still plenty of
memory available so there must be some hard coded limit in there that
needs to be adjusted.


>> 		witness_watch = -1;
>> 		mtx_unlock_spin(&w_mtx);
>> 		printf("%s: witness exhausted\n", __func__);
>> 		return (NULL);
>> 	}
>> 	w_lock_list_free = lle->ll_next;
>> 	mtx_unlock_spin(&w_mtx);
>> 	bzero(lle, sizeof(*lle));
>> 	return (lle);
>> }
>>
>> Where it seems that indeed witness_watch has been flipped to -1 and that
>> functionality is now gone?
> 
> Until the next boot, anyway.
> 

A fairly stange feature that is implemented by default if one merely
does a buildworld/buildkernel sequence with no adjustments.

-- 
--
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken