lockdep: minor config and documentation fixes
Subsystems (2)
cover lockdep: minor config and documentation fixes
These are some minor follow-up patches that came up during conversation
at: https://lore.kernel.org/all/30795.1620913191@jrobl/
Note this patchset is sent on top of akpm mm-nonmm-unstable as it depends on "[PATCH v2] lockdep: upper limit LOCKDEP_CHAINS_BITS" which as been previously applied there.
Carlos Llamas (3):
lockdep: fix upper limit for LOCKDEP_*_BITS configs
lockdep: clarify size for LOCKDEP_*_BITS configs
lockdep: document MAX_LOCKDEP_CHAIN_HLOCKS calculation
kernel/locking/lockdep_internals.h | 1 + lib/Kconfig.debug | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-)
base-commit: 766e1913ce7c3add51f49bc1861441e3a3275df2
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
PATCH 1/3 lockdep: fix upper limit for LOCKDEP_*_BITS configs
Lockdep has a set of configs used to determine the size of the static arrays that it uses. However, the upper limit that was initially setup for these configs is too high (30 bit shift). This equates to several GiB of static memory for individual symbols. Using such high values leads to linker errors:
$ make defconfig $ ./scripts/config -e PROVE_LOCKING --set-val LOCKDEP_BITS 30 $ make olddefconfig all [...] ld: kernel image bigger than KERNEL_IMAGE_SIZE ld: section .bss VMA wraps around address space
Adjust the upper limits to the maximum values that avoid these issues. The need for anything more, likely points to a problem elsewhere. Note that LOCKDEP_CHAINS_BITS was intentionally left out as its upper limit had a different symptom and has already been fixed [1].
--- lib/Kconfig.debug | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/Kconfig.debug +4 -4
@@ -1507,7 +1507,7 @@ config LOCKDEP_SMALL config LOCKDEP_BITS int "Bitsize for MAX_LOCKDEP_ENTRIES" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 24 default 15 help Try increasing this value if you hit "BUG: MAX_LOCKDEP_ENTRIES too low!" message.
@@ -1523,7 +1523,7 @@ config LOCKDEP_CHAINS_BITS config LOCKDEP_STACK_TRACE_BITS int "Bitsize for MAX_STACK_TRACE_ENTRIES" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 26 default 19 help Try increasing this value if you hit "BUG: MAX_STACK_TRACE_ENTRIES too low!" message.
@@ -1531,7 +1531,7 @@ config LOCKDEP_STACK_TRACE_BITS config LOCKDEP_STACK_TRACE_HASH_BITS int "Bitsize for STACK_TRACE_HASH_SIZE" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 26 default 14 help Try increasing this value if you need large STACK_TRACE_HASH_SIZE.
@@ -1539,7 +1539,7 @@ config LOCKDEP_STACK_TRACE_HASH_BITS config LOCKDEP_CIRCULAR_QUEUE_BITS int "Bitsize for elements in circular_queue struct" depends on LOCKDEP - range 10 30 + range 10 26 default 12 help Try increasing this value if you hit "lockdep bfs error:-1" warning due to __cq_enqueue() failure.
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
Re: [PATCH 1/3] lockdep: fix upper limit for LOCKDEP_*_BITS configs
Quoted 62 lines · Carlos Llamas
Lockdep has a set of configs used to determine the size of the static arrays that it uses. However, the upper limit that was initially setup for these configs is too high (30 bit shift). This equates to several GiB of static memory for individual symbols. Using such high values leads to linker errors:
$ make defconfig $ ./scripts/config -e PROVE_LOCKING --set-val LOCKDEP_BITS 30 $ make olddefconfig all [...] ld: kernel image bigger than KERNEL_IMAGE_SIZE ld: section .bss VMA wraps around address spaceAdjust the upper limits to the maximum values that avoid these issues. The need for anything more, likely points to a problem elsewhere. Note that
LOCKDEP_CHAINS_BITSwas intentionally left out as its upper limit had a different symptom and has already been fixed [1].Reported-by J. R. Okajima <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Boqun Feng <[email protected]>Cc Ingo Molnar <[email protected]>Cc Waiman Long <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Carlos Llamas <[email protected]>--- lib/Kconfig.debug | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)lib/Kconfig.debug +3
-3@@ -1507,7 +1507,7 @@ config LOCKDEP_SMALL config LOCKDEP_BITS int "Bitsize for MAX_LOCKDEP_ENTRIES" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 24 default 15 help Try increasing this value if you hit "BUG: MAX_LOCKDEP_ENTRIES too low!" message.@@ -1523,7 +1523,7 @@ config LOCKDEP_CHAINS_BITS config LOCKDEP_STACK_TRACE_BITS int "Bitsize for MAX_STACK_TRACE_ENTRIES" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 26 default 19 help Try increasing this value if you hit "BUG: MAX_STACK_TRACE_ENTRIES too low!" message.@@ -1531,7 +1531,7 @@ config LOCKDEP_STACK_TRACE_BITS config LOCKDEP_STACK_TRACE_HASH_BITS int "Bitsize for STACK_TRACE_HASH_SIZE" depends on LOCKDEP && !LOCKDEP_SMALL - range 10 30 + range 10 26 default 14 help Try increasing this value if you need large STACK_TRACE_HASH_SIZE.
lib/Kconfig.debug config LOCKDEP_STACK_TRACE_HASH_BITS · line 1545
Quoted 8 lines
lib/Kconfig.debug +1
-1@@ -1539,7 +1539,7 @@ config LOCKDEP_STACK_TRACE_HASH_BITS config LOCKDEP_CIRCULAR_QUEUE_BITS int "Bitsize for elements in circular_queue struct" depends on LOCKDEP - range 10 30 + range 10 26 default 12 help Try increasing this value if you hit "lockdep bfs error:-1" warning due to __cq_enqueue() failure.
I agree that we should further limit the max values.
PATCH 2/3 lockdep: clarify size for LOCKDEP_*_BITS configs
In reply to Carlos LlamasThe LOCKDEP_*_BITS configs control the size of internal structures used by lockdep. The size is calculated as a power of two of the configured value (e.g. 16 => 64KB). Update these descriptions to more accurately reflect this, as "Bitsize" can be misleading.
--- lib/Kconfig.debug | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/Kconfig.debug +5 -5
@@ -1505,7 +1505,7 @@ config LOCKDEP_SMALL bool config LOCKDEP_BITS - int "Bitsize for MAX_LOCKDEP_ENTRIES" + int "Size for MAX_LOCKDEP_ENTRIES (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 24 default 15
@@ -1513,7 +1513,7 @@ config LOCKDEP_BITS Try increasing this value if you hit "BUG: MAX_LOCKDEP_ENTRIES too low!" message. config LOCKDEP_CHAINS_BITS - int "Bitsize for MAX_LOCKDEP_CHAINS" + int "Size for MAX_LOCKDEP_CHAINS (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 21 default 16
@@ -1521,7 +1521,7 @@ config LOCKDEP_CHAINS_BITS Try increasing this value if you hit "BUG: MAX_LOCKDEP_CHAINS too low!" message. config LOCKDEP_STACK_TRACE_BITS - int "Bitsize for MAX_STACK_TRACE_ENTRIES" + int "Size for MAX_STACK_TRACE_ENTRIES (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 26 default 19
@@ -1529,7 +1529,7 @@ config LOCKDEP_STACK_TRACE_BITS Try increasing this value if you hit "BUG: MAX_STACK_TRACE_ENTRIES too low!" message. config LOCKDEP_STACK_TRACE_HASH_BITS - int "Bitsize for STACK_TRACE_HASH_SIZE" + int "Size for STACK_TRACE_HASH_SIZE (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 26 default 14
@@ -1537,7 +1537,7 @@ config LOCKDEP_STACK_TRACE_HASH_BITS Try increasing this value if you need large STACK_TRACE_HASH_SIZE. config LOCKDEP_CIRCULAR_QUEUE_BITS - int "Bitsize for elements in circular_queue struct" + int "Size for elements in circular_queue struct (as Nth power of 2)" depends on LOCKDEP range 10 26 default 12
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
Waiman Long
reviewerRe: [PATCH 2/3] lockdep: clarify size for LOCKDEP_*_BITS configs
Quoted 57 lines · Carlos Llamas
The LOCKDEP_*_BITS configs control the size of internal structures used by lockdep. The size is calculated as a power of two of the configured value (e.g. 16 => 64KB). Update these descriptions to more accurately reflect this, as "Bitsize" can be misleading.
Suggested-by Andrew Morton <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Boqun Feng <[email protected]>Cc Ingo Molnar <[email protected]>Cc Waiman Long <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Carlos Llamas <[email protected]>--- lib/Kconfig.debug | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)lib/Kconfig.debug +4
-4@@ -1505,7 +1505,7 @@ config LOCKDEP_SMALL bool config LOCKDEP_BITS - int "Bitsize for MAX_LOCKDEP_ENTRIES" + int "Size for MAX_LOCKDEP_ENTRIES (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 24 default 15@@ -1513,7 +1513,7 @@ config LOCKDEP_BITS Try increasing this value if you hit "BUG: MAX_LOCKDEP_ENTRIES too low!" message. config LOCKDEP_CHAINS_BITS - int "Bitsize for MAX_LOCKDEP_CHAINS" + int "Size for MAX_LOCKDEP_CHAINS (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 21 default 16@@ -1521,7 +1521,7 @@ config LOCKDEP_CHAINS_BITS Try increasing this value if you hit "BUG: MAX_LOCKDEP_CHAINS too low!" message. config LOCKDEP_STACK_TRACE_BITS - int "Bitsize for MAX_STACK_TRACE_ENTRIES" + int "Size for MAX_STACK_TRACE_ENTRIES (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 26 default 19@@ -1529,7 +1529,7 @@ config LOCKDEP_STACK_TRACE_BITS Try increasing this value if you hit "BUG: MAX_STACK_TRACE_ENTRIES too low!" message. config LOCKDEP_STACK_TRACE_HASH_BITS - int "Bitsize for STACK_TRACE_HASH_SIZE" + int "Size for STACK_TRACE_HASH_SIZE (as Nth power of 2)" depends on LOCKDEP && !LOCKDEP_SMALL range 10 26 default 14
lib/Kconfig.debug config LOCKDEP_STACK_TRACE_HASH_BITS · line 1543
Quoted 8 lines
lib/Kconfig.debug +1
-1@@ -1537,7 +1537,7 @@ config LOCKDEP_STACK_TRACE_HASH_BITS Try increasing this value if you need large STACK_TRACE_HASH_SIZE. config LOCKDEP_CIRCULAR_QUEUE_BITS - int "Bitsize for elements in circular_queue struct" + int "Size for elements in circular_queue struct (as Nth power of 2)" depends on LOCKDEP range 10 26 default 12
Many kernel developers understand that BITS refers to a size of 2^n. Besides LOCKDEP, there are also many instances of such use in other kconfig entries. It can be a bit odd to explicitly state that just for LOCKDEP.
Cheers,
Longman
Re: [PATCH 2/3] lockdep: clarify size for LOCKDEP_*_BITS configs
Quoted 7 lines · Waiman Long
Many kernel developers understand that BITS refers to a size of 2^n. Besides LOCKDEP, there are also many instances of such use in other kconfig entries. It can be a bit odd to explicitly state that just for LOCKDEP.
Cheers,
Longman
Right, and similar to BITS there is SHIFT, which is also a common way to specify the 2^n values. I'd point out though, that it is also common to clarify the "power of two" explicitly. To name a few examples that are doing so: SECURITY_SELINUX_SIDTAB_HASH_BITS, NODES_SHIFT, CMA_ALIGNMENT, IP_VS_SH_TAB_BITS, LOG_BUF_SHIFT but there is more.
Perhaps this is because the audience for these configs is not always a kernel developer?
Anyway, this is pretty much a trivial patch to address Andrew's comment below. But let me know if you think I should drop it, it seems to me it can be helpful.
[...]
btw, the help text "Bitsize for MAX_LOCKDEP_CHAINS" is odd. What's a bitsize? Maybe "bit shift count for..." or such.
Thanks,
--
Carlos Llamas
Waiman Long
reviewerRe: [PATCH 2/3] lockdep: clarify size for LOCKDEP_*_BITS configs
Quoted 16 lines · Carlos Llamas
Quoted 6 lines · Waiman Long
Many kernel developers understand that BITS refers to a size of 2^n. Besides LOCKDEP, there are also many instances of such use in other kconfig entries. It can be a bit odd to explicitly state that just for LOCKDEP.
Cheers,
LongmanRight, and similar to BITS there is SHIFT, which is also a common way to specify the 2^n values. I'd point out though, that it is also common to clarify the "power of two" explicitly. To name a few examples that are doing so:
SECURITY_SELINUX_SIDTAB_HASH_BITS,NODES_SHIFT,CMA_ALIGNMENT,IP_VS_SH_TAB_BITS,LOG_BUF_SHIFTbut there is more.Perhaps this is because the audience for these configs is not always a kernel developer?
Quoted 7 lines
Anyway, this is pretty much a trivial patch to address Andrew's comment below. But let me know if you think I should drop it, it seems to me it can be helpful.
[...]
btw, the help text "Bitsize forMAX_LOCKDEP_CHAINS" is odd. What's a bitsize? Maybe "bit shift count for..." or such.
I am not against this patch. Currently I am neutral. Let's see what Boqun think about it.
Cheers,
Longman
Re: [PATCH 2/3] lockdep: clarify size for LOCKDEP_*_BITS configs
Quoted 22 lines · Waiman Long
Quoted 20 lines · Carlos Llamas
Quoted 6 lines · Waiman Long
Many kernel developers understand that BITS refers to a size of 2^n. Besides LOCKDEP, there are also many instances of such use in other kconfig entries. It can be a bit odd to explicitly state that just for LOCKDEP.
Cheers,
LongmanRight, and similar to BITS there is SHIFT, which is also a common way to specify the 2^n values. I'd point out though, that it is also common to clarify the "power of two" explicitly. To name a few examples that are doing so:
SECURITY_SELINUX_SIDTAB_HASH_BITS,NODES_SHIFT,CMA_ALIGNMENT,IP_VS_SH_TAB_BITS,LOG_BUF_SHIFTbut there is more.Perhaps this is because the audience for these configs is not always a kernel developer?
Anyway, this is pretty much a trivial patch to address Andrew's comment below. But let me know if you think I should drop it, it seems to me it can be helpful.
Quoted 7 lines
Quoted 3 lines
[...]
btw, the help text "Bitsize forMAX_LOCKDEP_CHAINS" is odd. What's a bitsize? Maybe "bit shift count for..." or such.I am not against this patch. Currently I am neutral. Let's see what Boqun think about it.
This looks good to me. Maybe it's a bit verbose but that's what the doc part should be: providing enough information so more people can be on the same page. Please keep this one, thanks!
Regards,
Boqun
Quoted 3 lines
Cheers,
Longman
Re: [PATCH 2/3] lockdep: clarify size for LOCKDEP_*_BITS configs
Quoted 27 lines · Boqun Feng
Quoted 26 lines · Waiman Long
Quoted 23 lines · Carlos Llamas
Quoted 6 lines · Waiman Long
Many kernel developers understand that BITS refers to a size of 2^n. Besides LOCKDEP, there are also many instances of such use in other kconfig entries. It can be a bit odd to explicitly state that just for LOCKDEP.
Cheers,
LongmanRight, and similar to BITS there is SHIFT, which is also a common way to specify the 2^n values. I'd point out though, that it is also common to clarify the "power of two" explicitly. To name a few examples that are doing so:
SECURITY_SELINUX_SIDTAB_HASH_BITS,NODES_SHIFT,CMA_ALIGNMENT,IP_VS_SH_TAB_BITS,LOG_BUF_SHIFTbut there is more.Perhaps this is because the audience for these configs is not always a kernel developer?
Anyway, this is pretty much a trivial patch to address Andrew's comment below. But let me know if you think I should drop it, it seems to me it can be helpful.
[...]
btw, the help text "Bitsize forMAX_LOCKDEP_CHAINS" is odd. What's a bitsize? Maybe "bit shift count for..." or such.
Quoted 7 lines
Quoted 3 lines
I am not against this patch. Currently I am neutral. Let's see what Boqun think about it.
This looks good to me. Maybe it's a bit verbose but that's what the doc part should be: providing enough information so more people can be on the same page. Please keep this one, thanks!
Sounds good. I'll send out the v2 and keep this patch then.
Thanks,
Carlos Llamas
PATCH 3/3 lockdep: document MAX_LOCKDEP_CHAIN_HLOCKS calculation
In reply to Carlos LlamasAdd a comment to document the magic number '5' used in the calculation of MAX_LOCKDEP_CHAIN_HLOCKS. This number represents the estimated average depth (number of locks held) of a lock chain. This definition was added in commit 443cd507ce7f ("lockdep: add lock_class information to lock_chain and output it").
--- kernel/locking/lockdep_internals.h | 1 + 1 file changed, 1 insertion(+)
kernel/locking/lockdep_internals.h +1 -0
@@ -119,6 +119,7 @@ static const unsigned long LOCKF_USED_IN_IRQ_READ =#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) +/* We estimate that a chain holds 5 locks on average. */ #define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)extern struct lock_chain lock_chains[];
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
Waiman Long
reviewerRe: [PATCH 3/3] lockdep: document MAX_LOCKDEP_CHAIN_HLOCKS calculation
Quoted 23 lines · Carlos Llamas
Add a comment to document the magic number '5' used in the calculation of
MAX_LOCKDEP_CHAIN_HLOCKS. This number represents the estimated average depth (number of locks held) of a lock chain. This definition was added in commit443cd507ce7f("lockdep: addlock_classinformation tolock_chainand output it").Cc Huang Ying <[email protected]>Cc J. R. Okajima <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Boqun Feng <[email protected]>Cc Ingo Molnar <[email protected]>Cc Waiman Long <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Carlos Llamas <[email protected]>--- kernel/locking/lockdep_internals.h | 1 + 1 file changed, 1 insertion(+)kernel/locking/lockdep_internals.h +0
-0
kernel/locking/lockdep_internals.h static const unsigned long LOCKF_USED_IN_IRQ_READ = · line 125
Quoted 7 lines
kernel/locking/lockdep_internals.h +1
-0@@ -119,6 +119,7 @@ static const unsigned long LOCKF_USED_IN_IRQ_READ =#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) +/* We estimate that a chain holds 5 locks on average. */ #define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)extern struct lock_chain lock_chains[];
I think it is better to define another macro like
kernel/locking/lockdep_internals.h +0 -0
@@ -119,7 +119,8 @@ static const unsigned long LOCKF_USED_IN_IRQ_READ =
#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
-#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)
+#define AVG_LOCKDEP_CHAIN_DEPTH 5
+#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*AVG_LOCKDEP_CHAIN_DEPTH)
extern struct lock_chain lock_chains[];
Cheers,
Longman
Re: [PATCH 3/3] lockdep: document MAX_LOCKDEP_CHAIN_HLOCKS calculation
Quoted 19 lines · Waiman Long
I think it is better to define another macro like
kernel/locking/lockdep_internals.h +2
-1@@ -119,7 +119,8 @@ static const unsigned long LOCKF_USED_IN_IRQ_READ = #define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) -#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5) +#define AVG_LOCKDEP_CHAIN_DEPTH 5 +#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*AVG_LOCKDEP_CHAIN_DEPTH) extern struct lock_chain lock_chains[];
Quoted 2 lines
Cheers,
Longman
Sounds good, I'll add your suggestion for v2. Thanks!