Skip to contentSkip to conversation

tree/tiny rcu: Add debug RCU head option (v2)

PATCH In review Mathieu Desnoyers 4 participants 13 messages Mar 19, 2010 – Mar 22, 2010

Subsystems (3)
lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

PATCH 1/1 tree/tiny rcu: Add debug RCU head option (v2)

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)
include/linux/rcupdate.h +12 -1
Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;
kernel/rcutree.c +10 -0
Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 
lib/Kconfig.debug +9 -0
Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL
include/net/dst.h +2 -0
Index: linux-2.6-lttng/include/net/dst.h
===================================================================
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 
kernel/rcutiny.c +9 -0
Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#1 lore raw
Quoted 14 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

Quoted 6 lines

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

If this one finds at least one bug (or if the previous version found at least one bug -- bad memory day here), then I will push it. It can always be improved later, right?

The patch looks good to me.

Thanx, Paul

Quoted 170 lines
---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
Signature · 5 lines
-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
author reviewer
#2 lore raw
Quoted 22 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 14 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

Quoted 6 lines

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

Quoted 2 lines

If this one finds at least one bug (or if the previous version found at least one bug -- bad memory day here), then I will push it.

I had to create this patch when I was trying to pinpoint some RCU-related issues. I think it turned out to be coming more from the cpu hotplug side than from the call_rcu() side, but this is really one more tool in the toolbox. Trying to find out if it detect actual misuses that we currently have will depend on tracking down all the non-initialized rcu_head structures. I already got a few for 2.6.32, but there seem to be more in 2.6.33. Again, I'll try to spot and correct them as time permits me.

I already have spotted 6 non-initialized rcu heads, with more to come.

Quoted 2 lines

It can
always be improved later, right?

Absolutely.

Quoted 2 lines

The patch looks good to me.

Great! :)

Mathieu

Quoted 173 lines

Thanx, Paul

Quoted 170 lines
---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
Signature · 5 lines
-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#3 lore raw
In reply to Mathieu Desnoyers
CC Christoph Lameter <[email protected]>
CC Pekka Enberg <[email protected]>

I have written a patch like this before.

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

I tested it very long time before, so I can't give you dmesg.

Lai

Quoted 186 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
#4 lore raw
Quoted 21 lines · Lai Jiangshan
CC Christoph Lameter <[email protected]>
CC Pekka Enberg <[email protected]>

I have written a patch like this before.

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}
Quoted 8 lines

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

I tested it very long time before, so I can't give you dmesg.

Ouch!!!

If this only causes a problem for SLUB, maybe a workaround is to make the config variable depend on !SLUB. But this would seem to increase the urgency of using the debug objects

Thanx, Paul

Quoted 190 lines

Lai

Quoted 186 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
author reviewer
#5 lore raw
Quoted 29 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 28 lines · Lai Jiangshan
CC Christoph Lameter <[email protected]>
CC Pekka Enberg <[email protected]>

I have written a patch like this before.

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Quoted 7 lines
Quoted 1 line

I tested it very long time before, so I can't give you dmesg.

Ouch!!!

If this only causes a problem for SLUB, maybe a workaround is to make the config variable depend on !SLUB. But this would seem to increase the urgency of using the debug objects

Yep, that hurts. I think we'll have to move to debugobjects more quickly than expected.

Thanks,

Matheiu

Quoted 193 lines

Thanx, Paul

Quoted 190 lines

Lai

Quoted 186 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
author reviewer
#6 lore raw
In reply to Paul E. McKenney
Quoted 29 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 28 lines · Lai Jiangshan
CC Christoph Lameter <[email protected]>
CC Pekka Enberg <[email protected]>

I have written a patch like this before.

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Quoted 7 lines
Quoted 1 line

I tested it very long time before, so I can't give you dmesg.

Ouch!!!

If this only causes a problem for SLUB, maybe a workaround is to make the config variable depend on !SLUB. But this would seem to increase the urgency of using the debug objects

Hrm.. looking into the port to debugobjects, there are a few things that are not precisely well set at the moment for it:

- We need to have two distinct active states, with a check that we move between the two. This does not seem to be currently supported by debugobjects.
- RCU heads are never explicitely freed. So yeah, that means we will have to modify a lot of callers.

Thanks,

Mathieu

Quoted 193 lines

Thanx, Paul

Quoted 190 lines

Lai

Quoted 186 lines · Mathieu Desnoyers

Poisoning the rcu_head callback list.

Helps finding racy users of call_rcu(), which results in hangs because list entries are overwritten and/or skipped.

