Stop wasting time on malloc in snprintf_zstd_header

Profiling zdb -vvvvv on datasets with a lot of zstd blocks, we find
ourselves spending quite a lot of time on malloc/free, because we
allocate a 16M abd each call, and never free it, so we're leaking
16M per call as well.

This seems sub-optimal. So let's just keep the buffer around and
reuse it.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes #15721
This commit is contained in:
Rich Ercolani 2024-01-12 15:17:26 -05:00 committed by Brian Behlendorf
parent 3425484eb9
commit 4d4972ed98
1 changed files with 3 additions and 2 deletions

View File

@ -2360,7 +2360,7 @@ static void
snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen, snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen,
const blkptr_t *bp) const blkptr_t *bp)
{ {
abd_t *pabd; static abd_t *pabd = NULL;
void *buf; void *buf;
zio_t *zio; zio_t *zio;
zfs_zstdhdr_t zstd_hdr; zfs_zstdhdr_t zstd_hdr;
@ -2391,7 +2391,8 @@ snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen,
return; return;
} }
pabd = abd_alloc_for_io(SPA_MAXBLOCKSIZE, B_FALSE); if (!pabd)
pabd = abd_alloc_for_io(SPA_MAXBLOCKSIZE, B_FALSE);
zio = zio_root(spa, NULL, NULL, 0); zio = zio_root(spa, NULL, NULL, 0);
/* Decrypt but don't decompress so we can read the compression header */ /* Decrypt but don't decompress so we can read the compression header */