|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/slabSummary.c#7 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "slabSummary.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "memoryAlloc.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "adminState.h"
|
|
Packit Service |
b3514a |
#include "constants.h"
|
|
Packit Service |
b3514a |
#include "extent.h"
|
|
Packit Service |
b3514a |
#include "readOnlyNotifier.h"
|
|
Packit Service |
b3514a |
#include "slabSummaryInternals.h"
|
|
Packit Service |
b3514a |
#include "threadConfig.h"
|
|
Packit Service |
b3514a |
#include "types.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// SIZING
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static BlockCount getSlabSummaryZoneSize(BlockSize blockSize)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabCount entriesPerBlock = blockSize / sizeof(SlabSummaryEntry);
|
|
Packit Service |
b3514a |
BlockCount blocksNeeded = MAX_SLABS / entriesPerBlock;
|
|
Packit Service |
b3514a |
return blocksNeeded;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
BlockCount getSlabSummarySize(BlockSize blockSize)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return getSlabSummaryZoneSize(blockSize) * MAX_PHYSICAL_ZONES;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// FULLNESS HINT COMPUTATION
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Translate a slab's free block count into a 'fullness hint' that can be
|
|
Packit Service |
b3514a |
* stored in a SlabSummaryEntry's 7 bits that are dedicated to its free count.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Note: the number of free blocks must be strictly less than 2^23 blocks,
|
|
Packit Service |
b3514a |
* even though theoretically slabs could contain precisely 2^23 blocks; there
|
|
Packit Service |
b3514a |
* is an assumption that at least one block is used by metadata. This
|
|
Packit Service |
b3514a |
* assumption is necessary; otherwise, the fullness hint might overflow.
|
|
Packit Service |
b3514a |
* The fullness hint formula is roughly (fullness >> 16) & 0x7f, but
|
|
Packit Service |
b3514a |
* ((1 << 23) >> 16) & 0x7f is the same as (0 >> 16) & 0x7f, namely 0, which
|
|
Packit Service |
b3514a |
* is clearly a bad hint if it could indicate both 2^23 free blocks or 0 free
|
|
Packit Service |
b3514a |
* blocks.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summary The summary which is being updated
|
|
Packit Service |
b3514a |
* @param freeBlocks The number of free blocks
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return A fullness hint, which can be stored in 7 bits.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
static uint8_t computeFullnessHint(SlabSummary *summary, BlockCount freeBlocks)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
ASSERT_LOG_ONLY((freeBlocks < (1 << 23)),
|
|
Packit Service |
b3514a |
"free blocks must be less than 2^23");
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (freeBlocks == 0) {
|
|
Packit Service |
b3514a |
return 0;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
BlockCount hint = freeBlocks >> summary->hintShift;
|
|
Packit Service |
b3514a |
return ((hint == 0) ? 1 : hint);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Translate a slab's free block hint into an approximate count, such that
|
|
Packit Service |
b3514a |
* computeFullnessHint() is the inverse function of getApproximateFreeBlocks()
|
|
Packit Service |
b3514a |
* (i.e. computeFullnessHint(getApproximateFreeBlocks(x)) == x).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summary The summary from which the hint was obtained
|
|
Packit Service |
b3514a |
* @param freeBlockHint The hint read from the summary
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return An approximation to the free block count
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
static BlockCount getApproximateFreeBlocks(SlabSummary *summary,
|
|
Packit Service |
b3514a |
uint8_t freeBlockHint)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return ((BlockCount) freeBlockHint) << summary->hintShift;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// MAKE/FREE FUNCTIONS
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void launchWrite(SlabSummaryBlock *summaryBlock);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initialize a SlabSummaryBlock.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The backing layer
|
|
Packit Service |
b3514a |
* @param summaryZone The parent SlabSummaryZone
|
|
Packit Service |
b3514a |
* @param threadID The ID of the thread of physical zone of this block
|
|
Packit Service |
b3514a |
* @param entries The entries this block manages
|
|
Packit Service |
b3514a |
* @param index The index of this block in its zone's summary
|
|
Packit Service |
b3514a |
* @param slabSummaryBlock The block to intialize
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static int initializeSlabSummaryBlock(PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
ThreadID threadID,
|
|
Packit Service |
b3514a |
SlabSummaryEntry *entries,
|
|
Packit Service |
b3514a |
BlockCount index,
|
|
Packit Service |
b3514a |
SlabSummaryBlock *slabSummaryBlock)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
int result = ALLOCATE(VDO_BLOCK_SIZE, char, __func__,
|
|
Packit Service |
b3514a |
&slabSummaryBlock->outgoingEntries);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
result = createVIO(layer, VIO_TYPE_SLAB_SUMMARY, VIO_PRIORITY_METADATA,
|
|
Packit Service |
b3514a |
slabSummaryBlock, slabSummaryBlock->outgoingEntries,
|
|
Packit Service |
b3514a |
&slabSummaryBlock->vio);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
slabSummaryBlock->vio->completion.callbackThreadID = threadID;
|
|
Packit Service |
b3514a |
slabSummaryBlock->zone = summaryZone;
|
|
Packit Service |
b3514a |
slabSummaryBlock->entries = entries;
|
|
Packit Service |
b3514a |
slabSummaryBlock->index = index;
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Create a new, empty SlabSummaryZone object.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summary The summary to which the new zone will belong
|
|
Packit Service |
b3514a |
* @param layer The layer
|
|
Packit Service |
b3514a |
* @param zoneNumber The zone this is
|
|
Packit Service |
b3514a |
* @param threadID The ID of the thread for this zone
|
|
Packit Service |
b3514a |
* @param entries The buffer to hold the entries in this zone
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static int makeSlabSummaryZone(SlabSummary *summary,
|
|
Packit Service |
b3514a |
PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
ZoneCount zoneNumber,
|
|
Packit Service |
b3514a |
ThreadID threadID,
|
|
Packit Service |
b3514a |
SlabSummaryEntry *entries)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
int result = ALLOCATE_EXTENDED(SlabSummaryZone, summary->blocksPerZone,
|
|
Packit Service |
b3514a |
SlabSummaryBlock, __func__,
|
|
Packit Service |
b3514a |
&summary->zones[zoneNumber]);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
SlabSummaryZone *summaryZone = summary->zones[zoneNumber];
|
|
Packit Service |
b3514a |
summaryZone->summary = summary;
|
|
Packit Service |
b3514a |
summaryZone->zoneNumber = zoneNumber;
|
|
Packit Service |
b3514a |
summaryZone->entries = entries;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (layer->createMetadataVIO == NULL) {
|
|
Packit Service |
b3514a |
// Blocks are only used for writing, and without a createVIO() call,
|
|
Packit Service |
b3514a |
// we'll never be writing anything.
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Initialize each block.
|
|
Packit Service |
b3514a |
for (BlockCount i = 0; i < summary->blocksPerZone; i++) {
|
|
Packit Service |
b3514a |
result = initializeSlabSummaryBlock(layer, summaryZone, threadID, entries,
|
|
Packit Service |
b3514a |
i, &summaryZone->summaryBlocks[i]);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
entries += summary->entriesPerBlock;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int makeSlabSummary(PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
Partition *partition,
|
|
Packit Service |
b3514a |
const ThreadConfig *threadConfig,
|
|
Packit Service |
b3514a |
unsigned int slabSizeShift,
|
|
Packit Service |
b3514a |
BlockCount maximumFreeBlocksPerSlab,
|
|
Packit Service |
b3514a |
ReadOnlyNotifier *readOnlyNotifier,
|
|
Packit Service |
b3514a |
SlabSummary **slabSummaryPtr)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
BlockCount blocksPerZone = getSlabSummaryZoneSize(VDO_BLOCK_SIZE);
|
|
Packit Service |
b3514a |
SlabCount entriesPerBlock = MAX_SLABS / blocksPerZone;
|
|
Packit Service |
b3514a |
int result = ASSERT((entriesPerBlock * blocksPerZone) == MAX_SLABS,
|
|
Packit Service |
b3514a |
"block size must be a multiple of entry size");
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (partition == NULL) {
|
|
Packit Service |
b3514a |
// Don't make a slab summary for the formatter since it doesn't need it.
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
SlabSummary *summary;
|
|
Packit Service |
b3514a |
result = ALLOCATE_EXTENDED(SlabSummary, threadConfig->physicalZoneCount,
|
|
Packit Service |
b3514a |
SlabSummaryZone *, __func__, &summary);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
summary->zoneCount = threadConfig->physicalZoneCount;
|
|
Packit Service |
b3514a |
summary->readOnlyNotifier = readOnlyNotifier;
|
|
Packit Service |
b3514a |
summary->hintShift = (slabSizeShift > 6) ? (slabSizeShift - 6) : 0;
|
|
Packit Service |
b3514a |
summary->blocksPerZone = blocksPerZone;
|
|
Packit Service |
b3514a |
summary->entriesPerBlock = entriesPerBlock;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
size_t totalEntries = MAX_SLABS * MAX_PHYSICAL_ZONES;
|
|
Packit Service |
b3514a |
size_t entryBytes = totalEntries * sizeof(SlabSummaryEntry);
|
|
Packit Service |
b3514a |
result = layer->allocateIOBuffer(layer, entryBytes, "summary entries",
|
|
Packit Service |
b3514a |
(char **) &summary->entries);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
freeSlabSummary(&summary);
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Initialize all the entries.
|
|
Packit Service |
b3514a |
uint8_t hint = computeFullnessHint(summary, maximumFreeBlocksPerSlab);
|
|
Packit Service |
b3514a |
for (size_t i = 0; i < totalEntries; i++) {
|
|
Packit Service |
b3514a |
// This default tail block offset must be reflected in
|
|
Packit Service |
b3514a |
// slabJournal.c::readSlabJournalTail().
|
|
Packit Service |
b3514a |
summary->entries[i] = (SlabSummaryEntry) {
|
|
Packit Service |
b3514a |
.tailBlockOffset = 0,
|
|
Packit Service |
b3514a |
.fullnessHint = hint,
|
|
Packit Service |
b3514a |
.loadRefCounts = false,
|
|
Packit Service |
b3514a |
.isDirty = false,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
setSlabSummaryOrigin(summary, partition);
|
|
Packit Service |
b3514a |
for (ZoneCount zone = 0; zone < summary->zoneCount; zone++) {
|
|
Packit Service |
b3514a |
result = makeSlabSummaryZone(summary, layer, zone,
|
|
Packit Service |
b3514a |
getPhysicalZoneThread(threadConfig, zone),
|
|
Packit Service |
b3514a |
summary->entries + (MAX_SLABS * zone));
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
freeSlabSummary(&summary);
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
*slabSummaryPtr = summary;
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void freeSlabSummary(SlabSummary **slabSummaryPtr)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (*slabSummaryPtr == NULL) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
SlabSummary *summary = *slabSummaryPtr;
|
|
Packit Service |
b3514a |
for (ZoneCount zone = 0; zone < summary->zoneCount; zone++) {
|
|
Packit Service |
b3514a |
SlabSummaryZone *summaryZone = summary->zones[zone];
|
|
Packit Service |
b3514a |
if (summaryZone != NULL) {
|
|
Packit Service |
b3514a |
for (BlockCount i = 0; i < summary->blocksPerZone; i++) {
|
|
Packit Service |
b3514a |
freeVIO(&summaryZone->summaryBlocks[i].vio);
|
|
Packit Service |
b3514a |
FREE(summaryZone->summaryBlocks[i].outgoingEntries);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
FREE(summaryZone);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
FREE(summary->entries);
|
|
Packit Service |
b3514a |
FREE(summary);
|
|
Packit Service |
b3514a |
*slabSummaryPtr = NULL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
SlabSummaryZone *getSummaryForZone(SlabSummary *summary, ZoneCount zone)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return summary->zones[zone];
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// WRITING FUNCTIONALITY
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Check whether a summary zone has finished draining.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summaryZone The zone to check
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void checkForDrainComplete(SlabSummaryZone *summaryZone)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (!isDraining(&summaryZone->state) || (summaryZone->writeCount > 0)) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
finishOperationWithResult(&summaryZone->state,
|
|
Packit Service |
b3514a |
(isReadOnly(summaryZone->summary->readOnlyNotifier)
|
|
Packit Service |
b3514a |
? VDO_READ_ONLY : VDO_SUCCESS));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Wake all the waiters in a given queue. If the VDO is in read-only mode they
|
|
Packit Service |
b3514a |
* will be given a VDO_READ_ONLY error code as their context, otherwise they
|
|
Packit Service |
b3514a |
* will be given VDO_SUCCESS.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summaryZone The slab summary which owns the queue
|
|
Packit Service |
b3514a |
* @param queue The queue to notify
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void notifyWaiters(SlabSummaryZone *summaryZone, WaitQueue *queue)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
int result = (isReadOnly(summaryZone->summary->readOnlyNotifier)
|
|
Packit Service |
b3514a |
? VDO_READ_ONLY : VDO_SUCCESS);
|
|
Packit Service |
b3514a |
notifyAllWaiters(queue, NULL, &result);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Finish processing a block which attempted to write, whether or not the
|
|
Packit Service |
b3514a |
* attempt succeeded.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void finishUpdatingSlabSummaryBlock(SlabSummaryBlock *block)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
notifyWaiters(block->zone, &block->currentUpdateWaiters);
|
|
Packit Service |
b3514a |
block->writing = false;
|
|
Packit Service |
b3514a |
block->zone->writeCount--;
|
|
Packit Service |
b3514a |
if (hasWaiters(&block->nextUpdateWaiters)) {
|
|
Packit Service |
b3514a |
launchWrite(block);
|
|
Packit Service |
b3514a |
} else {
|
|
Packit Service |
b3514a |
checkForDrainComplete(block->zone);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* This is the callback for a successful block write.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param completion The write VIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void finishUpdate(VDOCompletion *completion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryBlock *block = completion->parent;
|
|
Packit Service |
b3514a |
atomicAdd64(&block->zone->summary->statistics.blocksWritten, 1);
|
|
Packit Service |
b3514a |
finishUpdatingSlabSummaryBlock(block);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Handle an error writing a slab summary block.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param completion The write VIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void handleWriteError(VDOCompletion *completion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryBlock *block = completion->parent;
|
|
Packit Service |
b3514a |
enterReadOnlyMode(block->zone->summary->readOnlyNotifier,
|
|
Packit Service |
b3514a |
completion->result);
|
|
Packit Service |
b3514a |
finishUpdatingSlabSummaryBlock(block);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Write a slab summary block unless it is currently out for writing.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] block The block that needs to be committed
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void launchWrite(SlabSummaryBlock *block)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (block->writing) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
SlabSummaryZone *zone = block->zone;
|
|
Packit Service |
b3514a |
zone->writeCount++;
|
|
Packit Service |
b3514a |
transferAllWaiters(&block->nextUpdateWaiters, &block->currentUpdateWaiters);
|
|
Packit Service |
b3514a |
block->writing = true;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
SlabSummary *summary = zone->summary;
|
|
Packit Service |
b3514a |
if (isReadOnly(summary->readOnlyNotifier)) {
|
|
Packit Service |
b3514a |
finishUpdatingSlabSummaryBlock(block);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
memcpy(block->outgoingEntries, block->entries,
|
|
Packit Service |
b3514a |
sizeof(SlabSummaryEntry) * summary->entriesPerBlock);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Flush before writing to ensure that the slab journal tail blocks and
|
|
Packit Service |
b3514a |
// reference updates covered by this summary update are stable (VDO-2332).
|
|
Packit Service |
b3514a |
PhysicalBlockNumber pbn = (summary->origin
|
|
Packit Service |
b3514a |
+ (summary->blocksPerZone * zone->zoneNumber)
|
|
Packit Service |
b3514a |
+ block->index);
|
|
Packit Service |
b3514a |
launchWriteMetadataVIOWithFlush(block->vio, pbn, finishUpdate,
|
|
Packit Service |
b3514a |
handleWriteError, true, false);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initiate a drain.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements AdminInitiator.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void initiateDrain(AdminState *state)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
checkForDrainComplete(container_of(state, SlabSummaryZone, state));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void drainSlabSummaryZone(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
AdminStateCode operation,
|
|
Packit Service |
b3514a |
VDOCompletion *parent)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
startDraining(&summaryZone->state, operation, parent, initiateDrain);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void resumeSlabSummaryZone(SlabSummaryZone *summaryZone, VDOCompletion *parent)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
finishCompletion(parent, resumeIfQuiescent(&summaryZone->state));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// READ/UPDATE FUNCTIONS
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Get the summary block, and offset into it, for storing the summary for a
|
|
Packit Service |
b3514a |
* slab.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param summaryZone The SlabSummaryZone being queried
|
|
Packit Service |
b3514a |
* @param slabNumber The slab whose summary location is sought
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return A pointer to the SlabSummaryEntryBlock containing this
|
|
Packit Service |
b3514a |
* SlabSummaryEntry
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static SlabSummaryBlock *getSummaryBlockForSlab(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabCount entriesPerBlock = summaryZone->summary->entriesPerBlock;
|
|
Packit Service |
b3514a |
return &summaryZone->summaryBlocks[slabNumber / entriesPerBlock];
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void updateSlabSummaryEntry(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
Waiter *waiter,
|
|
Packit Service |
b3514a |
SlabCount slabNumber,
|
|
Packit Service |
b3514a |
TailBlockOffset tailBlockOffset,
|
|
Packit Service |
b3514a |
bool loadRefCounts,
|
|
Packit Service |
b3514a |
bool isClean,
|
|
Packit Service |
b3514a |
BlockCount freeBlocks)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryBlock *block = getSummaryBlockForSlab(summaryZone, slabNumber);
|
|
Packit Service |
b3514a |
int result;
|
|
Packit Service |
b3514a |
if (isReadOnly(summaryZone->summary->readOnlyNotifier)) {
|
|
Packit Service |
b3514a |
result = VDO_READ_ONLY;
|
|
Packit Service |
b3514a |
} else if (isDraining(&summaryZone->state)
|
|
Packit Service |
b3514a |
|| isQuiescent(&summaryZone->state)) {
|
|
Packit Service |
b3514a |
result = VDO_INVALID_ADMIN_STATE;
|
|
Packit Service |
b3514a |
} else {
|
|
Packit Service |
b3514a |
uint8_t hint = computeFullnessHint(summaryZone->summary, freeBlocks);
|
|
Packit Service |
b3514a |
SlabSummaryEntry *entry = &summaryZone->entries[slabNumber];
|
|
Packit Service |
b3514a |
*entry = (SlabSummaryEntry) {
|
|
Packit Service |
b3514a |
.tailBlockOffset = tailBlockOffset,
|
|
Packit Service |
b3514a |
.loadRefCounts = (entry->loadRefCounts || loadRefCounts),
|
|
Packit Service |
b3514a |
.isDirty = !isClean,
|
|
Packit Service |
b3514a |
.fullnessHint = hint,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
result = enqueueWaiter(&block->nextUpdateWaiters, waiter);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
waiter->callback(waiter, &result);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
launchWrite(block);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
TailBlockOffset getSummarizedTailBlockOffset(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return summaryZone->entries[slabNumber].tailBlockOffset;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
bool mustLoadRefCounts(SlabSummaryZone *summaryZone, SlabCount slabNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return summaryZone->entries[slabNumber].loadRefCounts;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
bool getSummarizedCleanliness(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return !summaryZone->entries[slabNumber].isDirty;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
BlockCount getSummarizedFreeBlockCount(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryEntry *entry = &summaryZone->entries[slabNumber];
|
|
Packit Service |
b3514a |
return getApproximateFreeBlocks(summaryZone->summary, entry->fullnessHint);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void getSummarizedRefCountsState(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabNumber,
|
|
Packit Service |
b3514a |
size_t *freeBlockHint,
|
|
Packit Service |
b3514a |
bool *isClean)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryEntry *entry = &summaryZone->entries[slabNumber];
|
|
Packit Service |
b3514a |
*freeBlockHint = entry->fullnessHint;
|
|
Packit Service |
b3514a |
*isClean = !entry->isDirty;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void getSummarizedSlabStatuses(SlabSummaryZone *summaryZone,
|
|
Packit Service |
b3514a |
SlabCount slabCount,
|
|
Packit Service |
b3514a |
SlabStatus *statuses)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
for (SlabCount i = 0; i < slabCount; i++) {
|
|
Packit Service |
b3514a |
statuses[i] = (SlabStatus) {
|
|
Packit Service |
b3514a |
.slabNumber = i,
|
|
Packit Service |
b3514a |
.isClean = !summaryZone->entries[i].isDirty,
|
|
Packit Service |
b3514a |
.emptiness = summaryZone->entries[i].fullnessHint
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// RESIZE FUNCTIONS
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void setSlabSummaryOrigin(SlabSummary *summary, Partition *partition)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
summary->origin = getFixedLayoutPartitionOffset(partition);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// COMBINING FUNCTIONS (LOAD)
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Clean up after saving out the combined slab summary. This callback is
|
|
Packit Service |
b3514a |
* registered in finishLoadingSummary() and loadSlabSummary().
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param completion The extent which was used to write the summary data
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void finishCombiningZones(VDOCompletion *completion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummary *summary = completion->parent;
|
|
Packit Service |
b3514a |
int result = completion->result;
|
|
Packit Service |
b3514a |
VDOExtent *extent = asVDOExtent(completion);
|
|
Packit Service |
b3514a |
freeExtent(&extent);
|
|
Packit Service |
b3514a |
finishLoadingWithResult(&summary->zones[0]->state, result);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void combineZones(SlabSummary *summary)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
// Combine all the old summary data into the portion of the buffer
|
|
Packit Service |
b3514a |
// corresponding to the first zone.
|
|
Packit Service |
b3514a |
ZoneCount zone = 0;
|
|
Packit Service |
b3514a |
if (summary->zonesToCombine > 1) {
|
|
Packit Service |
b3514a |
for (SlabCount entryNumber = 0; entryNumber < MAX_SLABS; entryNumber++) {
|
|
Packit Service |
b3514a |
if (zone != 0) {
|
|
Packit Service |
b3514a |
memcpy(summary->entries + entryNumber,
|
|
Packit Service |
b3514a |
summary->entries + (zone * MAX_SLABS) + entryNumber,
|
|
Packit Service |
b3514a |
sizeof(SlabSummaryEntry));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
zone++;
|
|
Packit Service |
b3514a |
if (zone == summary->zonesToCombine) {
|
|
Packit Service |
b3514a |
zone = 0;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Copy the combined data to each zones's region of the buffer.
|
|
Packit Service |
b3514a |
for (zone = 1; zone < MAX_PHYSICAL_ZONES; zone++) {
|
|
Packit Service |
b3514a |
memcpy(summary->entries + (zone * MAX_SLABS), summary->entries,
|
|
Packit Service |
b3514a |
MAX_SLABS * sizeof(SlabSummaryEntry));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Combine the slab summary data from all the previously written zones
|
|
Packit Service |
b3514a |
* and copy the combined summary to each partition's data region. Then write
|
|
Packit Service |
b3514a |
* the combined summary back out to disk. This callback is registered in
|
|
Packit Service |
b3514a |
* loadSlabSummary().
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param completion The extent which was used to read the summary data
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void finishLoadingSummary(VDOCompletion *completion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummary *summary = completion->parent;
|
|
Packit Service |
b3514a |
VDOExtent *extent = asVDOExtent(completion);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Combine the zones so each zone is correct for all slabs.
|
|
Packit Service |
b3514a |
combineZones(summary);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Write the combined summary back out.
|
|
Packit Service |
b3514a |
extent->completion.callback = finishCombiningZones;
|
|
Packit Service |
b3514a |
writeMetadataExtent(extent, summary->origin);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void loadSlabSummary(SlabSummary *summary,
|
|
Packit Service |
b3514a |
AdminStateCode operation,
|
|
Packit Service |
b3514a |
ZoneCount zonesToCombine,
|
|
Packit Service |
b3514a |
VDOCompletion *parent)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SlabSummaryZone *zone = summary->zones[0];
|
|
Packit Service |
b3514a |
if (!startLoading(&zone->state, operation, parent, NULL)) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
VDOExtent *extent;
|
|
Packit Service |
b3514a |
BlockCount blocks = summary->blocksPerZone * MAX_PHYSICAL_ZONES;
|
|
Packit Service |
b3514a |
int result = createExtent(parent->layer, VIO_TYPE_SLAB_SUMMARY,
|
|
Packit Service |
b3514a |
VIO_PRIORITY_METADATA, blocks,
|
|
Packit Service |
b3514a |
(char *) summary->entries, &extent);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
finishLoadingWithResult(&zone->state, result);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if ((operation == ADMIN_STATE_FORMATTING)
|
|
Packit Service |
b3514a |
|| (operation == ADMIN_STATE_LOADING_FOR_REBUILD)) {
|
|
Packit Service |
b3514a |
prepareCompletion(&extent->completion, finishCombiningZones,
|
|
Packit Service |
b3514a |
finishCombiningZones, 0, summary);
|
|
Packit Service |
b3514a |
writeMetadataExtent(extent, summary->origin);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
summary->zonesToCombine = zonesToCombine;
|
|
Packit Service |
b3514a |
prepareCompletion(&extent->completion, finishLoadingSummary,
|
|
Packit Service |
b3514a |
finishCombiningZones, 0, summary);
|
|
Packit Service |
b3514a |
readMetadataExtent(extent, summary->origin);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
SlabSummaryStatistics getSlabSummaryStatistics(const SlabSummary *summary)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
const AtomicSlabSummaryStatistics *atoms = &summary->statistics;
|
|
Packit Service |
b3514a |
return (SlabSummaryStatistics) {
|
|
Packit Service |
b3514a |
.blocksWritten = atomicLoad64(&atoms->blocksWritten),
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
}
|