File diskdump-Directly-map-buffers-from-flattened-file-ca.patch of Package libkdumpfile.36085
From: Petr Tesarik <petr@tesarici.cz>
Date: Mon, 6 Nov 2023 21:08:50 +0100
Subject: diskdump: Directly map buffers from flattened file cache if possible
References: bsc#1223399
Upstream: merged
Git-commit: d15d53bcfc5ce0bf34d30425219abe1427da8d2c
Check if a flattened segment completely covers a requested chunk and if
yes, map the underlying file cache buffer instead of copying it to a
dynamically allocated temporary buffer.
Since makedumpfile writes a flattened segment only after adding a complete
compressed page to its output buffer, this is the normal case. This change
saves a lot of allocating, copying and freeing.
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
src/kdumpfile/diskdump.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
--- a/src/kdumpfile/diskdump.c
+++ b/src/kdumpfile/diskdump.c
@@ -291,14 +291,25 @@ diskdump_pread(kdump_ctx_t *ctx, void *b
* @param pos File position.
* @returns Error status.
*
- * Get a contiguous data chunk from a flattened dump file. Currently, this is
- * implemented using a dynamically allocated buffer, even if the underlying
- * file cache buffer might be used.
+ * Get a contiguous data chunk from a flattened dump file.
*/
static inline kdump_status
flattened_get_chunk(kdump_ctx_t *ctx, struct fcache_chunk *fch,
size_t len, off_t pos)
{
+ struct disk_dump_priv *ddp = ctx->shared->fmtdata;
+ const addrxlat_range_t *range, *end;
+ off_t off;
+
+ range = addrxlat_map_ranges(ddp->flatmap);
+ end = range + addrxlat_map_len(ddp->flatmap);
+ for (off = pos; range < end && off > range->endoff; ++range)
+ off -= range->endoff + 1;
+ if (len <= range->endoff + 1 - off) {
+ pos += ddp->flatoffs[range->meth];
+ return fcache_get_chunk(ctx->shared->fcache, fch, len, pos);
+ }
+
fch->data = malloc(len);
if (!fch->data)
return KDUMP_ERR_SYSTEM;