fs/nfsd/filecache.c
Source file repositories/reference/linux-study-clean/fs/nfsd/filecache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfsd/filecache.c- Extension
.c- Size
- 40445 bytes
- Lines
- 1477
- 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.
- 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/hash.hlinux/slab.hlinux/file.hlinux/pagemap.hlinux/sched.hlinux/list_lru.hlinux/fsnotify_backend.hlinux/fsnotify.hlinux/seq_file.hlinux/rhashtable.hlinux/nfslocalio.hvfs.hnfsd.hnfsfh.hnetns.hfilecache.htrace.h
Detected Declarations
struct nfsd_fcache_disposalfunction nfsd_match_credfunction nfsd_file_schedule_laundrettefunction nfsd_file_slab_freefunction nfsd_file_mark_freefunction nfsd_file_mark_getfunction nfsd_file_mark_putfunction nfsd_file_mark_find_or_createfunction nfsd_file_allocfunction nfsd_file_check_write_errorfunction nfsd_file_hash_removefunction nfsd_file_unhashfunction nfsd_file_freefunction nfsd_file_check_writebackfunction nfsd_file_lru_addfunction nfsd_file_lru_removefunction nfsd_file_getfunction nfsd_file_putfunction nfsd_file_put_localfunction nfsd_file_filefunction nfsd_file_dispose_listfunction nfsd_file_dispose_list_delayedfunction nfsd_file_net_disposefunction nfsd_file_lru_cbfunction nfsd_file_gc_cbfunction nfsd_file_gcfunction nfsd_file_gc_workerfunction nfsd_file_lru_countfunction nfsd_file_lru_scanfunction nfsd_file_cond_queuefunction activityfunction nfsd_file_close_inodefunction nfsd_file_close_inode_syncfunction nfsd_file_close_exportfunction nfsd_file_lease_notifier_callfunction nfsd_file_fsnotify_handle_eventfunction nfsd_file_cache_initfunction __nfsd_file_cache_purgefunction nfsd_alloc_fcache_disposalfunction nfsd_free_fcache_disposalfunction nfsd_free_fcache_disposal_netfunction nfsd_file_cache_start_netfunction nfsd_file_cache_purgefunction nfsd_file_cache_shutdown_netfunction nfsd_file_cache_shutdownfunction for_each_possible_cpufunction nfsd_file_lookup_lockedfunction nfsd_file_acquire
Annotated Snippet
struct nfsd_fcache_disposal {
spinlock_t lock;
struct list_head freeme;
};
static struct kmem_cache *nfsd_file_slab;
static struct kmem_cache *nfsd_file_mark_slab;
static struct list_lru nfsd_file_lru;
static unsigned long nfsd_file_flags;
static struct fsnotify_group *nfsd_file_fsnotify_group;
static struct delayed_work nfsd_filecache_laundrette;
static struct rhltable nfsd_file_rhltable
____cacheline_aligned_in_smp;
static bool
nfsd_match_cred(const struct cred *c1, const struct cred *c2)
{
int i;
if (!uid_eq(c1->fsuid, c2->fsuid))
return false;
if (!gid_eq(c1->fsgid, c2->fsgid))
return false;
if (c1->group_info == NULL || c2->group_info == NULL)
return c1->group_info == c2->group_info;
if (c1->group_info->ngroups != c2->group_info->ngroups)
return false;
for (i = 0; i < c1->group_info->ngroups; i++) {
if (!gid_eq(c1->group_info->gid[i], c2->group_info->gid[i]))
return false;
}
return true;
}
static const struct rhashtable_params nfsd_file_rhash_params = {
.key_len = sizeof_field(struct nfsd_file, nf_inode),
.key_offset = offsetof(struct nfsd_file, nf_inode),
.head_offset = offsetof(struct nfsd_file, nf_rlist),
/*
* Start with a single page hash table to reduce resizing churn
* on light workloads.
*/
.min_size = 256,
.automatic_shrinking = true,
};
static void
nfsd_file_schedule_laundrette(void)
{
if (test_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags))
queue_delayed_work(system_dfl_wq, &nfsd_filecache_laundrette,
NFSD_LAUNDRETTE_DELAY);
}
static void
nfsd_file_slab_free(struct rcu_head *rcu)
{
struct nfsd_file *nf = container_of(rcu, struct nfsd_file, nf_rcu);
put_cred(nf->nf_cred);
kmem_cache_free(nfsd_file_slab, nf);
}
static void
nfsd_file_mark_free(struct fsnotify_mark *mark)
{
struct nfsd_file_mark *nfm = container_of(mark, struct nfsd_file_mark,
nfm_mark);
kmem_cache_free(nfsd_file_mark_slab, nfm);
}
static struct nfsd_file_mark *
nfsd_file_mark_get(struct nfsd_file_mark *nfm)
{
if (!refcount_inc_not_zero(&nfm->nfm_ref))
return NULL;
return nfm;
}
static void
nfsd_file_mark_put(struct nfsd_file_mark *nfm)
{
if (refcount_dec_and_test(&nfm->nfm_ref)) {
fsnotify_destroy_mark(&nfm->nfm_mark, nfsd_file_fsnotify_group);
fsnotify_put_mark(&nfm->nfm_mark);
}
}
Annotation
- Immediate include surface: `linux/hash.h`, `linux/slab.h`, `linux/file.h`, `linux/pagemap.h`, `linux/sched.h`, `linux/list_lru.h`, `linux/fsnotify_backend.h`, `linux/fsnotify.h`.
- Detected declarations: `struct nfsd_fcache_disposal`, `function nfsd_match_cred`, `function nfsd_file_schedule_laundrette`, `function nfsd_file_slab_free`, `function nfsd_file_mark_free`, `function nfsd_file_mark_get`, `function nfsd_file_mark_put`, `function nfsd_file_mark_find_or_create`, `function nfsd_file_alloc`, `function nfsd_file_check_write_error`.
- 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.