drivers/md/dm-kcopyd.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-kcopyd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-kcopyd.c- Extension
.c- Size
- 22097 bytes
- Lines
- 999
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/types.hlinux/atomic.hlinux/blkdev.hlinux/fs.hlinux/init.hlinux/list.hlinux/mempool.hlinux/module.hlinux/pagemap.hlinux/slab.hlinux/vmalloc.hlinux/workqueue.hlinux/mutex.hlinux/delay.hlinux/device-mapper.hlinux/dm-kcopyd.hdm-core.h
Detected Declarations
struct dm_kcopyd_clientstruct kcopyd_jobfunction dm_get_kcopyd_subjob_sizefunction io_job_startfunction io_job_finishfunction wakefunction free_plfunction kcopyd_put_pagesfunction kcopyd_get_pagesfunction drop_pagesfunction client_reserve_pagesfunction client_free_pagesfunction dm_kcopyd_initfunction dm_kcopyd_exitfunction pushfunction push_headfunction run_complete_jobfunction complete_iofunction run_io_jobfunction run_pages_jobfunction process_jobsfunction do_workfunction dispatch_jobfunction segment_completefunction split_jobfunction dm_kcopyd_copyfunction dm_kcopyd_zerofunction dm_kcopyd_do_callbackfunction kcopyd_cancelfunction dm_kcopyd_client_destroyfunction dm_kcopyd_client_flushexport dm_kcopyd_copyexport dm_kcopyd_zeroexport dm_kcopyd_prepare_callbackexport dm_kcopyd_do_callbackexport dm_kcopyd_client_createexport dm_kcopyd_client_destroyexport dm_kcopyd_client_flush
Annotated Snippet
struct dm_kcopyd_client {
struct page_list *pages;
unsigned int nr_reserved_pages;
unsigned int nr_free_pages;
unsigned int sub_job_size;
struct dm_io_client *io_client;
wait_queue_head_t destroyq;
mempool_t job_pool;
struct workqueue_struct *kcopyd_wq;
struct work_struct kcopyd_work;
struct dm_kcopyd_throttle *throttle;
atomic_t nr_jobs;
/*
* We maintain four lists of jobs:
*
* i) jobs waiting for pages
* ii) jobs that have pages, and are waiting for the io to be issued.
* iii) jobs that don't need to do any IO and just run a callback
* iv) jobs that have completed.
*
* All four of these are protected by job_lock.
*/
spinlock_t job_lock;
struct list_head callback_jobs;
struct list_head complete_jobs;
struct list_head io_jobs;
struct list_head pages_jobs;
};
static struct page_list zero_page_list;
static DEFINE_SPINLOCK(throttle_spinlock);
/*
* IO/IDLE accounting slowly decays after (1 << ACCOUNT_INTERVAL_SHIFT) period.
* When total_period >= (1 << ACCOUNT_INTERVAL_SHIFT) the counters are divided
* by 2.
*/
#define ACCOUNT_INTERVAL_SHIFT SHIFT_HZ
/*
* Sleep this number of milliseconds.
*
* The value was decided experimentally.
* Smaller values seem to cause an increased copy rate above the limit.
* The reason for this is unknown but possibly due to jiffies rounding errors
* or read/write cache inside the disk.
*/
#define SLEEP_USEC 100000
/*
* Maximum number of sleep events. There is a theoretical livelock if more
* kcopyd clients do work simultaneously which this limit avoids.
*/
#define MAX_SLEEPS 10
static void io_job_start(struct dm_kcopyd_throttle *t)
{
unsigned int throttle, now, difference;
int slept = 0, skew;
if (unlikely(!t))
return;
try_again:
spin_lock_irq(&throttle_spinlock);
throttle = READ_ONCE(t->throttle);
if (likely(throttle >= 100))
goto skip_limit;
now = jiffies;
difference = now - t->last_jiffies;
t->last_jiffies = now;
if (t->num_io_jobs)
t->io_period += difference;
t->total_period += difference;
/*
* Maintain sane values if we got a temporary overflow.
*/
if (unlikely(t->io_period > t->total_period))
Annotation
- Immediate include surface: `linux/types.h`, `linux/atomic.h`, `linux/blkdev.h`, `linux/fs.h`, `linux/init.h`, `linux/list.h`, `linux/mempool.h`, `linux/module.h`.
- Detected declarations: `struct dm_kcopyd_client`, `struct kcopyd_job`, `function dm_get_kcopyd_subjob_size`, `function io_job_start`, `function io_job_finish`, `function wake`, `function free_pl`, `function kcopyd_put_pages`, `function kcopyd_get_pages`, `function drop_pages`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: integration 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.