mm/shmem.c
Source file repositories/reference/linux-study-clean/mm/shmem.c
File Facts
- System
- Linux kernel
- Corpus path
mm/shmem.c- Extension
.c- Size
- 159732 bytes
- Lines
- 5964
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/fs.hlinux/init.hlinux/vfs.hlinux/mount.hlinux/ramfs.hlinux/pagemap.hlinux/file.hlinux/fileattr.hlinux/filelock.hlinux/mm.hlinux/random.hlinux/sched/signal.hlinux/export.hlinux/shmem_fs.hlinux/swap.hlinux/uio.hlinux/hugetlb.hlinux/fs_parser.hlinux/swapfile.hlinux/iversion.hlinux/unicode.hswap.hlinux/xattr.hlinux/exportfs.hlinux/posix_acl.hlinux/posix_acl_xattr.hlinux/mman.hlinux/string.hlinux/slab.hlinux/backing-dev.hlinux/writeback.hlinux/folio_batch.h
Detected Declarations
struct shmem_fallocstruct shmem_optionsenum shmem_paramenum huge_modefunction shmem_default_max_blocksfunction shmem_default_max_inodesfunction anonymousfunction shmem_unacct_sizefunction shmem_reacct_sizefunction shmem_acct_blocksfunction shmem_unacct_blocksfunction shmem_inode_acct_blocksfunction shmem_inode_unacct_blocksfunction shmem_mappingfunction vma_is_anon_shmemfunction vma_is_shmemfunction shmem_enable_quotasfunction shmem_disable_quotasfunction shmem_reserve_inodefunction shmem_free_inodefunction shmem_recalc_inodefunction shmem_writeoutfunction shmem_chargefunction shmem_unchargefunction shmem_replace_entryfunction shmem_confirm_swapfunction shmem_get_orders_within_sizefunction shmem_huge_global_enabledfunction shmem_parse_hugefunction shmem_unused_huge_shrinkfunction list_for_each_safefunction shmem_unused_huge_scanfunction shmem_unused_huge_countfunction shmem_unused_huge_shrinkfunction shmem_huge_global_enabledfunction shmem_update_statsfunction shmem_add_to_page_cachefunction xas_for_each_conflictfunction shmem_delete_from_page_cachefunction shmem_free_swapfunction Determinefunction Determinefunction shmem_unlock_mappingfunction filemap_get_foliosfunction shmem_undo_rangefunction shmem_truncate_rangefunction shmem_getattrfunction shmem_setattr
Annotated Snippet
static const struct file_operations shmem_file_operations;
static const struct inode_operations shmem_inode_operations;
static const struct inode_operations shmem_dir_inode_operations;
static const struct inode_operations shmem_special_inode_operations;
static const struct vm_operations_struct shmem_vm_ops;
static const struct vm_operations_struct shmem_anon_vm_ops;
static struct file_system_type shmem_fs_type;
bool shmem_mapping(const struct address_space *mapping)
{
return mapping->a_ops == &shmem_aops;
}
EXPORT_SYMBOL_GPL(shmem_mapping);
bool vma_is_anon_shmem(const struct vm_area_struct *vma)
{
return vma->vm_ops == &shmem_anon_vm_ops;
}
bool vma_is_shmem(const struct vm_area_struct *vma)
{
return vma_is_anon_shmem(vma) || vma->vm_ops == &shmem_vm_ops;
}
static LIST_HEAD(shmem_swaplist);
static DEFINE_SPINLOCK(shmem_swaplist_lock);
#ifdef CONFIG_TMPFS_QUOTA
static int shmem_enable_quotas(struct super_block *sb,
unsigned short quota_types)
{
int type, err = 0;
sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY;
for (type = 0; type < SHMEM_MAXQUOTAS; type++) {
if (!(quota_types & (1 << type)))
continue;
err = dquot_load_quota_sb(sb, type, QFMT_SHMEM,
DQUOT_USAGE_ENABLED |
DQUOT_LIMITS_ENABLED);
if (err)
goto out_err;
}
return 0;
out_err:
pr_warn("tmpfs: failed to enable quota tracking (type=%d, err=%d)\n",
type, err);
for (type--; type >= 0; type--)
dquot_quota_off(sb, type);
return err;
}
static void shmem_disable_quotas(struct super_block *sb)
{
int type;
for (type = 0; type < SHMEM_MAXQUOTAS; type++)
dquot_quota_off(sb, type);
}
static struct dquot __rcu **shmem_get_dquots(struct inode *inode)
{
return SHMEM_I(inode)->i_dquot;
}
#endif /* CONFIG_TMPFS_QUOTA */
/*
* shmem_reserve_inode() performs bookkeeping to reserve a shmem inode, and
* produces a novel ino for the newly allocated inode.
*
* It may also be called when making a hard link to permit the space needed by
* each dentry. However, in that case, no new inode number is needed since that
* internally draws from another pool of inode numbers (currently global
* get_next_ino()). This case is indicated by passing NULL as inop.
*/
#define SHMEM_INO_BATCH 1024
static int shmem_reserve_inode(struct super_block *sb, ino_t *inop)
{
struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
ino_t ino;
if (!(sb->s_flags & SB_KERNMOUNT)) {
raw_spin_lock(&sbinfo->stat_lock);
if (sbinfo->max_inodes) {
if (sbinfo->free_ispace < BOGO_INODE_SIZE) {
raw_spin_unlock(&sbinfo->stat_lock);
return -ENOSPC;
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/init.h`, `linux/vfs.h`, `linux/mount.h`, `linux/ramfs.h`, `linux/pagemap.h`, `linux/file.h`, `linux/fileattr.h`.
- Detected declarations: `struct shmem_falloc`, `struct shmem_options`, `enum shmem_param`, `enum huge_mode`, `function shmem_default_max_blocks`, `function shmem_default_max_inodes`, `function anonymous`, `function shmem_unacct_size`, `function shmem_reacct_size`, `function shmem_acct_blocks`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: pattern 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.