mm/kasan/quarantine.c
Source file repositories/reference/linux-study-clean/mm/kasan/quarantine.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/quarantine.c- Extension
.c- Size
- 10989 bytes
- Lines
- 415
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/gfp.hlinux/hash.hlinux/kernel.hlinux/mm.hlinux/percpu.hlinux/printk.hlinux/shrinker.hlinux/slab.hlinux/srcu.hlinux/string.hlinux/types.hlinux/cpuhotplug.h../slab.hkasan.h
Detected Declarations
struct qlist_headstruct cpu_shrink_qlistfunction qlist_emptyfunction qlist_initfunction qlist_putfunction qlist_move_allfunction qlink_freefunction qlist_free_allfunction kasan_quarantine_putfunction kasan_quarantine_reducefunction qlist_move_cachefunction __per_cpu_remove_cachefunction per_cpu_remove_cachefunction kasan_quarantine_remove_cachefunction for_each_online_cpufunction kasan_cpu_onlinefunction kasan_cpu_offlinefunction kasan_cpu_quarantine_init
Annotated Snippet
struct qlist_head {
struct qlist_node *head;
struct qlist_node *tail;
size_t bytes;
bool offline;
};
#define QLIST_INIT { NULL, NULL, 0 }
static bool qlist_empty(struct qlist_head *q)
{
return !q->head;
}
static void qlist_init(struct qlist_head *q)
{
q->head = q->tail = NULL;
q->bytes = 0;
}
static void qlist_put(struct qlist_head *q, struct qlist_node *qlink,
size_t size)
{
if (unlikely(qlist_empty(q)))
q->head = qlink;
else
q->tail->next = qlink;
q->tail = qlink;
qlink->next = NULL;
q->bytes += size;
}
static void qlist_move_all(struct qlist_head *from, struct qlist_head *to)
{
if (unlikely(qlist_empty(from)))
return;
if (qlist_empty(to)) {
*to = *from;
qlist_init(from);
return;
}
to->tail->next = from->head;
to->tail = from->tail;
to->bytes += from->bytes;
qlist_init(from);
}
#define QUARANTINE_PERCPU_SIZE (1 << 20)
#define QUARANTINE_BATCHES \
(1024 > 4 * CONFIG_NR_CPUS ? 1024 : 4 * CONFIG_NR_CPUS)
/*
* The object quarantine consists of per-cpu queues and a global queue,
* guarded by quarantine_lock.
*/
static DEFINE_PER_CPU(struct qlist_head, cpu_quarantine);
/* Round-robin FIFO array of batches. */
static struct qlist_head global_quarantine[QUARANTINE_BATCHES];
static int quarantine_head;
static int quarantine_tail;
/* Total size of all objects in global_quarantine across all batches. */
static unsigned long quarantine_size;
static DEFINE_RAW_SPINLOCK(quarantine_lock);
DEFINE_STATIC_SRCU(remove_cache_srcu);
struct cpu_shrink_qlist {
raw_spinlock_t lock;
struct qlist_head qlist;
};
static DEFINE_PER_CPU(struct cpu_shrink_qlist, shrink_qlist) = {
.lock = __RAW_SPIN_LOCK_UNLOCKED(shrink_qlist.lock),
};
/* Maximum size of the global queue. */
static unsigned long quarantine_max_size;
/*
* Target size of a batch in global_quarantine.
* Usually equal to QUARANTINE_PERCPU_SIZE unless we have too much RAM.
*/
static unsigned long quarantine_batch_size;
/*
* The fraction of physical memory the quarantine is allowed to occupy.
* Quarantine doesn't support memory shrinker with SLAB allocator, so we keep
Annotation
- Immediate include surface: `linux/gfp.h`, `linux/hash.h`, `linux/kernel.h`, `linux/mm.h`, `linux/percpu.h`, `linux/printk.h`, `linux/shrinker.h`, `linux/slab.h`.
- Detected declarations: `struct qlist_head`, `struct cpu_shrink_qlist`, `function qlist_empty`, `function qlist_init`, `function qlist_put`, `function qlist_move_all`, `function qlink_free`, `function qlist_free_all`, `function kasan_quarantine_put`, `function kasan_quarantine_reduce`.
- Atlas domain: Core OS / Memory Management.
- 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.