Skip to content

Commit 8d7a434

Browse files
committed
obj: make sure footers are written for all huge memory blocks on...
... chunk reinit Huge memory blocks with the header chunk of type CHUNK_TYPE_FREE had not reinitialized their footer chunk. - Allocator divides the available space into zones and zones into smaller chunks. - All chunk headers belonging to a single zone are stored in an array. - Chunk header describes its: type, size_idx and flags. - Chunk can be of a few types. The types important for this patch are: CHUNK_TYPE_FOOTER, CHUNK_TYPE_FREE, and CHUNK_TYPE_USED. - CHUNK_TYPE_FREE and _USED are chunk types marking the beginning of so called huge memory block. This means this chunk and a number of chunks following it (size_idx) constitues a single allocation or a free memory. - The last chunk belonging to a huge memory block ought to be of type CHUNK_TYPE_FOOTER. Its size_idx allows to easily find the first chunk belonging to this huge memory block and determine the huge memory block type. - Huge memory blocks' footers are written immediately but persited lazily. It is not a problem at runtime since the footers are there at runtime. But in case of a crash the footers may be not persisted properly and missing on open. So, when the allocator is booted up it recreates footers just in case any of them is missing. Note: The huge memory block's first chunk header and the last chunk header (footer) are not written nor persisted in any way transactionally. The first chunk header occupies only 8 bytes so it is written and persisted atomically. But its footer is written independently and not explicitly persisted. Note: The first chunk header contains all the required info to recreate footer. The last chunk header is there only to make huge memory blocks coalescing easier to compute. Reading the footer allows to immediately find the memory block leaving just before the memory block which neighbours one might want to find. This patch makes sure the huge memory block's footer is recreated no matter whather its type is CHUNK_TYPE_FREE or CHUNK_TYPE_USED. The patch is inspired by work done for DAOS' DAV allocator (DAOS-18195) which is heavily based on the PMEMOBJ allocator. Signed-off-by: Jan Michalski <jan-marian.michalski@hpe.com> Inspired-by: Sherin T George <sherin-t.george@hpe.com>
1 parent 395360f commit 8d7a434

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
XXX
2+
3+
* Version X.X.X
4+
5+
- Fix a very unlikely issue in the PMEMOBJ allocator with a potential to corrupt the allocator's metadata (daos-stack/pmdk#24, DAOS-18195).
6+
17
Tue Nov 4 2025 Oksana Sałyk <oksana.salyk@hpe.com>
28

39
* Version 2.1.2

src/libpmemobj/memblock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
/* Copyright 2016-2024, Intel Corporation */
3+
/* Copyright 2025, Hewlett Packard Enterprise Development LP */
34

45
/*
56
* memblock.c -- implementation of memory block
@@ -1185,8 +1186,8 @@ static void
11851186
huge_reinit_chunk(const struct memory_block *m)
11861187
{
11871188
struct chunk_header *hdr = heap_get_chunk_hdr(m->heap, m);
1188-
if (hdr->type == CHUNK_TYPE_USED)
1189-
huge_write_footer(hdr, hdr->size_idx);
1189+
ASSERT(hdr->type == CHUNK_TYPE_USED || hdr->type == CHUNK_TYPE_FREE);
1190+
huge_write_footer(hdr, hdr->size_idx);
11901191
}
11911192

11921193
/*

0 commit comments

Comments
 (0)