Skip to content

feat: add sector-aligned mmap flush#3

Open
jgwesterlund wants to merge 1 commit intofeat/write-coalescingfrom
feat/sector-aligned-flush
Open

feat: add sector-aligned mmap flush#3
jgwesterlund wants to merge 1 commit intofeat/write-coalescingfrom
feat/sector-aligned-flush

Conversation

@jgwesterlund
Copy link
Owner

Pull Request

What does this change do?

Adds a sector_size parameter to flush only the sector-aligned mmap regions covering written data, instead of flushing the entire mapping. Integrates with both direct writes and wrap marker writes.

Why is this needed?

On block devices with specific sector sizes (e.g., SD cards with 512 or 4096-byte sectors), full-mapping flushes are expensive. Sector-aligned flushing targets only the modified sectors, improving write performance on constrained devices.

Type of change

  • Feature

How was this tested?

4 new tests in tests/test_extended.py:

  • Sector-aligned flush called with correctly aligned params
  • Wrap-around case (flush tail + head regions)
  • sector_size=0 falls back to normal flush
  • Various sector sizes (512, 1024, 4096, 8192)

All 47 tests pass, 98% coverage, ruff clean, mypy clean.

Checklist

  • I tested this locally
  • I didn't reformat the entire repo
  • I wrote sane commit messages
  • I read the contributing guide
  • This probably won't summon new bugs

Notes for reviewers

This PR is based on feat/write-coalescing (PR #2) since sector-aligned flush integrates with the coalesced flush path.

The flush alignment uses max(sector_size, mmap.PAGESIZE) to satisfy macOS page-alignment requirements for msync.

Docs updated: usage.md, api.md.

Add sector_size parameter to flush only aligned mmap regions covering
written data instead of the entire mapping. Integrates with both direct
writes and wrap marker writes. Falls back to full flush when sector_size=0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant