mm/filemap.c
Source file repositories/reference/linux-study-clean/mm/filemap.c
File Facts
- System
- Linux kernel
- Corpus path
mm/filemap.c- Extension
.c- Size
- 139286 bytes
- Lines
- 4791
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/export.hlinux/compiler.hlinux/dax.hlinux/fs.hlinux/sched/signal.hlinux/uaccess.hlinux/capability.hlinux/kernel_stat.hlinux/gfp.hlinux/mm.hlinux/swap.hlinux/leafops.hlinux/syscalls.hlinux/mman.hlinux/pagemap.hlinux/file.hlinux/uio.hlinux/error-injection.hlinux/hash.hlinux/writeback.hlinux/backing-dev.hlinux/folio_batch.hlinux/security.hlinux/cpuset.hlinux/hugetlb.hlinux/memcontrol.hlinux/shmem_fs.hlinux/rmap.hlinux/delayacct.hlinux/psi.hlinux/ramfs.hlinux/page_idle.h
Detected Declarations
syscall cachestatenum behaviorfunction Copyrightfunction filemap_unaccount_foliofunction __filemap_remove_foliofunction filemap_free_foliofunction filemap_remove_foliofunction page_cache_delete_batchfunction delete_from_page_cache_batchfunction filemap_check_errorsfunction filemap_check_and_keep_errorsfunction filemap_writebackfunction filemap_fdatawrite_rangefunction filemap_fdatawritefunction filemap_flush_rangefunction filemap_flushfunction filemap_flush_nrfunction filemap_range_has_pagefunction __filemap_fdatawait_rangefunction filemap_fdatawait_rangefunction fsfreezefunction file_fdatawait_rangefunction fsfreezefunction mapping_needs_writebackfunction filemap_range_has_writebackfunction filemap_write_and_wait_rangefunction __filemap_set_wb_errfunction fsyncfunction file_write_and_wait_rangefunction replace_page_cache_foliofunction __filemap_add_foliofunction xas_for_each_conflictfunction filemap_add_foliofunction filemap_invalidate_lock_twofunction filemap_invalidate_unlock_twofunction pagecache_initfunction wake_page_functionfunction folio_wake_bitfunction checkfunction folio_wait_bit_commonfunction folio_put_wait_lockedfunction folio_wait_bitfunction folio_wait_bit_killablefunction folio_put_wait_lockedfunction folio_unlockfunction folio_end_readfunction folio_end_private_2function folio_wait_private_2
Annotated Snippet
SYSCALL_DEFINE4(cachestat, unsigned int, fd,
struct cachestat_range __user *, cstat_range,
struct cachestat __user *, cstat, unsigned int, flags)
{
CLASS(fd, f)(fd);
struct address_space *mapping;
struct cachestat_range csr;
struct cachestat cs;
pgoff_t first_index, last_index;
if (fd_empty(f))
return -EBADF;
if (copy_from_user(&csr, cstat_range,
sizeof(struct cachestat_range)))
return -EFAULT;
/* hugetlbfs is not supported */
if (is_file_hugepages(fd_file(f)))
return -EOPNOTSUPP;
if (!can_do_cachestat(fd_file(f)))
return -EPERM;
if (flags != 0)
return -EINVAL;
first_index = csr.off >> PAGE_SHIFT;
last_index =
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
memset(&cs, 0, sizeof(struct cachestat));
mapping = fd_file(f)->f_mapping;
filemap_cachestat(mapping, first_index, last_index, &cs);
if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
return -EFAULT;
return 0;
}
#endif /* CONFIG_CACHESTAT_SYSCALL */
Annotation
- Immediate include surface: `linux/export.h`, `linux/compiler.h`, `linux/dax.h`, `linux/fs.h`, `linux/sched/signal.h`, `linux/uaccess.h`, `linux/capability.h`, `linux/kernel_stat.h`.
- Detected declarations: `syscall cachestat`, `enum behavior`, `function Copyright`, `function filemap_unaccount_folio`, `function __filemap_remove_folio`, `function filemap_free_folio`, `function filemap_remove_folio`, `function page_cache_delete_batch`, `function delete_from_page_cache_batch`, `function filemap_check_errors`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.