drivers/block/zram/backend_lz4hc.c
Source file repositories/reference/linux-study-clean/drivers/block/zram/backend_lz4hc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/zram/backend_lz4hc.c- Extension
.c- Size
- 2697 bytes
- Lines
- 129
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/lz4.hlinux/slab.hlinux/vmalloc.hbackend_lz4hc.h
Detected Declarations
struct lz4hc_ctxfunction lz4hc_release_paramsfunction lz4hc_destroyfunction lz4hc_createfunction lz4hc_compressfunction lz4hc_decompress
Annotated Snippet
struct lz4hc_ctx {
void *mem;
LZ4_streamDecode_t *dstrm;
LZ4_streamHC_t *cstrm;
};
static void lz4hc_release_params(struct zcomp_params *params)
{
}
static int lz4hc_setup_params(struct zcomp_params *params)
{
if (params->level == ZCOMP_PARAM_NOT_SET)
params->level = LZ4HC_DEFAULT_CLEVEL;
return 0;
}
static void lz4hc_destroy(struct zcomp_ctx *ctx)
{
struct lz4hc_ctx *zctx = ctx->context;
if (!zctx)
return;
kfree(zctx->dstrm);
kfree(zctx->cstrm);
vfree(zctx->mem);
kfree(zctx);
}
static int lz4hc_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
{
struct lz4hc_ctx *zctx;
zctx = kzalloc_obj(*zctx);
if (!zctx)
return -ENOMEM;
ctx->context = zctx;
if (params->dict_sz == 0) {
zctx->mem = vmalloc(LZ4HC_MEM_COMPRESS);
if (!zctx->mem)
goto error;
} else {
zctx->dstrm = kzalloc_obj(*zctx->dstrm);
if (!zctx->dstrm)
goto error;
zctx->cstrm = kzalloc_obj(*zctx->cstrm);
if (!zctx->cstrm)
goto error;
}
return 0;
error:
lz4hc_destroy(ctx);
return -EINVAL;
}
static int lz4hc_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req)
{
struct lz4hc_ctx *zctx = ctx->context;
int ret;
if (!zctx->cstrm) {
ret = LZ4_compress_HC(req->src, req->dst, req->src_len,
req->dst_len, params->level,
zctx->mem);
} else {
/* Cstrm needs to be reset */
LZ4_resetStreamHC(zctx->cstrm, params->level);
ret = LZ4_loadDictHC(zctx->cstrm, params->dict,
params->dict_sz);
if (ret != params->dict_sz)
return -EINVAL;
ret = LZ4_compress_HC_continue(zctx->cstrm, req->src, req->dst,
req->src_len, req->dst_len);
}
if (!ret)
return -EINVAL;
req->dst_len = ret;
return 0;
}
static int lz4hc_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/lz4.h`, `linux/slab.h`, `linux/vmalloc.h`, `backend_lz4hc.h`.
- Detected declarations: `struct lz4hc_ctx`, `function lz4hc_release_params`, `function lz4hc_destroy`, `function lz4hc_create`, `function lz4hc_compress`, `function lz4hc_decompress`.
- Atlas domain: Driver Families / drivers/block.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.