fs/xfs/xfs_zone_space_resv.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_zone_space_resv.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_zone_space_resv.c- Extension
.c- Size
- 7228 bytes
- Lines
- 263
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_shared.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_inode.hxfs_rtbitmap.hxfs_icache.hxfs_zone_alloc.hxfs_zone_priv.hxfs_zones.h
Detected Declarations
struct xfs_zone_reservationfunction xfs_zoned_default_resblksfunction xfs_zoned_resv_wake_allfunction xfs_zoned_add_availablefunction xfs_zoned_space_wait_errorfunction xfs_zoned_reserve_availablefunction xfs_zoned_reserve_extents_greedyfunction xfs_zoned_space_reservefunction xfs_zoned_space_unreserve
Annotated Snippet
struct xfs_zone_reservation {
struct list_head entry;
struct task_struct *task;
xfs_filblks_t count_fsb;
};
/*
* Calculate the number of reserved blocks.
*
* XC_FREE_RTEXTENTS counts the user available capacity, to which the file
* system can be filled, while XC_FREE_RTAVAILABLE counts the blocks instantly
* available for writes without waiting for GC.
*
* For XC_FREE_RTAVAILABLE only the smaller reservation required for GC and
* block zeroing is excluded from the user capacity, while XC_FREE_RTEXTENTS
* is further restricted by at least one zone as well as the optional
* persistently reserved blocks. This allows the allocator to run more
* smoothly by not always triggering GC.
*/
uint64_t
xfs_zoned_default_resblks(
struct xfs_mount *mp,
enum xfs_free_counter ctr)
{
switch (ctr) {
case XC_FREE_RTEXTENTS:
return xfs_rtgs_to_rfsbs(mp, XFS_RESERVED_ZONES) +
mp->m_sb.sb_rtreserved;
case XC_FREE_RTAVAILABLE:
return xfs_rtgs_to_rfsbs(mp, XFS_GC_ZONES);
default:
ASSERT(0);
return 0;
}
}
void
xfs_zoned_resv_wake_all(
struct xfs_mount *mp)
{
struct xfs_zone_info *zi = mp->m_zone_info;
struct xfs_zone_reservation *reservation;
spin_lock(&zi->zi_reservation_lock);
list_for_each_entry(reservation, &zi->zi_reclaim_reservations, entry)
wake_up_process(reservation->task);
spin_unlock(&zi->zi_reservation_lock);
}
void
xfs_zoned_add_available(
struct xfs_mount *mp,
xfs_filblks_t count_fsb)
{
struct xfs_zone_info *zi = mp->m_zone_info;
struct xfs_zone_reservation *reservation;
if (list_empty_careful(&zi->zi_reclaim_reservations)) {
xfs_add_freecounter(mp, XC_FREE_RTAVAILABLE, count_fsb);
return;
}
spin_lock(&zi->zi_reservation_lock);
xfs_add_freecounter(mp, XC_FREE_RTAVAILABLE, count_fsb);
count_fsb = xfs_sum_freecounter(mp, XC_FREE_RTAVAILABLE);
list_for_each_entry(reservation, &zi->zi_reclaim_reservations, entry) {
if (reservation->count_fsb > count_fsb)
break;
wake_up_process(reservation->task);
count_fsb -= reservation->count_fsb;
}
spin_unlock(&zi->zi_reservation_lock);
}
static int
xfs_zoned_space_wait_error(
struct xfs_mount *mp)
{
if (xfs_is_shutdown(mp))
return -EIO;
if (fatal_signal_pending(current))
return -EINTR;
return 0;
}
static int
xfs_zoned_reserve_available(
struct xfs_mount *mp,
xfs_filblks_t count_fsb,
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_inode.h`, `xfs_rtbitmap.h`, `xfs_icache.h`.
- Detected declarations: `struct xfs_zone_reservation`, `function xfs_zoned_default_resblks`, `function xfs_zoned_resv_wake_all`, `function xfs_zoned_add_available`, `function xfs_zoned_space_wait_error`, `function xfs_zoned_reserve_available`, `function xfs_zoned_reserve_extents_greedy`, `function xfs_zoned_space_reserve`, `function xfs_zoned_space_unreserve`.
- 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.