fs/netfs/misc.c
Source file repositories/reference/linux-study-clean/fs/netfs/misc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/netfs/misc.c- Extension
.c- Size
- 15272 bytes
- Lines
- 566
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/swap.hinternal.h
Detected Declarations
function netfs_alloc_folioq_bufferfunction netfs_free_folioq_bufferfunction netfs_reset_iterfunction netfs_dirty_foliofunction netfs_dirty_foliofunction clear_inodefunction netfs_invalidate_foliofunction netfs_release_foliofunction netfs_wake_collectorfunction netfs_subreq_clear_in_progressfunction netfs_wait_for_in_progress_streamfunction list_for_each_entryfunction netfs_collect_in_appfunction netfs_wait_for_in_progressfunction netfs_wait_for_readfunction netfs_wait_for_writefunction netfs_wait_for_pausefunction netfs_wait_for_paused_readfunction netfs_wait_for_paused_writeexport netfs_alloc_folioq_bufferexport netfs_free_folioq_bufferexport netfs_dirty_folioexport netfs_unpin_writebackexport netfs_clear_inode_writebackexport netfs_invalidate_folioexport netfs_release_folio
Annotated Snippet
if (!tail || folioq_full(tail)) {
p = netfs_folioq_alloc(0, GFP_NOFS, netfs_trace_folioq_alloc_buffer);
if (!p)
return -ENOMEM;
if (tail) {
tail->next = p;
p->prev = tail;
} else {
*_buffer = p;
}
tail = p;
}
if (size - *_cur_size > PAGE_SIZE)
order = umin(ilog2(size - *_cur_size) - PAGE_SHIFT,
MAX_PAGECACHE_ORDER);
folio = folio_alloc(gfp, order);
if (!folio && order > 0)
folio = folio_alloc(gfp, 0);
if (!folio)
return -ENOMEM;
folio->mapping = mapping;
folio->index = *_cur_size / PAGE_SIZE;
trace_netfs_folio(folio, netfs_folio_trace_alloc_buffer);
slot = folioq_append_mark(tail, folio);
*_cur_size += folioq_folio_size(tail, slot);
} while (*_cur_size < size);
return 0;
}
EXPORT_SYMBOL(netfs_alloc_folioq_buffer);
/**
* netfs_free_folioq_buffer - Free a folio queue.
* @fq: The start of the folio queue to free
*
* Free up a chain of folio_queues and, if marked, the marked folios they point
* to.
*/
void netfs_free_folioq_buffer(struct folio_queue *fq)
{
struct folio_queue *next;
struct folio_batch fbatch;
folio_batch_init(&fbatch);
for (; fq; fq = next) {
for (int slot = 0; slot < folioq_count(fq); slot++) {
struct folio *folio = folioq_folio(fq, slot);
if (!folio ||
!folioq_is_marked(fq, slot))
continue;
trace_netfs_folio(folio, netfs_folio_trace_put);
if (folio_batch_add(&fbatch, folio))
folio_batch_release(&fbatch);
}
netfs_stat_d(&netfs_n_folioq);
next = fq->next;
kfree(fq);
}
folio_batch_release(&fbatch);
}
EXPORT_SYMBOL(netfs_free_folioq_buffer);
/*
* Reset the subrequest iterator to refer just to the region remaining to be
* read. The iterator may or may not have been advanced by socket ops or
* extraction ops to an extent that may or may not match the amount actually
* read.
*/
void netfs_reset_iter(struct netfs_io_subrequest *subreq)
{
struct iov_iter *io_iter = &subreq->io_iter;
size_t remain = subreq->len - subreq->transferred;
if (io_iter->count > remain)
iov_iter_advance(io_iter, io_iter->count - remain);
else if (io_iter->count < remain)
iov_iter_revert(io_iter, remain - io_iter->count);
iov_iter_truncate(&subreq->io_iter, remain);
}
/**
* netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback
Annotation
- Immediate include surface: `linux/swap.h`, `internal.h`.
- Detected declarations: `function netfs_alloc_folioq_buffer`, `function netfs_free_folioq_buffer`, `function netfs_reset_iter`, `function netfs_dirty_folio`, `function netfs_dirty_folio`, `function clear_inode`, `function netfs_invalidate_folio`, `function netfs_release_folio`, `function netfs_wake_collector`, `function netfs_subreq_clear_in_progress`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.