drivers/block/zram/backend_lz4.c
Source file repositories/reference/linux-study-clean/drivers/block/zram/backend_lz4.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/zram/backend_lz4.c- Extension
.c- Size
- 3038 bytes
- Lines
- 151
- 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_lz4.h
Detected Declarations
struct lz4_ctxfunction lz4_release_paramsfunction lz4_setup_paramsfunction lz4_destroyfunction lz4_createfunction lz4_compressfunction lz4_decompress
Annotated Snippet
struct lz4_ctx {
void *mem;
LZ4_streamDecode_t *dstrm;
LZ4_stream_t *cstrm;
};
static void lz4_release_params(struct zcomp_params *params)
{
LZ4_stream_t *dict_stream = params->drv_data;
params->drv_data = NULL;
if (!dict_stream)
return;
kfree(dict_stream);
}
static int lz4_setup_params(struct zcomp_params *params)
{
LZ4_stream_t *dict_stream;
int ret;
if (params->level == ZCOMP_PARAM_NOT_SET)
params->level = LZ4_ACCELERATION_DEFAULT;
if (!params->dict || !params->dict_sz)
return 0;
dict_stream = kzalloc_obj(*dict_stream, GFP_KERNEL);
if (!dict_stream)
return -ENOMEM;
ret = LZ4_loadDict(dict_stream,
params->dict, params->dict_sz);
if (ret != params->dict_sz) {
kfree(dict_stream);
return -EINVAL;
}
params->drv_data = dict_stream;
return 0;
}
static void lz4_destroy(struct zcomp_ctx *ctx)
{
struct lz4_ctx *zctx = ctx->context;
if (!zctx)
return;
vfree(zctx->mem);
kfree(zctx->dstrm);
kfree(zctx->cstrm);
kfree(zctx);
}
static int lz4_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
{
struct lz4_ctx *zctx;
zctx = kzalloc_obj(*zctx);
if (!zctx)
return -ENOMEM;
ctx->context = zctx;
if (params->dict_sz == 0) {
zctx->mem = vmalloc(LZ4_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:
lz4_destroy(ctx);
return -ENOMEM;
}
static int lz4_compress(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_lz4.h`.
- Detected declarations: `struct lz4_ctx`, `function lz4_release_params`, `function lz4_setup_params`, `function lz4_destroy`, `function lz4_create`, `function lz4_compress`, `function lz4_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.