fs/xfs/libxfs/xfs_trans_resv.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_trans_resv.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_trans_resv.c- Extension
.c- Size
- 48634 bytes
- Lines
- 1560
- 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_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_da_format.hxfs_da_btree.hxfs_inode.hxfs_bmap_btree.hxfs_quota.hxfs_trans.hxfs_qm.hxfs_trans_space.hxfs_rtbitmap.hxfs_attr_item.hxfs_log.hxfs_defer.hxfs_bmap_item.hxfs_extfree_item.hxfs_rmap_item.hxfs_refcount_item.hxfs_trace.h
Detected Declarations
function Copyrightfunction xfs_calc_buf_resfunction modifiedfunction xfs_refcountbt_block_countfunction xfs_rtrefcountbt_block_countfunction xfs_calc_inode_resfunction btreesfunction allocationfunction headersfunction splitsfunction xfs_defer_finishfunction xfs_calc_finish_rt_cui_reservationfunction xfs_calc_refcountbt_reservationfunction joinfunction xfs_calc_write_reservation_minlogsizefunction blocksfunction xfs_calc_finish_rt_efi_reservationfunction xfs_calc_finish_rui_reservationfunction xfs_calc_finish_rt_rui_reservationfunction xfs_calc_finish_bui_reservationfunction blocksfunction xfs_calc_itruncate_reservation_minlogsizefunction xfs_calc_pptr_link_overheadfunction xfs_calc_pptr_unlink_overheadfunction xfs_calc_pptr_replace_overheadfunction blocksfunction xfs_rename_log_countfunction xfs_calc_iunlink_remove_reservationfunction xfs_link_log_countfunction xfs_calc_link_reservationfunction xfs_calc_iunlink_add_reservationfunction xfs_remove_log_countfunction xfs_calc_remove_reservationfunction finobtfunction chunkfunction xfs_icreate_log_countfunction xfs_calc_icreate_reservationfunction xfs_calc_create_tmpfile_reservationfunction xfs_mkdir_log_countfunction xfs_calc_mkdir_reservationfunction xfs_symlink_log_countfunction lengthfunction inodefunction xfs_calc_ichange_reservationfunction xfs_calc_growdata_reservationfunction transactionsfunction transactionsfunction transactions
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
* Copyright (C) 2010 Red Hat, Inc.
* All Rights Reserved.
*/
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include "xfs_inode.h"
#include "xfs_bmap_btree.h"
#include "xfs_quota.h"
#include "xfs_trans.h"
#include "xfs_qm.h"
#include "xfs_trans_space.h"
#include "xfs_rtbitmap.h"
#include "xfs_attr_item.h"
#include "xfs_log.h"
#include "xfs_defer.h"
#include "xfs_bmap_item.h"
#include "xfs_extfree_item.h"
#include "xfs_rmap_item.h"
#include "xfs_refcount_item.h"
#include "xfs_trace.h"
#define _ALLOC true
#define _FREE false
/*
* A buffer has a format structure overhead in the log in addition
* to the data, so we need to take this into account when reserving
* space in a transaction for a buffer. Round the space required up
* to a multiple of 128 bytes so that we don't change the historical
* reservation that has been used for this overhead.
*/
STATIC uint
xfs_buf_log_overhead(void)
{
return round_up(sizeof(struct xlog_op_header) +
sizeof(struct xfs_buf_log_format), 128);
}
/*
* Calculate out transaction log reservation per item in bytes.
*
* The nbufs argument is used to indicate the number of items that
* will be changed in a transaction. size is used to tell how many
* bytes should be reserved per item.
*/
STATIC uint
xfs_calc_buf_res(
uint nbufs,
uint size)
{
return nbufs * (size + xfs_buf_log_overhead());
}
/*
* Per-extent log reservation for the btree changes involved in freeing or
* allocating an extent. In classic XFS there were two trees that will be
* modified (bnobt + cntbt). With rmap enabled, there are three trees
* (rmapbt). The number of blocks reserved is based on the formula:
*
* num trees * ((2 blocks/level * max depth) - 1)
*
* Keep in mind that max depth is calculated separately for each type of tree.
*/
uint
xfs_allocfree_block_count(
struct xfs_mount *mp,
uint num_ops)
{
uint blocks;
blocks = num_ops * 2 * (2 * mp->m_alloc_maxlevels - 1);
if (xfs_has_rmapbt(mp))
blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1);
return blocks;
}
/*
* Per-extent log reservation for refcount btree changes. These are never done
* in the same transaction as an allocation or a free, so we compute them
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_da_format.h`.
- Detected declarations: `function Copyright`, `function xfs_calc_buf_res`, `function modified`, `function xfs_refcountbt_block_count`, `function xfs_rtrefcountbt_block_count`, `function xfs_calc_inode_res`, `function btrees`, `function allocation`, `function headers`, `function splits`.
- 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.