Skip to content

[UDFS] Implement faster free space search via roving pointer and allocation optimisations#346

Draft
Copilot wants to merge 10 commits into
udf-devfrom
copilot/udfs-implement-faster-free-space-search
Draft

[UDFS] Implement faster free space search via roving pointer and allocation optimisations#346
Copilot wants to merge 10 commits into
udf-devfrom
copilot/udfs-implement-faster-free-space-search

Conversation

Copy link
Copy Markdown

Copilot AI commented May 2, 2026

Implements a roving-pointer bitmap search hint and several allocation optimisations for the UDF filesystem driver to reduce I/O overhead when allocating file entries and creating many files.

Changes

Roving-pointer bitmap search hint (BitmapSearchHint)

  • Added BitmapSearchHint field to the VCB (struct.h)
  • UDFAllocFreeExtent_ now starts the bitmap scan at the hint LBA and falls back to a full-range scan when the hint-range yields nothing, advancing and persisting the hint after each successful allocation (alloc.cpp)
  • AdPrint diagnostics added for hint application, fallback, and persistence
  • UDFAllocateFESpace and UDFResizeExtent now call UDFAllocFreeExtent directly for the full partition range — the BitmapSearchHint roving pointer inside UDFAllocFreeExtent_ provides locality automatically by starting each scan near the last successful allocation, replacing the previous LastAllocatedFELba window-probe mechanism (extent.cpp)

Minimum directory pre-allocation (UDF_DIR_PREALLOC_MIN_SECTORS=8)

  • Directory data extents are now pre-allocated with at least 8 sectors (rounded up to WriteBlockSize) to amortise per-sector cold-write spikes across many file additions (udf_info.cpp)

Coalesced FE sector write (UDF_FE_FLAG_NEW_SECTOR)

  • Added UDF_FE_FLAG_NEW_SECTOR flag (udf_rel.h)
  • In UDFCreateFile__ (non-CDR path), the explicit zero-write of the FE sector is skipped and the flag is set instead
  • UDFFlushFE checks the flag and writes a single zero-padded full-sector buffer, reducing the previous 2-I/O sequence to 1 I/O per file creation (udf_info.cpp)

UDFRecordDirectory__ correctness fix

  • Added a UDFFlushFE call after UDFIndexDirectory so the on-disk FE reflects the updated fileType = DIRECTORY immediately, preventing a corrupt FE on crash-before-close (udf_info.cpp)

Copilot AI and others added 2 commits May 2, 2026 00:21
Copilot AI changed the title [WIP] Add faster method for finding free space during file creation [UDFS] Implement faster free space search via roving pointer May 2, 2026
Copilot AI requested a review from Zero3K20 May 2, 2026 00:24
Copilot AI added a commit that referenced this pull request May 2, 2026
…ointer in alloc.c

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/d6dc60b1-2014-42b3-89fd-578ad73aa8ce

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
@Zero3K20 Zero3K20 requested a review from Copilot May 5, 2026 01:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a simple “roving pointer” hint to UDFS free-space allocation so the bitmap scan can start near the last successful allocation (reducing repeated scans from the beginning of a partition), along with additional AdPrint diagnostics to trace hint application, fallback, and persistence.

Changes:

  • Introduce VCB::BitmapSearchHint to remember the next preferred LBA search start for free space allocation.
  • Update UDFAllocFreeExtent_ to:
    • apply the hint when it falls within the caller’s [SearchStart, SearchLim) range,
    • fall back to a full-range scan when the hint-range yields nothing,
    • advance and persist the hint on successful allocation.
  • Add AdPrint messages for hint application, fallback, and updates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
drivers/filesystems/udfs/udf_info/alloc.cpp Applies/persists a bitmap search hint during free extent allocation, with debug tracing.
drivers/filesystems/udfs/struct.h Adds BitmapSearchHint to VCB to store the roving-pointer LBA hint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented May 5, 2026

@copilot Is/are there any other code block(s) that can benefit from the same improvement?

Copy link
Copy Markdown
Author

Copilot AI commented May 5, 2026

@copilot Is/are there any other code block(s) that can benefit from the same improvement?

No other code blocks can benefit from the same improvement. UDFFindMinSuitableExtent is the only function that linearly scans the bitmap for a free extent, and every call to it already goes through UDFAllocFreeExtent_ which applies the hint via EffectiveSearchStart. The other bitmap functions (UDFGetPartFreeSpace/UDFGetFreeSpace, UDFMarkSpaceAsXXX*, UDFCheckSpaceAllocation_) either count bits, mark known ranges, or validate existing mappings — none of them search for free space, so the roving-pointer hint is not applicable to them.

@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented May 5, 2026

@copilot Does any other code do full disk searching?

Copy link
Copy Markdown
Author

Copilot AI commented May 5, 2026

@copilot Does any other code do full disk searching?

