Remove the unused number of data disks from the vector allocation

The same addressing rules are applied to the parity disks because
they are used as data disks during recovery operations.
This commit is contained in:
Andrea Mazzoleni 2026-06-02 21:32:21 +02:00
parent 9522d57691
commit 24389023ad
11 changed files with 21 additions and 24 deletions

View file

@ -967,7 +967,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
/* we need 1 * data + 2 * parity + 1 * zero */
buffermax = diskmax + 2 * state->level + 1;
buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc);
buffer = malloc_nofail_vector_align(buffermax, state->block_size, &buffer_alloc);
if (!state->opt.skip_self)
mtest_vector(buffermax, state->block_size, buffer);

View file

@ -970,9 +970,9 @@ void io_init(struct snapraid_io* io, struct snapraid_state* state,
allocated_size = 0;
for (i = 0; i < io->io_max; ++i) {
if (state->file_mode != ADVISE_DIRECT)
io->buffer_map[i] = malloc_nofail_vector_align(handle_max, buffer_max, block_size, &io->buffer_alloc_map[i]);
io->buffer_map[i] = malloc_nofail_vector_align(buffer_max, block_size, &io->buffer_alloc_map[i]);
else
io->buffer_map[i] = malloc_nofail_vector_direct(handle_max, buffer_max, block_size, &io->buffer_alloc_map[i]);
io->buffer_map[i] = malloc_nofail_vector_direct(buffer_max, block_size, &io->buffer_alloc_map[i]);
if (!state->opt.skip_self)
mtest_vector(io->buffer_max, state->block_size, io->buffer_map[i]);
allocated_size += block_size * buffer_max;

View file

@ -85,7 +85,7 @@ void speed(int period, int nd, int size)
nv = nd + RAID_PARITY_MAX + 1;
v = malloc_nofail_vector_align(nd, nv, size, &v_alloc);
v = malloc_nofail_vector_align(nv, size, &v_alloc);
/* initialize disks with fixed data */
for (i = 0; i < nd; ++i)

View file

@ -686,7 +686,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
io_init(&io, state, state->opt.io_cache, buffermax, handle, diskmax, 0, sync_data_reader, 0, parity_handle, state->level, 0, 0, sync_parity_writer);
/* allocate the copy buffer */
copy = malloc_nofail_vector_align(diskmax, diskmax, state->block_size, &copy_alloc);
copy = malloc_nofail_vector_align(diskmax, state->block_size, &copy_alloc);
/* allocate and fill the zero buffer */
zero = malloc_nofail_align(state->block_size, &zero_alloc);

View file

@ -43,11 +43,11 @@ void* malloc_nofail_direct(size_t size, void** freeptr)
return ptr;
}
void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr)
void** malloc_nofail_vector_align(int n, size_t size, void** freeptr)
{
void* ptr;
ptr = raid_malloc_vector(nd, n, size, freeptr);
ptr = raid_malloc_vector(n, size, freeptr);
if (!ptr) {
/* LCOV_EXCL_START */
@ -59,11 +59,11 @@ void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr)
return ptr;
}
void** malloc_nofail_vector_direct(int nd, int n, size_t size, void** freeptr)
void** malloc_nofail_vector_direct(int n, size_t size, void** freeptr)
{
void* ptr;
ptr = raid_malloc_vector_align(nd, n, size, direct_size(), 0, freeptr);
ptr = raid_malloc_vector_align(n, size, direct_size(), 0, freeptr);
if (!ptr) {
/* LCOV_EXCL_START */

View file

@ -23,13 +23,13 @@ void* malloc_nofail_direct(size_t size, void** freeptr);
* Safe aligned vector allocation.
* If no memory is available, it aborts.
*/
void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr);
void** malloc_nofail_vector_align(int n, size_t size, void** freeptr);
/**
* Safe page vector allocation. Usable for direct io.
* If no memory is available, it aborts.
*/
void** malloc_nofail_vector_direct(int nd, int n, size_t size, void** freeptr);
void** malloc_nofail_vector_direct(int n, size_t size, void** freeptr);
/**
* Safe allocation with memory test.