fs/jffs2/background.c
Source file repositories/reference/linux-study-clean/fs/jffs2/background.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jffs2/background.c- Extension
.c- Size
- 4333 bytes
- Lines
- 166
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- 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/kernel.hlinux/jffs2.hlinux/mtd/mtd.hlinux/completion.hlinux/sched/signal.hlinux/freezer.hlinux/kthread.hnodelist.h
Detected Declarations
function jffs2_garbage_collect_triggerfunction jffs2_start_garbage_collect_threadfunction jffs2_stop_garbage_collect_threadfunction jffs2_garbage_collect_thread
Annotated Snippet
if (!jffs2_thread_should_wake(c)) {
set_current_state (TASK_INTERRUPTIBLE);
spin_unlock(&c->erase_completion_lock);
jffs2_dbg(1, "%s(): sleeping...\n", __func__);
schedule();
} else {
spin_unlock(&c->erase_completion_lock);
}
/* Problem - immediately after bootup, the GCD spends a lot
* of time in places like jffs2_kill_fragtree(); so much so
* that userspace processes (like gdm and X) are starved
* despite plenty of cond_resched()s and renicing. Yield()
* doesn't help, either (presumably because userspace and GCD
* are generally competing for a higher latency resource -
* disk).
* This forces the GCD to slow the hell down. Pulling an
* inode in with read_inode() is much preferable to having
* the GC thread get there first. */
schedule_timeout_interruptible(msecs_to_jiffies(50));
if (kthread_should_stop()) {
jffs2_dbg(1, "%s(): kthread_stop() called\n", __func__);
goto die;
}
/* Put_super will send a SIGKILL and then wait on the sem.
*/
while (signal_pending(current) || freezing(current)) {
unsigned long signr;
if (try_to_freeze())
goto again;
signr = kernel_dequeue_signal();
switch(signr) {
case SIGSTOP:
jffs2_dbg(1, "%s(): SIGSTOP received\n",
__func__);
kernel_signal_stop();
break;
case SIGKILL:
jffs2_dbg(1, "%s(): SIGKILL received\n",
__func__);
goto die;
case SIGHUP:
jffs2_dbg(1, "%s(): SIGHUP received\n",
__func__);
break;
default:
jffs2_dbg(1, "%s(): signal %ld received\n",
__func__, signr);
}
}
/* We don't want SIGHUP to interrupt us. STOP and KILL are OK though. */
sigprocmask(SIG_BLOCK, &hupmask, NULL);
jffs2_dbg(1, "%s(): pass\n", __func__);
if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
pr_notice("No space for garbage collection. Aborting GC thread\n");
goto die;
}
}
die:
spin_lock(&c->erase_completion_lock);
c->gc_task = NULL;
spin_unlock(&c->erase_completion_lock);
kthread_complete_and_exit(&c->gc_thread_exit, 0);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/jffs2.h`, `linux/mtd/mtd.h`, `linux/completion.h`, `linux/sched/signal.h`, `linux/freezer.h`, `linux/kthread.h`, `nodelist.h`.
- Detected declarations: `function jffs2_garbage_collect_trigger`, `function jffs2_start_garbage_collect_thread`, `function jffs2_stop_garbage_collect_thread`, `function jffs2_garbage_collect_thread`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.