A lot of non-initialized rcu list heads will be found with this option enabled. It is important to do not just blindly initialize them before each call_rcu, but rather to perform the initialization at the proper location, after the memory has been allocated, so we can effectively detect incorrect call_rcu users.

This patch version does not use "debug objects", although it probably should. Some day I might find time to look into this transition, but the patch is usable as is.

The weird #ifdef in the networking code comes from an agreement with Eric Dumazet about how to disable the build check for the networking code. For those who wonder about the existence of this build-time check: it generates a build error when the size of struct dst_entry grows (because it is very performance sensitive). So the agreement here has been to disable the check when the DEBUG_RCU_HEAD config option is active.

---
 include/linux/rcupdate.h |   13 ++++++++++++-
 include/net/dst.h        |    2 ++
 kernel/rcutiny.c         |    9 +++++++++
 kernel/rcutree.c         |   10 ++++++++++
 lib/Kconfig.debug        |    9 +++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6-lttng/include/linux/rcupdate.h
===================================================================

include/linux/rcupdate.h +12 -1
@@ -49,6 +49,9 @@
 struct rcu_head {
 	struct rcu_head *next;
 	void (*func)(struct rcu_head *head);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	struct rcu_head *debug;
+#endif
 };
 
 /* Exported common interfaces */
@@ -71,11 +74,19 @@ extern void rcu_init(void);
 #error "Unknown RCU implementation specified to kernel configuration"
 #endif
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+#define RCU_HEAD_INIT 	{ .next = NULL, .func = NULL, .debug = NULL }
+#define INIT_RCU_HEAD(ptr) do { \
+       (ptr)->next = NULL; (ptr)->func = NULL; (ptr)->debug = NULL; \
+} while (0)
+#else
 #define RCU_HEAD_INIT	{ .next = NULL, .func = NULL }
-#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 #define INIT_RCU_HEAD(ptr) do { \
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
+#endif
+
+#define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 extern struct lockdep_map rcu_lock_map;

Index: linux-2.6-lttng/kernel/rcutree.c
===================================================================

kernel/rcutree.c +10 -0
@@ -39,6 +39,7 @@
 #include <asm/atomic.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
+#include <linux/poison.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
 #include <linux/percpu.h>
@@ -1060,6 +1061,10 @@ static void rcu_do_batch(struct rcu_stat
 		next = list->next;
 		prefetch(next);
 		trace_rcu_tree_callback(list);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 		if (++count >= rdp->blimit)
@@ -1350,6 +1355,11 @@ __call_rcu(struct rcu_head *head, void (
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
+
 	head->func = func;
 	head->next = NULL;
 

Index: linux-2.6-lttng/lib/Kconfig.debug
===================================================================

lib/Kconfig.debug +9 -0
@@ -661,6 +661,15 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RCU_HEAD
+	bool "Debug RCU callbacks"
+	depends on DEBUG_KERNEL
+	depends on TREE_RCU
+	help
+	  Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+	  Seems to find problems more quickly with stress-tests in single-cpu
+	  mode.
+
 config DEBUG_SG
 	bool "Debug SG table operations"
 	depends on DEBUG_KERNEL

Index: linux-2.6-lttng/include/net/dst.h
===================================================================

include/net/dst.h +2 -0
@@ -159,7 +159,9 @@ static inline void dst_hold(struct dst_e
 	 * If your kernel compilation stops here, please check
 	 * __pad_to_align_refcnt declaration in struct dst_entry
 	 */
+#ifndef CONFIG_DEBUG_RCU_HEAD
 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
+#endif
 	atomic_inc(&dst->__refcnt);
 }
 

Index: linux-2.6-lttng/kernel/rcutiny.c
===================================================================

kernel/rcutiny.c +9 -0
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/cpu.h>
+#include <linux/poison.h>
 
 /* Global control variables for rcupdate callback mechanism. */
 struct rcu_ctrlblk {
@@ -163,6 +164,10 @@ static void __rcu_process_callbacks(stru
 	while (list) {
 		next = list->next;
 		prefetch(next);
+#ifdef CONFIG_DEBUG_RCU_HEAD
+		WARN_ON_ONCE(list->debug != LIST_POISON1);
+		list->debug = NULL;
+#endif
 		list->func(list);
 		list = next;
 	}
@@ -210,6 +215,10 @@ static void __call_rcu(struct rcu_head *
 {
 	unsigned long flags;
 
+#ifdef CONFIG_DEBUG_RCU_HEAD
+	WARN_ON_ONCE(head->debug);
+	head->debug = LIST_POISON1;
+#endif
 	head->func = func;
 	head->next = NULL;
 
Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#7 lore raw
In reply to Lai Jiangshan
Quoted 16 lines · Lai Jiangshan

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}
Quoted 6 lines

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Right. I like the smallness of the RCU structure but if you must increase its size then we could:

A) put the rcu structure at the end of each page like SLOB but that will take away memory that could be used by objects.

B) Move the rcu object up by a word so that it overloads the index field in the page struct. That would give another exact fit but will cause trouble again if you bloat the structure some more.

#8 lore raw
Quoted 28 lines · Christoph Lameter
Quoted 16 lines · Lai Jiangshan

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}
Quoted 6 lines

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Right. I like the smallness of the RCU structure but if you must increase its size then we could:

Quoted 6 lines

A) put the rcu structure at the end of each page like SLOB but that will take away memory that could be used by objects.

B) Move the rcu object up by a word so that it overloads the index field in the page struct. That would give another exact fit but will cause trouble again if you bloat the structure some more.

The size increase is strictly under a debug option -- the non-debug size remains the same as always. And I expect that in the longer term, we will be able to shrink the size back down even with this debug option available.

One question: do any of the other allocators care about the size of the struct rcu_head? If not, a temporary work-around would be to simply prohibit use of this debug option when running with SLUB.

Thanx, Paul

author reviewer
#9 lore raw
Quoted 41 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 28 lines · Christoph Lameter
Quoted 16 lines · Lai Jiangshan

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}
Quoted 6 lines

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Right. I like the smallness of the RCU structure but if you must increase its size then we could:

