lib/ref_tracker.c
Source file repositories/reference/linux-study-clean/lib/ref_tracker.c
File Facts
- System
- Linux kernel
- Corpus path
lib/ref_tracker.c- Extension
.c- Size
- 14008 bytes
- Lines
- 534
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/list_sort.hlinux/ref_tracker.hlinux/slab.hlinux/stacktrace.hlinux/stackdepot.hlinux/seq_file.hlinux/xarray.hlinux/debugfs.h
Detected Declarations
struct ref_trackerstruct ref_tracker_dir_statsstruct ostreamfunction ref_tracker_debugfs_markfunction ref_tracker_debugfs_markfunction list_for_each_entryfunction pr_ostream_logfunction pr_ostream_buffunction __ref_tracker_dir_pr_ostreamfunction ref_tracker_dir_print_lockedfunction ref_tracker_dir_printfunction ref_tracker_dir_snprintfunction ref_tracker_dir_exitfunction list_for_each_entry_safefunction ref_tracker_allocfunction ref_tracker_freefunction pr_ostream_seqfunction ref_tracker_dir_seq_printfunction ref_tracker_debugfs_showfunction xa_get_markfunction ref_tracker_debugfs_openfunction ref_tracker_dir_debugfsfunction ref_tracker_dir_symlinkfunction debugfs_reap_workfunction xa_for_each_markedfunction xa_for_each_markedfunction ref_tracker_debugfs_postcore_initfunction ref_tracker_debugfs_late_initexport ref_tracker_dir_print_lockedexport ref_tracker_dir_printexport ref_tracker_dir_snprintexport ref_tracker_dir_exitexport ref_tracker_allocexport ref_tracker_freeexport ref_tracker_dir_debugfsexport ref_tracker_dir_symlink
Annotated Snippet
static const struct file_operations ref_tracker_debugfs_fops = {
.owner = THIS_MODULE,
.open = ref_tracker_debugfs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/**
* ref_tracker_dir_debugfs - create debugfs file for ref_tracker_dir
* @dir: ref_tracker_dir to be associated with debugfs file
*
* In most cases, a debugfs file will be created automatically for every
* ref_tracker_dir. If the object was created before debugfs is brought up
* then that may fail. In those cases, it is safe to call this at a later
* time to create the file.
*/
void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
{
char name[NAME_MAX + 1];
struct dentry *dentry;
int ret;
/* No-op if already created */
dentry = xa_load(&debugfs_dentries, (unsigned long)dir);
if (dentry && !xa_is_err(dentry))
return;
ret = snprintf(name, sizeof(name), "%s@%p", dir->class, dir);
name[sizeof(name) - 1] = '\0';
if (ret < sizeof(name)) {
dentry = debugfs_create_file(name, S_IFREG | 0400,
ref_tracker_debug_dir, dir,
&ref_tracker_debugfs_fops);
if (!IS_ERR(dentry)) {
void *old;
old = xa_store_irq(&debugfs_dentries, (unsigned long)dir,
dentry, GFP_KERNEL);
if (xa_is_err(old))
debugfs_remove(dentry);
else
WARN_ON_ONCE(old);
}
}
}
EXPORT_SYMBOL(ref_tracker_dir_debugfs);
void __ostream_printf ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
{
char name[NAME_MAX + 1];
struct dentry *symlink, *dentry;
va_list args;
int ret;
symlink = xa_load(&debugfs_symlinks, (unsigned long)dir);
dentry = xa_load(&debugfs_dentries, (unsigned long)dir);
/* Already created?*/
if (symlink && !xa_is_err(symlink))
return;
if (!dentry || xa_is_err(dentry))
return;
va_start(args, fmt);
ret = vsnprintf(name, sizeof(name), fmt, args);
va_end(args);
name[sizeof(name) - 1] = '\0';
if (ret < sizeof(name)) {
symlink = debugfs_create_symlink(name, ref_tracker_debug_dir,
dentry->d_name.name);
if (!IS_ERR(symlink)) {
void *old;
old = xa_store_irq(&debugfs_symlinks, (unsigned long)dir,
symlink, GFP_KERNEL);
if (xa_is_err(old))
debugfs_remove(symlink);
else
WARN_ON_ONCE(old);
}
}
}
EXPORT_SYMBOL(ref_tracker_dir_symlink);
static void debugfs_reap_work(struct work_struct *work)
Annotation
- Immediate include surface: `linux/export.h`, `linux/list_sort.h`, `linux/ref_tracker.h`, `linux/slab.h`, `linux/stacktrace.h`, `linux/stackdepot.h`, `linux/seq_file.h`, `linux/xarray.h`.
- Detected declarations: `struct ref_tracker`, `struct ref_tracker_dir_stats`, `struct ostream`, `function ref_tracker_debugfs_mark`, `function ref_tracker_debugfs_mark`, `function list_for_each_entry`, `function pr_ostream_log`, `function pr_ostream_buf`, `function __ref_tracker_dir_pr_ostream`, `function ref_tracker_dir_print_locked`.
- Atlas domain: Kernel Services / lib.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.