linux/drivers/md/dm-vdo/geometry.h
Matthew Sakai 4390aa138b dm vdo: add deduplication configuration structures
Add structures which record the configuration of various deduplication
index parameters. This also includes facilities for saving and loading the
configuration and validating its integrity.

Co-developed-by: J. corwin Coburn <corwin@hurlbutnet.net>
Signed-off-by: J. corwin Coburn <corwin@hurlbutnet.net>
Co-developed-by: Michael Sclafani <dm-devel@lists.linux.dev>
Signed-off-by: Michael Sclafani <dm-devel@lists.linux.dev>
Co-developed-by: Thomas Jaskiewicz <tom@jaskiewicz.us>
Signed-off-by: Thomas Jaskiewicz <tom@jaskiewicz.us>
Co-developed-by: John Wiele <jwiele@redhat.com>
Signed-off-by: John Wiele <jwiele@redhat.com>
Signed-off-by: Matthew Sakai <msakai@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
2024-02-20 13:43:14 -05:00

139 lines
4.5 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2023 Red Hat
*/
#ifndef UDS_GEOMETRY_H
#define UDS_GEOMETRY_H
#include "uds.h"
/*
* The geometry records parameters that define the layout of a UDS index volume, and the size and
* shape of various index structures. It is created when the index is created, and is referenced by
* many index sub-components.
*/
struct geometry {
/* Size of a chapter page, in bytes */
size_t bytes_per_page;
/* Number of record pages in a chapter */
u32 record_pages_per_chapter;
/* Total number of chapters in a volume */
u32 chapters_per_volume;
/* Number of sparsely-indexed chapters in a volume */
u32 sparse_chapters_per_volume;
/* Number of bits used to determine delta list numbers */
u8 chapter_delta_list_bits;
/* Virtual chapter remapped from physical chapter 0 */
u64 remapped_virtual;
/* New physical chapter where the remapped chapter can be found */
u64 remapped_physical;
/*
* The following properties are derived from the ones above, but they are computed and
* recorded as fields for convenience.
*/
/* Total number of pages in a volume, excluding the header */
u32 pages_per_volume;
/* Total number of bytes in a volume, including the header */
size_t bytes_per_volume;
/* Number of pages in a chapter */
u32 pages_per_chapter;
/* Number of index pages in a chapter index */
u32 index_pages_per_chapter;
/* Number of records that fit on a page */
u32 records_per_page;
/* Number of records that fit in a chapter */
u32 records_per_chapter;
/* Number of records that fit in a volume */
u64 records_per_volume;
/* Number of delta lists per chapter index */
u32 delta_lists_per_chapter;
/* Mean delta for chapter indexes */
u32 chapter_mean_delta;
/* Number of bits needed for record page numbers */
u8 chapter_payload_bits;
/* Number of bits used to compute addresses for chapter delta lists */
u8 chapter_address_bits;
/* Number of densely-indexed chapters in a volume */
u32 dense_chapters_per_volume;
};
enum {
/* The number of bytes in a record (name + metadata) */
BYTES_PER_RECORD = (UDS_RECORD_NAME_SIZE + UDS_RECORD_DATA_SIZE),
/* The default length of a page in a chapter, in bytes */
DEFAULT_BYTES_PER_PAGE = 1024 * BYTES_PER_RECORD,
/* The default maximum number of records per page */
DEFAULT_RECORDS_PER_PAGE = DEFAULT_BYTES_PER_PAGE / BYTES_PER_RECORD,
/* The default number of record pages in a chapter */
DEFAULT_RECORD_PAGES_PER_CHAPTER = 256,
/* The default number of record pages in a chapter for a small index */
SMALL_RECORD_PAGES_PER_CHAPTER = 64,
/* The default number of chapters in a volume */
DEFAULT_CHAPTERS_PER_VOLUME = 1024,
/* The default number of sparsely-indexed chapters in a volume */
DEFAULT_SPARSE_CHAPTERS_PER_VOLUME = 0,
/* The log2 of the default mean delta */
DEFAULT_CHAPTER_MEAN_DELTA_BITS = 16,
/* The log2 of the number of delta lists in a large chapter */
DEFAULT_CHAPTER_DELTA_LIST_BITS = 12,
/* The log2 of the number of delta lists in a small chapter */
SMALL_CHAPTER_DELTA_LIST_BITS = 10,
/* The number of header pages per volume */
HEADER_PAGES_PER_VOLUME = 1,
};
int __must_check uds_make_geometry(size_t bytes_per_page, u32 record_pages_per_chapter,
u32 chapters_per_volume,
u32 sparse_chapters_per_volume, u64 remapped_virtual,
u64 remapped_physical,
struct geometry **geometry_ptr);
int __must_check uds_copy_geometry(struct geometry *source,
struct geometry **geometry_ptr);
void uds_free_geometry(struct geometry *geometry);
u32 __must_check uds_map_to_physical_chapter(const struct geometry *geometry,
u64 virtual_chapter);
/*
* Check whether this geometry is reduced by a chapter. This will only be true if the volume was
* converted from a non-lvm volume to an lvm volume.
*/
static inline bool __must_check uds_is_reduced_geometry(const struct geometry *geometry)
{
return !!(geometry->chapters_per_volume & 1);
}
static inline bool __must_check uds_is_sparse_geometry(const struct geometry *geometry)
{
return geometry->sparse_chapters_per_volume > 0;
}
bool __must_check uds_has_sparse_chapters(const struct geometry *geometry,
u64 oldest_virtual_chapter,
u64 newest_virtual_chapter);
bool __must_check uds_is_chapter_sparse(const struct geometry *geometry,
u64 oldest_virtual_chapter,
u64 newest_virtual_chapter,
u64 virtual_chapter_number);
u32 __must_check uds_chapters_to_expire(const struct geometry *geometry,
u64 newest_chapter);
#endif /* UDS_GEOMETRY_H */