History

lib: add reference counting tracking infrastructure

It can be hard to track where references are taken and released. In networking, we have annoying issues at device or netns dismantles, and we had various proposals to ease root causing them. This patch adds new infrastructure pairing refcount increases and decreases. This will self document code, because programmers will have to associate increments/decrements. This is controled by CONFIG_REF_TRACKER which can be selected by users of this feature. This adds both cpu and memory costs, and thus should probably be used with care.

Eric Dumazet committed 4 years ago

Commit 4e669341 parent ce832784 files · +220 −0Browse files

Showing the changes to include (1 of 4 files). Show all

Unified · Split

include/linux/ref_tracker.h+73−0
@@ -0,0 +1,73 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+#ifndef _LINUX_REF_TRACKER_H
3+#define _LINUX_REF_TRACKER_H
4+#include <linux/refcount.h>
5+#include <linux/types.h>
6+#include <linux/spinlock.h>
7+
8+struct ref_tracker;
9+
10+struct ref_tracker_dir {
11+#ifdef CONFIG_REF_TRACKER
12+ spinlock_t lock;
13+ unsigned int quarantine_avail;
14+ refcount_t untracked;
15+ struct list_head list; /* List of active trackers */
16+ struct list_head quarantine; /* List of dead trackers */
17+#endif
18+};
19+
20+#ifdef CONFIG_REF_TRACKER
21+static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
22+ unsigned int quarantine_count)
23+{
24+ INIT_LIST_HEAD(&dir->list);
25+ INIT_LIST_HEAD(&dir->quarantine);
26+ spin_lock_init(&dir->lock);
27+ dir->quarantine_avail = quarantine_count;
28+ refcount_set(&dir->untracked, 1);
29+}
30+
31+void ref_tracker_dir_exit(struct ref_tracker_dir *dir);
32+
33+void ref_tracker_dir_print(struct ref_tracker_dir *dir,
34+ unsigned int display_limit);
35+
36+int ref_tracker_alloc(struct ref_tracker_dir *dir,
37+ struct ref_tracker **trackerp, gfp_t gfp);
38+
39+int ref_tracker_free(struct ref_tracker_dir *dir,
40+ struct ref_tracker **trackerp);
41+
42+#else /* CONFIG_REF_TRACKER */
43+
44+static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
45+ unsigned int quarantine_count)
46+{
47+}
48+
49+static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
50+{
51+}
52+
53+static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir,
54+ unsigned int display_limit)
55+{
56+}
57+
58+static inline int ref_tracker_alloc(struct ref_tracker_dir *dir,
59+ struct ref_tracker **trackerp,
60+ gfp_t gfp)
61+{
62+ return 0;
63+}
64+
65+static inline int ref_tracker_free(struct ref_tracker_dir *dir,
66+ struct ref_tracker **trackerp)
67+{
68+ return 0;
69+}
70+
71+#endif
72+
73+#endif /* _LINUX_REF_TRACKER_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t