Page MenuHomeFreeBSD

Ensure I/O buffers in fsck_ffs(8) are 64-byte aligned
AbandonedPublic

Authored by mckusick on Sep 5 2023, 9:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 1, 12:57 AM
Unknown Object (File)
Sep 29 2024, 9:38 PM
Unknown Object (File)
Sep 29 2024, 7:30 PM
Unknown Object (File)
Sep 25 2024, 10:20 AM
Unknown Object (File)
Sep 24 2024, 4:39 AM
Unknown Object (File)
Sep 15 2024, 11:20 PM
Unknown Object (File)
Sep 12 2024, 6:40 PM
Unknown Object (File)
Sep 8 2024, 6:52 PM
Subscribers

Details

Reviewers
kib
lwhsu
Summary

Various disk controllers require their buffers to be aligned to 64 bytes. For buffers allocated in structures, ensure that they are 64-byte aligned.

Create a new Balloc() function in fsck_ffs(8) that allocates 64-byte aligned memory to use when allocating memory that will be used for doing disk I/O. Go through and change all buffer allocations to call Balloc().

On 64-bit architectures, malloc always returns 64-bit aligned allocations, so this change should have no effect. But if a bigger alignment requirement (say 128) comes down in the future, it will be trivial to implement it.

Test Plan

The aligned I/O problems most recent showed up in Azure, so test that it is works on Azure.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

mckusick added reviewers: kib, lwhsu.

Same general comments s for the other review: don't hard code 64, document which controllers, and consider just doing this all page aligned.

sbin/fsck_ffs/suj.c
2277

And maybe make this allocated with mem_aligned() for a PAGE_SIZE alignment (or the sysconf returned value since arm64 is now both 4k and 64k page sized).

Updates reflecting comments from kib.

Please use git diff -U999999 ... or like to generate patches, so that the context is available.

sbin/fsck_ffs/fsck.h
433

static inline void *

439

It is simpler to just fail on aligned_alloc() failure without trying to free one buffer, IMO. Malloc() failures mean that UVA is exhausted and/or fragmented, and apps usually cannot get out of it.

Relevant parts of these changes were incorporated in commit 772430dd6795585 as discussed in PR 267654 and review https://reviews.freebsd.org/D41724.