include/linux/sched/mm.h
Source file repositories/reference/linux-study-clean/include/linux/sched/mm.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/sched/mm.h- Extension
.h- Size
- 17660 bytes
- Lines
- 576
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- 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/atomic.hlinux/sched.hlinux/mm_types.hlinux/gfp.hlinux/sync_core.hlinux/sched/coredump.hasm/membarrier.h
Detected Declarations
function mmgrabfunction smp_mb__after_mmgrabfunction mmdropfunction __mmdrop_delayedfunction finish_task_switchfunction mmdrop_schedfunction mmgrab_lazy_tlbfunction mmdrop_lazy_tlbfunction mmdrop_lazy_tlb_schedfunction mmgetfunction mmget_not_zerofunction mm_update_next_ownerfunction arch_pick_mmap_layoutfunction current_gfp_contextfunction __fs_reclaim_acquirefunction might_sleepfunction memalloc_flags_savefunction memalloc_flags_restorefunction memalloc_noio_savefunction memalloc_noio_restorefunction memalloc_nofs_savefunction memalloc_nofs_restorefunction __gfp_pfmemalloc_flagsfunction memalloc_noreclaim_restorefunction memalloc_pin_savefunction memalloc_pin_restorefunction set_active_memcgfunction set_active_memcgfunction membarrier_mm_sync_core_before_usermodefunction membarrier_arch_switch_mm
Annotated Snippet
static inline void __fs_reclaim_acquire(unsigned long ip) { }
static inline void __fs_reclaim_release(unsigned long ip) { }
static inline void fs_reclaim_acquire(gfp_t gfp_mask) { }
static inline void fs_reclaim_release(gfp_t gfp_mask) { }
#endif
/* Any memory-allocation retry loop should use
* memalloc_retry_wait(), and pass the flags for the most
* constrained allocation attempt that might have failed.
* This provides useful documentation of where loops are,
* and a central place to fine tune the waiting as the MM
* implementation changes.
*/
static inline void memalloc_retry_wait(gfp_t gfp_flags)
{
/* We use io_schedule_timeout because waiting for memory
* typically included waiting for dirty pages to be
* written out, which requires IO.
*/
__set_current_state(TASK_UNINTERRUPTIBLE);
gfp_flags = current_gfp_context(gfp_flags);
if (gfpflags_allow_blocking(gfp_flags) &&
!(gfp_flags & __GFP_NORETRY))
/* Probably waited already, no need for much more */
io_schedule_timeout(1);
else
/* Probably didn't wait, and has now released a lock,
* so now is a good time to wait
*/
io_schedule_timeout(HZ/50);
}
/**
* might_alloc - Mark possible allocation sites
* @gfp_mask: gfp_t flags that would be used to allocate
*
* Similar to might_sleep() and other annotations, this can be used in functions
* that might allocate, but often don't. Compiles to nothing without
* CONFIG_LOCKDEP. Includes a conditional might_sleep() if @gfp allows blocking.
*/
static inline void might_alloc(gfp_t gfp_mask)
{
fs_reclaim_acquire(gfp_mask);
fs_reclaim_release(gfp_mask);
if (current->flags & PF_MEMALLOC)
return;
might_sleep_if(gfpflags_allow_blocking(gfp_mask));
}
/**
* memalloc_flags_save - Add a PF_* flag to current->flags, save old value
* @flags: Flags to add.
*
* This allows PF_* flags to be conveniently added, irrespective of current
* value, and then the old version restored with memalloc_flags_restore().
*/
static inline unsigned memalloc_flags_save(unsigned flags)
{
unsigned oldflags = ~current->flags & flags;
current->flags |= flags;
return oldflags;
}
static inline void memalloc_flags_restore(unsigned flags)
{
current->flags &= ~flags;
}
/**
* memalloc_noio_save - Marks implicit GFP_NOIO allocation scope.
*
* This functions marks the beginning of the GFP_NOIO allocation scope.
* All further allocations will implicitly drop __GFP_IO flag and so
* they are safe for the IO critical section from the allocation recursion
* point of view. Use memalloc_noio_restore to end the scope with flags
* returned by this function.
*
* Context: This function is safe to be used from any context.
* Return: The saved flags to be passed to memalloc_noio_restore.
*/
static inline unsigned int memalloc_noio_save(void)
{
return memalloc_flags_save(PF_MEMALLOC_NOIO);
}
/**
* memalloc_noio_restore - Ends the implicit GFP_NOIO scope.
* @flags: Flags to restore.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/atomic.h`, `linux/sched.h`, `linux/mm_types.h`, `linux/gfp.h`, `linux/sync_core.h`, `linux/sched/coredump.h`, `asm/membarrier.h`.
- Detected declarations: `function mmgrab`, `function smp_mb__after_mmgrab`, `function mmdrop`, `function __mmdrop_delayed`, `function finish_task_switch`, `function mmdrop_sched`, `function mmgrab_lazy_tlb`, `function mmdrop_lazy_tlb`, `function mmdrop_lazy_tlb_sched`, `function mmget`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.