drivers/block/zram/backend_deflate.c
Source file repositories/reference/linux-study-clean/drivers/block/zram/backend_deflate.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/zram/backend_deflate.c- Extension
.c- Size
- 3246 bytes
- Lines
- 149
- 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/slab.hlinux/vmalloc.hlinux/zlib.hbackend_deflate.h
Detected Declarations
struct deflate_ctxfunction deflate_release_paramsfunction deflate_destroyfunction deflate_createfunction deflate_compressfunction deflate_decompress
Annotated Snippet
struct deflate_ctx {
struct z_stream_s cctx;
struct z_stream_s dctx;
};
static void deflate_release_params(struct zcomp_params *params)
{
}
static int deflate_setup_params(struct zcomp_params *params)
{
if (params->level == ZCOMP_PARAM_NOT_SET)
params->level = Z_DEFAULT_COMPRESSION;
if (params->deflate.winbits == ZCOMP_PARAM_NOT_SET)
params->deflate.winbits = DEFLATE_DEF_WINBITS;
return 0;
}
static void deflate_destroy(struct zcomp_ctx *ctx)
{
struct deflate_ctx *zctx = ctx->context;
if (!zctx)
return;
if (zctx->cctx.workspace) {
zlib_deflateEnd(&zctx->cctx);
vfree(zctx->cctx.workspace);
}
if (zctx->dctx.workspace) {
zlib_inflateEnd(&zctx->dctx);
vfree(zctx->dctx.workspace);
}
kfree(zctx);
}
static int deflate_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
{
struct deflate_ctx *zctx;
size_t sz;
int ret;
zctx = kzalloc_obj(*zctx);
if (!zctx)
return -ENOMEM;
ctx->context = zctx;
sz = zlib_deflate_workspacesize(params->deflate.winbits, MAX_MEM_LEVEL);
zctx->cctx.workspace = vzalloc(sz);
if (!zctx->cctx.workspace)
goto error;
ret = zlib_deflateInit2(&zctx->cctx, params->level, Z_DEFLATED,
params->deflate.winbits, DEFLATE_DEF_MEMLEVEL,
Z_DEFAULT_STRATEGY);
if (ret != Z_OK)
goto error;
sz = zlib_inflate_workspacesize();
zctx->dctx.workspace = vzalloc(sz);
if (!zctx->dctx.workspace)
goto error;
ret = zlib_inflateInit2(&zctx->dctx, params->deflate.winbits);
if (ret != Z_OK)
goto error;
return 0;
error:
deflate_destroy(ctx);
return -EINVAL;
}
static int deflate_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req)
{
struct deflate_ctx *zctx = ctx->context;
struct z_stream_s *deflate;
int ret;
deflate = &zctx->cctx;
ret = zlib_deflateReset(deflate);
if (ret != Z_OK)
return -EINVAL;
deflate->next_in = (u8 *)req->src;
deflate->avail_in = req->src_len;
deflate->next_out = (u8 *)req->dst;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/zlib.h`, `backend_deflate.h`.
- Detected declarations: `struct deflate_ctx`, `function deflate_release_params`, `function deflate_destroy`, `function deflate_create`, `function deflate_compress`, `function deflate_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.