per Intel policy to include file commit date using git cmd below. The policy does not apply to non-Intel (C) notices. git log --follow -C90% --format=%ad --date default <file> | tail -1 and then pull just the 4 digit year from the result. Intel copyrights were not added to files where Intel either had no contribution ot the contribution lacked substance (ie license header updates, formatting changes, etc). Contribution date used "--follow -C95%" to get the most accurate date. Note that several files in this patch didn't end the license/(c) block with a blank comment line so these were added as the vast majority of files do have this last blank line. Simply there for consistency. Signed-off-by: paul luse <paul.e.luse@intel.com> Change-Id: Id5b7ce4f658fe87132f14139ead58d6e285c04d4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15192 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Community-CI: Mellanox Build Bot
224 lines
5.4 KiB
C
224 lines
5.4 KiB
C
/* SPDX-License-Identifier: BSD-3-Clause
|
|
* Copyright (C) 2018 Intel Corporation.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include "spdk/ftl.h"
|
|
#include "ftl_debug.h"
|
|
#include "ftl_band.h"
|
|
|
|
/* TODO: Switch to INFOLOG instead, we can control the printing via spdk_log_get_flag */
|
|
#if defined(DEBUG)
|
|
|
|
static const char *ftl_band_state_str[] = {
|
|
"free",
|
|
"prep",
|
|
"opening",
|
|
"open",
|
|
"full",
|
|
"closing",
|
|
"closed",
|
|
"max"
|
|
};
|
|
|
|
struct ftl_band_validate_ctx {
|
|
struct ftl_band *band;
|
|
ftl_band_validate_md_cb cb;
|
|
int remaining;
|
|
uint64_t pin_cnt;
|
|
uint64_t current_offset;
|
|
struct ftl_l2p_pin_ctx l2p_pin_ctx[];
|
|
};
|
|
|
|
static void ftl_band_validate_md_l2p_pin_cb(struct spdk_ftl_dev *dev, int status,
|
|
struct ftl_l2p_pin_ctx *pin_ctx);
|
|
|
|
#define FTL_MD_VALIDATE_LBA_PER_ITERATION 128
|
|
|
|
static void
|
|
ftl_band_validate_md_pin(struct ftl_band_validate_ctx *ctx)
|
|
{
|
|
struct ftl_band *band = ctx->band;
|
|
struct spdk_ftl_dev *dev = band->dev;
|
|
struct ftl_p2l_map *p2l_map = &band->p2l_map;
|
|
size_t i, size;
|
|
struct ftl_l2p_pin_ctx tmp_pin_ctx = {
|
|
.cb_ctx = ctx
|
|
};
|
|
|
|
/* Since the first L2P page may already be pinned, the ftl_band_validate_md_l2p_pin_cb could be prematurely
|
|
* triggered. Initializing to 1 and then triggering the callback again manually prevents the issue.
|
|
*/
|
|
ctx->remaining = 1;
|
|
size = spdk_min(FTL_MD_VALIDATE_LBA_PER_ITERATION,
|
|
ftl_get_num_blocks_in_band(dev) - ctx->current_offset);
|
|
|
|
for (i = ctx->current_offset; i < ctx->current_offset + size; ++i) {
|
|
if (!ftl_bitmap_get(p2l_map->valid, i)) {
|
|
ctx->l2p_pin_ctx[i].lba = FTL_LBA_INVALID;
|
|
continue;
|
|
}
|
|
|
|
assert(p2l_map->band_map[i].lba != FTL_LBA_INVALID);
|
|
ctx->remaining++;
|
|
ctx->pin_cnt++;
|
|
ftl_l2p_pin(dev, p2l_map->band_map[i].lba, 1, ftl_band_validate_md_l2p_pin_cb, ctx,
|
|
&ctx->l2p_pin_ctx[i]);
|
|
}
|
|
|
|
ftl_band_validate_md_l2p_pin_cb(dev, 0, &tmp_pin_ctx);
|
|
}
|
|
|
|
static void
|
|
_ftl_band_validate_md(void *_ctx)
|
|
{
|
|
struct ftl_band_validate_ctx *ctx = _ctx;
|
|
struct ftl_band *band = ctx->band;
|
|
struct spdk_ftl_dev *dev = band->dev;
|
|
ftl_addr addr_l2p;
|
|
size_t i, size;
|
|
bool valid = true;
|
|
uint64_t lba;
|
|
|
|
size = spdk_min(FTL_MD_VALIDATE_LBA_PER_ITERATION,
|
|
ftl_get_num_blocks_in_band(dev) - ctx->current_offset);
|
|
|
|
for (i = ctx->current_offset; i < ctx->current_offset + size; ++i) {
|
|
lba = ctx->l2p_pin_ctx[i].lba;
|
|
if (lba == FTL_LBA_INVALID) {
|
|
continue;
|
|
}
|
|
|
|
if (ftl_bitmap_get(band->p2l_map.valid, i)) {
|
|
addr_l2p = ftl_l2p_get(dev, lba);
|
|
|
|
if (addr_l2p != FTL_ADDR_INVALID && !ftl_addr_in_nvc(dev, addr_l2p) &&
|
|
addr_l2p != ftl_band_addr_from_block_offset(band, i)) {
|
|
valid = false;
|
|
}
|
|
}
|
|
|
|
ctx->pin_cnt--;
|
|
ftl_l2p_unpin(dev, lba, 1);
|
|
}
|
|
assert(ctx->pin_cnt == 0);
|
|
|
|
ctx->current_offset += size;
|
|
|
|
if (ctx->current_offset == ftl_get_num_blocks_in_band(dev)) {
|
|
ctx->cb(band, valid);
|
|
free(ctx);
|
|
return;
|
|
}
|
|
|
|
ftl_band_validate_md_pin(ctx);
|
|
}
|
|
|
|
static void
|
|
ftl_band_validate_md_l2p_pin_cb(struct spdk_ftl_dev *dev, int status,
|
|
struct ftl_l2p_pin_ctx *pin_ctx)
|
|
{
|
|
struct ftl_band_validate_ctx *ctx = pin_ctx->cb_ctx;
|
|
|
|
assert(status == 0);
|
|
|
|
if (--ctx->remaining == 0) {
|
|
spdk_thread_send_msg(dev->core_thread, _ftl_band_validate_md, ctx);
|
|
}
|
|
}
|
|
|
|
void
|
|
ftl_band_validate_md(struct ftl_band *band, ftl_band_validate_md_cb cb)
|
|
{
|
|
struct ftl_band_validate_ctx *ctx;
|
|
size_t size;
|
|
|
|
assert(cb);
|
|
|
|
size = ftl_get_num_blocks_in_band(band->dev);
|
|
|
|
ctx = malloc(sizeof(*ctx) + size * sizeof(*ctx->l2p_pin_ctx));
|
|
|
|
if (!ctx) {
|
|
FTL_ERRLOG(band->dev, "Failed to allocate memory for band validate context");
|
|
cb(band, false);
|
|
return;
|
|
}
|
|
|
|
ctx->band = band;
|
|
ctx->cb = cb;
|
|
ctx->pin_cnt = 0;
|
|
ctx->current_offset = 0;
|
|
|
|
ftl_band_validate_md_pin(ctx);
|
|
}
|
|
|
|
void
|
|
ftl_dev_dump_bands(struct spdk_ftl_dev *dev)
|
|
{
|
|
uint64_t i;
|
|
|
|
if (!dev->bands) {
|
|
return;
|
|
}
|
|
|
|
FTL_NOTICELOG(dev, "Bands validity:\n");
|
|
for (i = 0; i < ftl_get_num_bands(dev); ++i) {
|
|
FTL_NOTICELOG(dev, " Band %3zu: %8zu / %zu \twr_cnt: %"PRIu64
|
|
"\tstate: %s\n",
|
|
i + 1, dev->bands[i].p2l_map.num_valid,
|
|
ftl_band_user_blocks(&dev->bands[i]),
|
|
dev->bands[i].md->wr_cnt,
|
|
ftl_band_state_str[dev->bands[i].md->state]);
|
|
}
|
|
}
|
|
|
|
#endif /* defined(DEBUG) */
|
|
|
|
void
|
|
ftl_dev_dump_stats(const struct spdk_ftl_dev *dev)
|
|
{
|
|
uint64_t i, total = 0;
|
|
char uuid[SPDK_UUID_STRING_LEN];
|
|
double waf;
|
|
uint64_t write_user, write_total;
|
|
const char *limits[] = {
|
|
[SPDK_FTL_LIMIT_CRIT] = "crit",
|
|
[SPDK_FTL_LIMIT_HIGH] = "high",
|
|
[SPDK_FTL_LIMIT_LOW] = "low",
|
|
[SPDK_FTL_LIMIT_START] = "start"
|
|
};
|
|
|
|
(void)limits;
|
|
|
|
if (!dev->bands) {
|
|
return;
|
|
}
|
|
|
|
/* Count the number of valid LBAs */
|
|
for (i = 0; i < ftl_get_num_bands(dev); ++i) {
|
|
total += dev->bands[i].p2l_map.num_valid;
|
|
}
|
|
|
|
write_user = dev->stats.entries[FTL_STATS_TYPE_CMP].write.blocks;
|
|
write_total = write_user +
|
|
dev->stats.entries[FTL_STATS_TYPE_GC].write.blocks +
|
|
dev->stats.entries[FTL_STATS_TYPE_MD_BASE].write.blocks;
|
|
|
|
waf = (double)write_total / (double)write_user;
|
|
|
|
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &dev->conf.uuid);
|
|
FTL_NOTICELOG(dev, "\n");
|
|
FTL_NOTICELOG(dev, "device UUID: %s\n", uuid);
|
|
FTL_NOTICELOG(dev, "total valid LBAs: %zu\n", total);
|
|
FTL_NOTICELOG(dev, "total writes: %"PRIu64"\n", write_total);
|
|
FTL_NOTICELOG(dev, "user writes: %"PRIu64"\n", write_user);
|
|
FTL_NOTICELOG(dev, "WAF: %.4lf\n", waf);
|
|
#ifdef DEBUG
|
|
FTL_NOTICELOG(dev, "limits:\n");
|
|
for (i = 0; i < SPDK_FTL_LIMIT_MAX; ++i) {
|
|
FTL_NOTICELOG(dev, " %5s: %"PRIu64"\n", limits[i], dev->stats.limits[i]);
|
|
}
|
|
#endif
|
|
}
|