drivers/md/dm-stats.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-stats.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-stats.c- Extension
.c- Size
- 31112 bytes
- Lines
- 1265
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/errno.hlinux/numa.hlinux/slab.hlinux/rculist.hlinux/threads.hlinux/preempt.hlinux/irqflags.hlinux/vmalloc.hlinux/mm.hlinux/module.hlinux/device-mapper.hdm-core.hdm-stats.h
Detected Declarations
struct dm_stat_percpustruct dm_stat_sharedstruct dm_statstruct dm_stats_last_positionfunction __check_shared_memoryfunction check_shared_memoryfunction claim_shared_memoryfunction free_shared_memoryfunction dm_kvfreefunction dm_stat_freefunction dm_stat_in_flightfunction dm_stats_initfunction for_each_possible_cpufunction dm_stats_cleanupfunction dm_stats_recalc_precise_timestampsfunction list_for_eachfunction dm_stats_createfunction for_each_possible_cpufunction list_for_each_entryfunction dm_stats_deletefunction is_vmalloc_addrfunction dm_stats_listfunction dm_stat_roundfunction dm_stat_for_entryfunction __dm_stat_biofunction dm_stats_account_iofunction __dm_stat_init_temporary_percpu_totalsfunction for_each_possible_cpufunction __dm_stat_clearfunction dm_stats_clearfunction dm_jiffies_to_msec64function dm_stats_printfunction dm_stats_set_auxfunction parse_histogramfunction message_stats_createfunction message_stats_deletefunction message_stats_clearfunction message_stats_listfunction message_stats_printfunction message_stats_set_auxfunction dm_stats_messagefunction dm_statistics_initfunction dm_statistics_exit
Annotated Snippet
struct dm_stat_percpu {
unsigned long long sectors[2];
unsigned long long ios[2];
unsigned long long merges[2];
unsigned long long ticks[2];
unsigned long long io_ticks[2];
unsigned long long io_ticks_total;
unsigned long long time_in_queue;
unsigned long long *histogram;
};
struct dm_stat_shared {
atomic_t in_flight[2];
unsigned long long stamp;
struct dm_stat_percpu tmp;
};
struct dm_stat {
struct list_head list_entry;
int id;
unsigned int stat_flags;
size_t n_entries;
sector_t start;
sector_t end;
sector_t step;
unsigned int n_histogram_entries;
unsigned long long *histogram_boundaries;
const char *program_id;
const char *aux_data;
struct rcu_head rcu_head;
size_t shared_alloc_size;
size_t percpu_alloc_size;
size_t histogram_alloc_size;
struct dm_stat_percpu *stat_percpu[NR_CPUS];
struct dm_stat_shared stat_shared[] __counted_by(n_entries);
};
#define STAT_PRECISE_TIMESTAMPS 1
struct dm_stats_last_position {
sector_t last_sector;
unsigned int last_rw;
};
#define DM_STAT_MAX_ENTRIES 8388608
#define DM_STAT_MAX_HISTOGRAM_ENTRIES 134217728
/*
* A typo on the command line could possibly make the kernel run out of memory
* and crash. To prevent the crash we account all used memory. We fail if we
* exhaust 1/4 of all memory or 1/2 of vmalloc space.
*/
#define DM_STATS_MEMORY_FACTOR 4
#define DM_STATS_VMALLOC_FACTOR 2
static DEFINE_SPINLOCK(shared_memory_lock);
static unsigned long shared_memory_amount;
static bool __check_shared_memory(size_t alloc_size)
{
size_t a;
a = shared_memory_amount + alloc_size;
if (a < shared_memory_amount)
return false;
if (a >> PAGE_SHIFT > totalram_pages() / DM_STATS_MEMORY_FACTOR)
return false;
#ifdef CONFIG_MMU
if (a > (VMALLOC_END - VMALLOC_START) / DM_STATS_VMALLOC_FACTOR)
return false;
#endif
return true;
}
static bool check_shared_memory(size_t alloc_size)
{
bool ret;
spin_lock_irq(&shared_memory_lock);
ret = __check_shared_memory(alloc_size);
spin_unlock_irq(&shared_memory_lock);
return ret;
}
static bool claim_shared_memory(size_t alloc_size)
{
Annotation
- Immediate include surface: `linux/errno.h`, `linux/numa.h`, `linux/slab.h`, `linux/rculist.h`, `linux/threads.h`, `linux/preempt.h`, `linux/irqflags.h`, `linux/vmalloc.h`.
- Detected declarations: `struct dm_stat_percpu`, `struct dm_stat_shared`, `struct dm_stat`, `struct dm_stats_last_position`, `function __check_shared_memory`, `function check_shared_memory`, `function claim_shared_memory`, `function free_shared_memory`, `function dm_kvfree`, `function dm_stat_free`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source 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.