fs/hugetlbfs/inode.c
Source file repositories/reference/linux-study-clean/fs/hugetlbfs/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hugetlbfs/inode.c- Extension
.c- Size
- 43071 bytes
- Lines
- 1630
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- 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/thread_info.hasm/current.hlinux/falloc.hlinux/fs.hlinux/mount.hlinux/file.hlinux/kernel.hlinux/writeback.hlinux/pagemap.hlinux/highmem.hlinux/init.hlinux/string.hlinux/capability.hlinux/ctype.hlinux/backing-dev.hlinux/hugetlb.hlinux/folio_batch.hlinux/fs_parser.hlinux/mman.hlinux/slab.hlinux/dnotify.hlinux/statfs.hlinux/security.hlinux/magic.hlinux/migrate.hlinux/uio.hlinux/uaccess.hlinux/sched/mm.htrace/events/hugetlbfs.h
Detected Declarations
struct hugetlbfs_fs_contextenum hugetlbfs_size_typeenum hugetlb_paramfunction hugetlbfs_file_mmapfunction mmap_write_lockfunction adjust_range_hwpoisonfunction readfunction hugetlbfs_write_beginfunction hugetlbfs_write_endfunction hugetlb_delete_from_page_cachefunction vmafunction vma_offset_startfunction vma_offset_endfunction hugetlb_unmap_file_foliofunction hugetlb_vmdelete_listfunction remove_inode_single_foliofunction remove_inode_hugepagesfunction hugetlbfs_evict_inodefunction hugetlb_vmtruncatefunction hugetlbfs_zero_partial_pagefunction hugetlbfs_punch_holefunction hugetlbfs_fallocatefunction hugetlbfs_setattrfunction hugetlbfs_mknodfunction hugetlbfs_createfunction hugetlbfs_tmpfilefunction hugetlbfs_symlinkfunction hugetlbfs_migrate_foliofunction hugetlbfs_error_remove_foliofunction hugetlbfs_show_optionsfunction hugetlbfs_statfsfunction hugetlbfs_put_superfunction hugetlbfs_dec_free_inodesfunction hugetlbfs_inc_free_inodesfunction hugetlbfs_free_inodefunction hugetlbfs_destroy_inodefunction init_oncefunction hugetlbfs_size_to_hpagesfunction hugetlbfs_parse_paramfunction hugetlbfs_validatefunction hugetlbfs_fill_superfunction hugetlbfs_get_treefunction hugetlbfs_fs_context_freefunction hugetlbfs_init_fs_contextfunction can_do_hugetlb_shmfunction get_hstate_idxfunction mount_one_hugetlbfsfunction init_hugetlbfs_fs
Annotated Snippet
static const struct file_operations hugetlbfs_file_operations;
static const struct inode_operations hugetlbfs_dir_inode_operations;
static const struct inode_operations hugetlbfs_inode_operations;
enum hugetlbfs_size_type { NO_SIZE, SIZE_STD, SIZE_PERCENT };
struct hugetlbfs_fs_context {
struct hstate *hstate;
unsigned long long max_size_opt;
unsigned long long min_size_opt;
long max_hpages;
long nr_inodes;
long min_hpages;
enum hugetlbfs_size_type max_val_type;
enum hugetlbfs_size_type min_val_type;
kuid_t uid;
kgid_t gid;
umode_t mode;
};
int sysctl_hugetlb_shm_group;
enum hugetlb_param {
Opt_gid,
Opt_min_size,
Opt_mode,
Opt_nr_inodes,
Opt_pagesize,
Opt_size,
Opt_uid,
};
static const struct fs_parameter_spec hugetlb_fs_parameters[] = {
fsparam_gid ("gid", Opt_gid),
fsparam_string("min_size", Opt_min_size),
fsparam_u32oct("mode", Opt_mode),
fsparam_string("nr_inodes", Opt_nr_inodes),
fsparam_string("pagesize", Opt_pagesize),
fsparam_string("size", Opt_size),
fsparam_uid ("uid", Opt_uid),
{}
};
/*
* Mask used when checking the page offset value passed in via system
* calls. This value will be converted to a loff_t which is signed.
* Therefore, we want to check the upper PAGE_SHIFT + 1 bits of the
* value. The extra bit (- 1 in the shift value) is to take the sign
* bit into account.
*/
#define PGOFF_LOFFT_MAX \
(((1UL << (PAGE_SHIFT + 1)) - 1) << (BITS_PER_LONG - (PAGE_SHIFT + 1)))
static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
{
struct inode *inode = file_inode(file);
loff_t len, vma_len;
int ret;
struct hstate *h = hstate_file(file);
vma_flags_t vma_flags;
/*
* vma address alignment (but not the pgoff alignment) has
* already been checked by prepare_hugepage_range. If you add
* any error returns here, do so after setting VM_HUGETLB, so
* is_vm_hugetlb_page tests below unmap_region go the right
* way when do_mmap unwinds (may be important on powerpc
* and ia64).
*/
vma_set_flags(vma, VMA_HUGETLB_BIT, VMA_DONTEXPAND_BIT);
vma->vm_ops = &hugetlb_vm_ops;
/*
* page based offset in vm_pgoff could be sufficiently large to
* overflow a loff_t when converted to byte offset. This can
* only happen on architectures where sizeof(loff_t) ==
* sizeof(unsigned long). So, only check in those instances.
*/
if (sizeof(unsigned long) == sizeof(loff_t)) {
if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
return -EINVAL;
}
/* must be huge page aligned */
if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
return -EINVAL;
vma_len = (loff_t)(vma->vm_end - vma->vm_start);
len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
/* check for overflow */
Annotation
- Immediate include surface: `linux/thread_info.h`, `asm/current.h`, `linux/falloc.h`, `linux/fs.h`, `linux/mount.h`, `linux/file.h`, `linux/kernel.h`, `linux/writeback.h`.
- Detected declarations: `struct hugetlbfs_fs_context`, `enum hugetlbfs_size_type`, `enum hugetlb_param`, `function hugetlbfs_file_mmap`, `function mmap_write_lock`, `function adjust_range_hwpoison`, `function read`, `function hugetlbfs_write_begin`, `function hugetlbfs_write_end`, `function hugetlb_delete_from_page_cache`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.