[FEATURE] Resize owned allocations within their original region #3

Open
opened 2026-10-24 08:15:46 +02:00 by erikinkinen · 1 comment
Owner

Problem and motivation

Growing a native tool buffer currently allocates its full replacement before returning the old block. That can fail when the original region has enough adjacent free bytes for the growth but cannot hold both complete buffers. Image assembly and whole-file inputs need useful growth within their explicitly supplied workspace.

Proposed behavior and scope

Add an original-pointer resize operation to ReservedHeap. Grow into an adjacent free extent, return a shrunken tail to the same free list, and preserve alignment and the retained payload prefix. RegionAllocator should use it for GlobalAlloc reallocation, then use the existing allocate/copy/return path when moving is necessary.

Authority, security and reliability

Every operation retains the same original writable region and its caller-owned backing lifetime. The live pointer and exact current Layout remain mandatory unsafe caller premises. Resizing acquires no memory, mapping, service or replacement arena. Check geometry before mutation; failed growth preserves the original allocation. Serialize the complete adapter operation under its existing guard, with no external or allocating callback. Allocation counts and complete-drain observations must remain accurate.

Acceptance criteria

  • Grow in place when only the additional adjacent bytes fit, preserving alignment, the prefix and unrelated live allocations.
  • Shrink and coalesce returned tails, including unchanged rounded size classes, without hidden per-allocation headers.
  • Preserve the original allocation and free geometry on refused growth or invalid target geometry.
  • Move only after obtaining complete replacement storage; preserve the prefix, original region and outstanding count through success and failure.
  • Cover guarded memory, fragmentation, exact capacity, alignment and serialized concurrent lifetimes; document pointer and final-backing obligations inline and in the manual.
  • Confirm native tool consumers use the common adapter and retain their existing workspace and final-retirement boundaries.

Alternatives and tradeoffs

Keeping the default allocate/copy/return path is simple but requires a second full extent even for adjacent growth. Raising workspace budgets leaves that avoidable requirement in place. In-place growth remains conditional on actual contiguous free bytes; fragmentation can still require a move or an explicit allocation refusal. No measured runtime speedup is claimed.

Tracking and rollout

Build on the owned-region contract and shared library review. Coordinate native Boot and SHA consumers through their existing shared LibCli workspace. Keep Kernel backing acquisition and native grant retirement with their original owners.

## Problem and motivation Growing a native tool buffer currently allocates its full replacement before returning the old block. That can fail when the original region has enough adjacent free bytes for the growth but cannot hold both complete buffers. Image assembly and whole-file inputs need useful growth within their explicitly supplied workspace. ## Proposed behavior and scope Add an original-pointer resize operation to ReservedHeap. Grow into an adjacent free extent, return a shrunken tail to the same free list, and preserve alignment and the retained payload prefix. RegionAllocator should use it for GlobalAlloc reallocation, then use the existing allocate/copy/return path when moving is necessary. ## Authority, security and reliability Every operation retains the same original writable region and its caller-owned backing lifetime. The live pointer and exact current Layout remain mandatory unsafe caller premises. Resizing acquires no memory, mapping, service or replacement arena. Check geometry before mutation; failed growth preserves the original allocation. Serialize the complete adapter operation under its existing guard, with no external or allocating callback. Allocation counts and complete-drain observations must remain accurate. ## Acceptance criteria - [x] Grow in place when only the additional adjacent bytes fit, preserving alignment, the prefix and unrelated live allocations. - [x] Shrink and coalesce returned tails, including unchanged rounded size classes, without hidden per-allocation headers. - [x] Preserve the original allocation and free geometry on refused growth or invalid target geometry. - [x] Move only after obtaining complete replacement storage; preserve the prefix, original region and outstanding count through success and failure. - [ ] Cover guarded memory, fragmentation, exact capacity, alignment and serialized concurrent lifetimes; document pointer and final-backing obligations inline and in the manual. - [ ] Confirm native tool consumers use the common adapter and retain their existing workspace and final-retirement boundaries. ## Alternatives and tradeoffs Keeping the default allocate/copy/return path is simple but requires a second full extent even for adjacent growth. Raising workspace budgets leaves that avoidable requirement in place. In-place growth remains conditional on actual contiguous free bytes; fragmentation can still require a move or an explicit allocation refusal. No measured runtime speedup is claimed. ## Tracking and rollout Build on the [owned-region contract](https://git.erikinkinen.fi/erix/lib-owned-region/issues/1) and [shared library review](https://git.erikinkinen.fi/erix/lib-owned-region/pulls/2). Coordinate native Boot and SHA consumers through their existing shared LibCli workspace. Keep Kernel backing acquisition and native grant retirement with their original owners.
Author
Owner

Published 494312f3: allocations can grow into adjacent free space and return shrunken tails to their own region. The serialized adapter uses that path before allocating a replacement, preserving the live prefix and allocation count. Boot and SHA keep the shared adapter and their existing backing lifetimes.

The library PR now includes resizing and the remaining consumer work.

Published `494312f3`: allocations can grow into adjacent free space and return shrunken tails to their own region. The serialized adapter uses that path before allocating a replacement, preserving the live prefix and allocation count. Boot and SHA keep the shared adapter and their existing backing lifetimes. The [library PR](https://git.erikinkinen.fi/erix/lib-owned-region/pulls/2) now includes resizing and the remaining consumer work.
erikinkinen added this to the Alpha 1 milestone 2026-10-30 09:34:48 +01:00
Sign in to join this conversation.
No description provided.