0001
0002 #ifndef _LINUX_REF_TRACKER_H
0003 #define _LINUX_REF_TRACKER_H
0004 #include <linux/refcount.h>
0005 #include <linux/types.h>
0006 #include <linux/spinlock.h>
0007 #include <linux/stackdepot.h>
0008
0009 struct ref_tracker;
0010
0011 struct ref_tracker_dir {
0012 #ifdef CONFIG_REF_TRACKER
0013 spinlock_t lock;
0014 unsigned int quarantine_avail;
0015 refcount_t untracked;
0016 refcount_t no_tracker;
0017 bool dead;
0018 struct list_head list;
0019 struct list_head quarantine;
0020 #endif
0021 };
0022
0023 #ifdef CONFIG_REF_TRACKER
0024 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
0025 unsigned int quarantine_count)
0026 {
0027 INIT_LIST_HEAD(&dir->list);
0028 INIT_LIST_HEAD(&dir->quarantine);
0029 spin_lock_init(&dir->lock);
0030 dir->quarantine_avail = quarantine_count;
0031 dir->dead = false;
0032 refcount_set(&dir->untracked, 1);
0033 refcount_set(&dir->no_tracker, 1);
0034 stack_depot_init();
0035 }
0036
0037 void ref_tracker_dir_exit(struct ref_tracker_dir *dir);
0038
0039 void ref_tracker_dir_print(struct ref_tracker_dir *dir,
0040 unsigned int display_limit);
0041
0042 int ref_tracker_alloc(struct ref_tracker_dir *dir,
0043 struct ref_tracker **trackerp, gfp_t gfp);
0044
0045 int ref_tracker_free(struct ref_tracker_dir *dir,
0046 struct ref_tracker **trackerp);
0047
0048 #else
0049
0050 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
0051 unsigned int quarantine_count)
0052 {
0053 }
0054
0055 static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
0056 {
0057 }
0058
0059 static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir,
0060 unsigned int display_limit)
0061 {
0062 }
0063
0064 static inline int ref_tracker_alloc(struct ref_tracker_dir *dir,
0065 struct ref_tracker **trackerp,
0066 gfp_t gfp)
0067 {
0068 return 0;
0069 }
0070
0071 static inline int ref_tracker_free(struct ref_tracker_dir *dir,
0072 struct ref_tracker **trackerp)
0073 {
0074 return 0;
0075 }
0076
0077 #endif
0078
0079 #endif