Yes, several functions iterate over all partition blocks, but none of them are doing a free-space search that could benefit from a roving pointer:

  • UDFUpdateXSpaceBitmap (mount.cpp ~256–275) — writes the on-disk bitmap by diffing old vs. new bitmaps; must cover every block.
  • UDFAddXSpaceBitmap (mount.cpp ~1638–1688) — mount-time import of an on-disk Space Bitmap Descriptor into the in-memory FSBM; must process all bits for correctness.
  • UDFUpdateNonAllocated (mount.cpp ~896–911) — scans all blocks to locate bad blocks (BSBM) and register them in the NonAllocatable file; must cover the whole range.
  • UDFLoadVAT (udf_info.cpp ~3937–3955) — syncs all VAT entries → FSBM at mount time; must iterate every VAT slot.
  • UDFRecordVAT (udf_info.cpp ~5071–5073) — syncs FSBM → VAT at unmount; same requirement.
  • UDFGetVolumeBitmap (fscntrl.cpp ~1380–1383) — copies bits in response to FSCTL_GET_VOLUME_BITMAP; the start position is caller-supplied and it just copies, not searches.

All of these must process their entire range by design (initialization, sync, or full export). The roving-pointer hint only applies when searching for the best free extent to satisfy an allocation request, which only UDFFindMinSuitableExtent via UDFAllocFreeExtent_ does.

@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented May 5, 2026

@copilot Can any of the performance improvements from #335 be implemented?

…tion, dir pre-alloc, coalesced FE write

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/06cc0c82-c9cd-4105-8d76-e0c33424d7bf

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented May 5, 2026

@copilot Can any of the performance improvements from #335 be implemented?

Yes — all three optimizations from PR #335 are now implemented in commit 362b9b1a:

  1. Locality-based FE allocation (LastAllocatedFELba)UDFAllocateFESpace now uses a 3-probe strategy: ① locality window around the parent directory's FE, ② locality window around the most recently allocated FE (LastAllocatedFELba), ③ full-partition fallback. UDFResizeExtent also tries the LastAllocatedFELba window before falling back to a full-partition scan when appending a new fragment.

  2. Minimum directory pre-allocation (UDF_DIR_PREALLOC_MIN_SECTORS=8)UDFWriteFile__ now pre-allocates at least 8 sectors (rounded up to WriteBlockSize) for new directory extents, amortising repeated small-allocation overhead when many files are created.

  3. Coalesced FE sector write (UDF_FE_FLAG_NEW_SECTOR)UDFCreateFile__ (non-CDR path) no longer does an explicit zero-write; instead it sets the flag and UDFFlushFE writes a single zero-padded full-sector buffer, reducing the per-file I/O count.

Additionally, UDFRecordDirectory__ now flushes the FE after UDFIndexDirectory so the on-disk FE reflects the updated fileType = DIRECTORY immediately.

Copilot AI changed the title [UDFS] Implement faster free space search via roving pointer [UDFS] Implement faster free space search via roving pointer and locality-based allocation May 5, 2026
@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented May 5, 2026

@copilot How about switching number 1 in the list to use the roving pointer instead?

Copilot AI and others added 2 commits May 5, 2026 20:32
… roving pointer

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/3e5c385c-9e82-46b0-b8f3-9a2ff7c4f30d

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
…edundant calls

Agent-Logs-Url: https://github.com/Zero3K20/reactos/sessions/3e5c385c-9e82-46b0-b8f3-9a2ff7c4f30d

Co-authored-by: Zero3K20 <258969903+Zero3K20@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented May 5, 2026

@copilot How about switching number 1 in the list to use the roving pointer instead?

Done in commit d3867a46. UDFAllocateFESpace now simply calls UDFAllocFreeExtent for the full partition range — the BitmapSearchHint roving pointer inside UDFAllocFreeExtent_ already starts the bitmap scan near the last successful allocation, so no separate LastAllocatedFELba field or window-probe logic is needed. UDFResizeExtent's new-fragment path was simplified the same way. The LastAllocatedFELba VCB field and LOCALITY_WINDOW_BLOCKS macro were removed.

Copilot AI changed the title [UDFS] Implement faster free space search via roving pointer and locality-based allocation [UDFS] Implement faster free space search via roving pointer and allocation optimisations May 5, 2026
@Zero3K20
Copy link
Copy Markdown
Owner

Zero3K20 commented May 5, 2026

@copilot shouldn't the other performance improvements be kept?

Copy link
Copy Markdown
Author

Copilot AI commented May 5, 2026

@copilot shouldn't the other performance improvements be kept?

Yes, all the other improvements are still present — only the LastAllocatedFELba window-probe mechanism in UDFAllocateFESpace/UDFResizeExtent was replaced with the roving pointer:

  • UDF_DIR_PREALLOC_MIN_SECTORS=8 — still in udf_info.cpp
  • UDF_FE_FLAG_NEW_SECTOR coalesced FE write — still in udf_info.cpp
  • UDFRecordDirectory__ UDFFlushFE after UDFIndexDirectory — still in udf_info.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UDFS] Implement faster way of finding free space when creating files and directories

4 participants