Quoted 6 lines

A) put the rcu structure at the end of each page like SLOB but that will take away memory that could be used by objects.

B) Move the rcu object up by a word so that it overloads the index field in the page struct. That would give another exact fit but will cause trouble again if you bloat the structure some more.

The size increase is strictly under a debug option -- the non-debug size remains the same as always. And I expect that in the longer term, we will be able to shrink the size back down even with this debug option available.

Quoted 5 lines

One question: do any of the other allocators care about the size of the struct rcu_head? If not, a temporary work-around would be to simply prohibit use of this debug option when running with SLUB.

Thanx, Paul

Don't worry about the struct rcu_head size too much. I'm currently working on a debugobjects implementation. I should have something by the end of the day.

Thanks,

Mathieu

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
#10 lore raw
Quoted 42 lines · Mathieu Desnoyers
Quoted 41 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 28 lines · Christoph Lameter
Quoted 16 lines · Lai Jiangshan

but SLUB opposed me, so I did not post it.

@ slub.c
static void free_slab(struct kmem_cache *s, struct page *page)

{
	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
		/*
		 * RCU free overloads the RCU head over the LRU
		 */
		struct rcu_head *head = (void *)&page->lru;

		call_rcu(head, rcu_free_slab);
	} else
		__free_slab(s, page);
}
Quoted 6 lines

I think it is not your patch's fault, but the above code has already existed.

In your patch, struct rcu_head::debug will share the same memory of the other field of struct page, (especially share the struct page::flags which I encountered)

Right. I like the smallness of the RCU structure but if you must increase its size then we could:

Quoted 6 lines

A) put the rcu structure at the end of each page like SLOB but that will take away memory that could be used by objects.

B) Move the rcu object up by a word so that it overloads the index field in the page struct. That would give another exact fit but will cause trouble again if you bloat the structure some more.

The size increase is strictly under a debug option -- the non-debug size remains the same as always. And I expect that in the longer term, we will be able to shrink the size back down even with this debug option available.

Quoted 8 lines
Quoted 5 lines

One question: do any of the other allocators care about the size of the struct rcu_head? If not, a temporary work-around would be to simply prohibit use of this debug option when running with SLUB.

Thanx, Paul

Don't worry about the struct rcu_head size too much. I'm currently working on a debugobjects implementation. I should have something by the end of the day.

Even better!!! Thank you, Mathieu!!!

Thanx, Paul

#11 lore raw

SLAB overloads "struct slab" with the rcu_head. Its not that critical there since the metadata allocated for each slab page is larger. SLUB does not have such a per slab page metadata structure and limits its metadata to what is available in the page struct.

#12 lore raw
Quoted 4 lines · Christoph Lameter

SLAB overloads "struct slab" with the rcu_head. Its not that critical there since the metadata allocated for each slab page is larger. SLUB does not have such a per slab page metadata structure and limits its metadata to what is available in the page struct.

Thank you for the info!

FWIW, Mathieu is now using debug objects, which permits him to keep rcu_head the same size.

Thanx, Paul