drivers/block/zram/backend_zstd.c
Source file repositories/reference/linux-study-clean/drivers/block/zram/backend_zstd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/zram/backend_zstd.c- Extension
.c- Size
- 4692 bytes
- Lines
- 218
- 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/zstd.hbackend_zstd.h
Detected Declarations
struct zstd_ctxstruct zstd_paramsfunction zstd_custom_freefunction zstd_release_paramsfunction zstd_setup_paramsfunction zstd_destroyfunction zstd_createfunction zstd_compressfunction zstd_decompress
Annotated Snippet
struct zstd_ctx {
zstd_cctx *cctx;
zstd_dctx *dctx;
void *cctx_mem;
void *dctx_mem;
};
struct zstd_params {
zstd_custom_mem custom_mem;
zstd_cdict *cdict;
zstd_ddict *ddict;
zstd_parameters cprm;
};
/*
* For C/D dictionaries we need to provide zstd with zstd_custom_mem,
* which zstd uses internally to allocate/free memory when needed.
*/
static void *zstd_custom_alloc(void *opaque, size_t size)
{
return kvzalloc(size, GFP_NOIO | __GFP_NOWARN);
}
static void zstd_custom_free(void *opaque, void *address)
{
kvfree(address);
}
static void zstd_release_params(struct zcomp_params *params)
{
struct zstd_params *zp = params->drv_data;
params->drv_data = NULL;
if (!zp)
return;
zstd_free_cdict(zp->cdict);
zstd_free_ddict(zp->ddict);
kfree(zp);
}
static int zstd_setup_params(struct zcomp_params *params)
{
zstd_compression_parameters prm;
struct zstd_params *zp;
zp = kzalloc_obj(*zp);
if (!zp)
return -ENOMEM;
params->drv_data = zp;
if (params->level == ZCOMP_PARAM_NOT_SET)
params->level = zstd_default_clevel();
zp->cprm = zstd_get_params(params->level, PAGE_SIZE);
zp->custom_mem.customAlloc = zstd_custom_alloc;
zp->custom_mem.customFree = zstd_custom_free;
prm = zstd_get_cparams(params->level, PAGE_SIZE,
params->dict_sz);
zp->cdict = zstd_create_cdict_byreference(params->dict,
params->dict_sz,
prm,
zp->custom_mem);
if (!zp->cdict)
goto error;
zp->ddict = zstd_create_ddict_byreference(params->dict,
params->dict_sz,
zp->custom_mem);
if (!zp->ddict)
goto error;
return 0;
error:
zstd_release_params(params);
return -EINVAL;
}
static void zstd_destroy(struct zcomp_ctx *ctx)
{
struct zstd_ctx *zctx = ctx->context;
if (!zctx)
return;
/*
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/zstd.h`, `backend_zstd.h`.
- Detected declarations: `struct zstd_ctx`, `struct zstd_params`, `function zstd_custom_free`, `function zstd_release_params`, `function zstd_setup_params`, `function zstd_destroy`, `function zstd_create`, `function zstd_compress`, `function zstd_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.