mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-08 06:44:35 +08:00
9cc97529a1
This is preparation patch to add multi stream support to zcomp. Introduce struct zcomp_strm_single and a set of functions to manage zcomp_strm stream access. zcomp_strm_single implements single compession stream, same way as current zcomp implementation. This moves zcomp_strm stream control and locking from zcomp, so compressing backend zcomp is not aware of required locking. Single and multi streams require different locking schemes. Minchan Kim reported that spinlock-based locking scheme (which is used in multi stream implementation) has demonstrated a severe perfomance regression for single compression stream case, comparing to mutex-based. see https://lkml.org/lkml/2014/2/18/16 The following set of functions added: - zcomp_strm_single_find()/zcomp_strm_single_release() find and release a compression stream, implement required locking - zcomp_strm_single_create()/zcomp_strm_single_destroy() create and destroy zcomp_strm_single New ->strm_find() and ->strm_release() callbacks added to zcomp, which are set to zcomp_strm_single_find() and zcomp_strm_single_release() during initialisation. Instead of direct locking and zcomp_strm access from zcomp_strm_find() and zcomp_strm_release(), zcomp now calls ->strm_find() and ->strm_release() correspondingly. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
/*
|
|
* Copyright (C) 2014 Sergey Senozhatsky.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
#ifndef _ZCOMP_H_
|
|
#define _ZCOMP_H_
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
struct zcomp_strm {
|
|
/* compression/decompression buffer */
|
|
void *buffer;
|
|
/*
|
|
* The private data of the compression stream, only compression
|
|
* stream backend can touch this (e.g. compression algorithm
|
|
* working memory)
|
|
*/
|
|
void *private;
|
|
};
|
|
|
|
/* static compression backend */
|
|
struct zcomp_backend {
|
|
int (*compress)(const unsigned char *src, unsigned char *dst,
|
|
size_t *dst_len, void *private);
|
|
|
|
int (*decompress)(const unsigned char *src, size_t src_len,
|
|
unsigned char *dst);
|
|
|
|
void *(*create)(void);
|
|
void (*destroy)(void *private);
|
|
|
|
const char *name;
|
|
};
|
|
|
|
/* dynamic per-device compression frontend */
|
|
struct zcomp {
|
|
void *stream;
|
|
struct zcomp_backend *backend;
|
|
|
|
struct zcomp_strm *(*strm_find)(struct zcomp *comp);
|
|
void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm);
|
|
void (*destroy)(struct zcomp *comp);
|
|
};
|
|
|
|
struct zcomp *zcomp_create(const char *comp);
|
|
void zcomp_destroy(struct zcomp *comp);
|
|
|
|
struct zcomp_strm *zcomp_strm_find(struct zcomp *comp);
|
|
void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm);
|
|
|
|
int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
|
|
const unsigned char *src, size_t *dst_len);
|
|
|
|
int zcomp_decompress(struct zcomp *comp, const unsigned char *src,
|
|
size_t src_len, unsigned char *dst);
|
|
#endif /* _ZCOMP_H_ */
|