Skip to content

Commit 270700d

Browse files
Barry Songakpm00
Barry Song
authored andcommitted
mm/zswap: remove the memcpy if acomp is not sleepable
Most compressors are actually CPU-based and won't sleep during compression and decompression. We should remove the redundant memcpy for them. This patch checks if the algorithm is sleepable by testing the CRYPTO_ALG_ASYNC algorithm flag. Generally speaking, async and sleepable are semantically similar but not equal. But for compress drivers, they are basically equal at least due to the below facts. Firstly, scompress drivers - crypto/deflate.c, lz4.c, zstd.c, lzo.c etc have no sleep. Secondly, zRAM has been using these scompress drivers for years in atomic contexts, and never worried those drivers going to sleep. One exception is that an async driver can sometimes still return synchronously per Herbert's clarification. In this case, we are still having a redundant memcpy. But we can't know if one particular acomp request will sleep or not unless crypto can expose more details for each specific request from offload drivers. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Barry Song <[email protected]> Tested-by: Chengming Zhou <[email protected]> Reviewed-by: Nhat Pham <[email protected]> Acked-by: Yosry Ahmed <[email protected]> Reviewed-by: Chengming Zhou <[email protected]> Acked-by: Chris Li <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Dan Streetman <[email protected]> Cc: David S. Miller <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Seth Jennings <[email protected]> Cc: Vitaly Wool <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6c303f1 commit 270700d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mm/zswap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct crypto_acomp_ctx {
162162
struct crypto_wait wait;
163163
u8 *buffer;
164164
struct mutex mutex;
165+
bool is_sleepable;
165166
};
166167

167168
/*
@@ -951,6 +952,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
951952
goto acomp_fail;
952953
}
953954
acomp_ctx->acomp = acomp;
955+
acomp_ctx->is_sleepable = acomp_is_async(acomp);
954956

955957
req = acomp_request_alloc(acomp_ctx->acomp);
956958
if (!req) {
@@ -1078,7 +1080,7 @@ static void zswap_decompress(struct zswap_entry *entry, struct page *page)
10781080
mutex_lock(&acomp_ctx->mutex);
10791081

10801082
src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO);
1081-
if (!zpool_can_sleep_mapped(zpool)) {
1083+
if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) {
10821084
memcpy(acomp_ctx->buffer, src, entry->length);
10831085
src = acomp_ctx->buffer;
10841086
zpool_unmap_handle(zpool, entry->handle);
@@ -1092,7 +1094,7 @@ static void zswap_decompress(struct zswap_entry *entry, struct page *page)
10921094
BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE);
10931095
mutex_unlock(&acomp_ctx->mutex);
10941096

1095-
if (zpool_can_sleep_mapped(zpool))
1097+
if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool))
10961098
zpool_unmap_handle(zpool, entry->handle);
10971099
}
10981100

0 commit comments

Comments
 (0)