Message ID | 20240216040815.114202-3-21cnbao@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp288722dyb; Thu, 15 Feb 2024 20:17:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaig2sLTzuhSniazUtgJbd16s9VJmP4HBTNY5mvDXgmBKoFV3GDNcZWOmAmIIIE1jthbjCgh/6E23k5jMxV7K1+ctx1w== X-Google-Smtp-Source: AGHT+IFvpx+H0+Y6sHFL3AGZ30BZ4Fz+rMs3WVi4PZ8NZ/vXm1N3XRR06iMDnS03ta2SbpBWMlC0 X-Received: by 2002:a17:902:aa91:b0:1d9:a14c:eeb0 with SMTP id d17-20020a170902aa9100b001d9a14ceeb0mr3911050plr.43.1708057046246; Thu, 15 Feb 2024 20:17:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708057046; cv=pass; d=google.com; s=arc-20160816; b=cE1oS5YX7lxr+19ZASPTUU3529acvGJ2UQKFRPJuk719bN6wUbdkCFgUX4XLQ/3nD+ tAfrB3FUhz+YksVA/LXCjloE2bnrUl+szRj3s0iQxMNuI9bOSJ3AMFUFOfZLlVeLKekO AuCTPfnOzaaLjcOaS9n+5zZw528tvX0ERqmnSkpDYuI3eGroBkVO8iKs9ULYR6HRzAre ImggZMdPrYZTErRbuPynVa5HoFnK6rgqRIhtWl0Ubj9d1Fdmesh4/qAcBXbZR7o39+KD u/BvnJEadgCN+kj2ONFfvE4peVvScXn7/EYF9LNyplutWJfDKSPvAeinTcK4idks6B7H ZWtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; fh=0Vx+ghEkchbSQ0GvaNAgfnArLgMiCsox9SyyETyCi/o=; b=tC4m1/MEIpX87wmP85a6hKGRi8Lv85mr/AMdeuT7aQFFTy1Ju/IXTKmIogde7VvkeN wTIe0WKca5H+PU5Kk2e3nK6WntJdgbsAXjEOwSVf1RZdxo8E/v7yrTBBEzeYPVWnaY36 IPbJLdaP6ObFI5WNrrymc9RHG/DXuDC2v6+oHmEHCxbJnoF7sQBPO34Kg/daCOsUKtrm PUwbtJRDu47TxUOI7vB6O90HLRy9vvHfqBsPAnSxZ0riEjhkp5d5W2my9Lr9K9KrmH6+ Z71lTcLWdpvCrHRmD7GZmT4vzj+uct3kscJRlMcU+j7n+SLnQXlwFwdFv9YCTJYgoIbj lSZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwzcx4fV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j9-20020a170902690900b001da22d9e810si2232390plk.219.2024.02.15.20.17.26 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:17:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mwzcx4fV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 15FC22835D0 for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 04:17:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7169B179B5; Fri, 16 Feb 2024 04:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mwzcx4fV" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F85D17551; Fri, 16 Feb 2024 04:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056546; cv=none; b=YNQE+AFeAXco/pTqfDs2vY+ArbkVMRdk2Uf30dDBEFlFqFe9mvhxd0eccIVOfojnfbOo+0lMiWQHJhSm9fd654YYhZY4pN44Ln0BTPog9QblYb+BeTrlS5G6g0xnTuShU1tHxUZOtqqfi1ruCvBfGTt7bBPTEs2ods2PLsEcGm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708056546; c=relaxed/simple; bh=PIYvWr5DMLF8+jxHRgFqYx/2Q2KnJ/Jtsvfz7TqNIu4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t76syD5n0bnF3t8lTBwFtg4PelYeKwdWGzndjXEO8A22HvApEvPaw59dtVso5JiJ769qltZiqUiN3w9h9/s5fXsYWrpcmXW1GEqhg+/4h0hhit/Zi8rpBgFcUSWo5mcLtdVoXfWsHQbf0lU90IDT6rqgsjmrAmlHipS0Ebn1VwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mwzcx4fV; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso302340a12.3; Thu, 15 Feb 2024 20:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056545; x=1708661345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=mwzcx4fVqYo6YP3/p+OJBp2EqeOemf24U/B/c3aryo1z0Z5GJEgzEeYzgw/KQtMK5O 7zWALR0cg6mUqmYl7AWMQwd5PgYJM5jagyHmygWN+p1mYcWGs2lUDGIRJzZ8IlPJwe7d YHLPKyndSx5GKGRv0NABZYsk7vLqjvdH2FyPzaR1o9m4gZ+GA5dsTHm24hsXABCrSVNc JJi0MpXAGVnrYCZzbshAn6z/qJG9xp7ZkGmTd/Y8jkCB7PnS3PVzoEE/OAe1SkaeSWZA Y6XnPmGpaUWTZnNpKet9eFzHIWmrIFsZgbfeo5n4AkITX9sKJJme59v+0+O41t+pzqGn T2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056545; x=1708661345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=rr2o9ZGkeflidRPpw8/LEAdJkzucagkxZDJJvUwtfI4uxNuW0KCt2sz7WvswmQEI+v DNkuR+1S4ik73TC6Jz6Ps3eIk5wYl1ckb/wNItj/MaqDg6pfqMGM+Mz5JUq4Xsic5vTL MGjZBFWxuj67vT9F3u6MN3bQtugdxTD6SJVBvqG9TiJTs/2CVlf1lhRmVLtelYpWbbrh 4umz7Yp6QVm3RSdNp09sWpPreEmn+ZPvVy+GazVJ71Wi/uF+xaJ9hJxurw2734ifaXae ctcXtOiXG58VAkbUq/RSLxyXJ6CWpD3sIBNtV+rlhDz7xSxorUNBVSKocwHH2i4K4NQG hKww== X-Forwarded-Encrypted: i=1; AJvYcCV/LOydAloFbm2JV4la88O8Ei5Ek5gVZ/zBohoOi5sJgpQrGbBqw0pUTXufjdFUYbqWcw4ftBp1boA6WCEOzMoYWbTJTJuYcurgKY51zviZHexKYGvL5ibwo+W8HdlbYTpmX7kTctPghHbb X-Gm-Message-State: AOJu0YyXSC7P09Lvzybj5pcRieJ81/xzB/QSdAKe5f1RmtzEFAKR5Cah hneWZfRNdXqbhlaiizi4qU0s675zE90rlv50Ws/p5kEPwSYAH4vN X-Received: by 2002:a17:90b:3606:b0:299:3657:4950 with SMTP id ml6-20020a17090b360600b0029936574950mr257715pjb.2.1708056544708; Thu, 15 Feb 2024 20:09:04 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:09:04 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH v2 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Fri, 16 Feb 2024 17:08:14 +1300 Message-Id: <20240216040815.114202-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791027625304209716 X-GMAIL-MSGID: 1791027625304209716 |
Series |
mm/zswap & crypto/acompress: remove a couple of memcpy
|
|
Commit Message
Barry Song
Feb. 16, 2024, 4:08 a.m. UTC
From: Barry Song <v-songbaohua@oppo.com> Most compressors are actually CPU-based and won't sleep during compression and decompression. We should remove the redundant memcpy for them. Signed-off-by: Barry Song <v-songbaohua@oppo.com> Tested-by: Chengming Zhou <zhouchengming@bytedance.com> Reviewed-by: Nhat Pham <nphamcs@gmail.com> --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On Fri, Feb 16, 2024 at 05:08:14PM +1300, Barry Song wrote: > From: Barry Song <v-songbaohua@oppo.com> > > Most compressors are actually CPU-based and won't sleep during > compression and decompression. We should remove the redundant > memcpy for them. > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > Reviewed-by: Nhat Pham <nphamcs@gmail.com> > --- > mm/zswap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 350dd2fc8159..6319d2281020 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > struct crypto_wait wait; > u8 *buffer; > struct mutex mutex; > + bool is_sleepable; > }; > > /* > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > goto acomp_fail; > } > acomp_ctx->acomp = acomp; > + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); Just one question here. In patch 1, sleepable seems to mean "not async". IIUC, even a synchronous algorithm may sleep (e.g. if there is a cond_resched or waiting for a mutex). Does sleepable in acomp terms the same as "atomic" in scheduling/preemption terms? Also, was this tested with debug options to catch any possible sleeps in atomic context? If the answer to both questions is yes, the change otherwise LGTM. Feel free to add: Acked-by: Yosry Ahmed <yosryahmed@google.com> Thanks! > > req = acomp_request_alloc(acomp_ctx->acomp); > if (!req) { > @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > mutex_lock(&acomp_ctx->mutex); > > src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > - if (!zpool_can_sleep_mapped(zpool)) { > + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { > memcpy(acomp_ctx->buffer, src, entry->length); > src = acomp_ctx->buffer; > zpool_unmap_handle(zpool, entry->handle); > @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); > mutex_unlock(&acomp_ctx->mutex); > > - if (zpool_can_sleep_mapped(zpool)) > + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) > zpool_unmap_handle(zpool, entry->handle); > } > > -- > 2.34.1 >
On Fri, Feb 16, 2024 at 9:30 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > On Fri, Feb 16, 2024 at 05:08:14PM +1300, Barry Song wrote: > > From: Barry Song <v-songbaohua@oppo.com> > > > > Most compressors are actually CPU-based and won't sleep during > > compression and decompression. We should remove the redundant > > memcpy for them. > > > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > > Reviewed-by: Nhat Pham <nphamcs@gmail.com> > > --- > > mm/zswap.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index 350dd2fc8159..6319d2281020 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > > struct crypto_wait wait; > > u8 *buffer; > > struct mutex mutex; > > + bool is_sleepable; > > }; > > > > /* > > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > > goto acomp_fail; > > } > > acomp_ctx->acomp = acomp; > > + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); > > Just one question here. In patch 1, sleepable seems to mean "not async". > IIUC, even a synchronous algorithm may sleep (e.g. if there is a > cond_resched or waiting for a mutex). Does sleepable in acomp terms the > same as "atomic" in scheduling/preemption terms? I think the answer is yes though async and sleepable are slightly different semantically generally speaking. but for comp cases, they are equal. We have two backends for compression/ decompression - scomp and acomp. if comp is using scomp backend, we can safely think they are not sleepable at least from the below three facts. 1. in zRAM, we are using scomp APIs only - crypto_comp_decompress()/ crypto_comp_compress(), which are definitely scomp, we have never considered sleeping problem in zram drivers: static int zram_read_from_zspool(struct zram *zram, struct page *page, u32 index) { struct zcomp_strm *zstrm; unsigned long handle; unsigned int size; void *src, *dst; u32 prio; int ret; handle = zram_get_handle(zram, index); ... src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { dst = kmap_local_page(page); memcpy(dst, src, PAGE_SIZE); kunmap_local(dst); ret = 0; } else { dst = kmap_local_page(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_local(dst); zcomp_stream_put(zram->comps[prio]); } zs_unmap_object(zram->mem_pool, handle); return ret; } 2. zswap used to only support scomp before we moved to use crypto_acomp_compress() and crypto_acomp_decompress() APIs whose backends can be either scomp or acomp, thus new hardware-based compression drivers can be used in zswap. But before we moved to these new APIs in commit 1ec3b5fe6eec782 ("mm/zswap: move to use crypto_acomp API for hardware acceleration") , zswap had never considered sleeping problems just like zRAM. 3. There is no sleeping in drivers using scomp backend. $ git grep crypto_register_scomp crypto/842.c: ret = crypto_register_scomp(&scomp); crypto/deflate.c: ret = crypto_register_scomp(&scomp); crypto/lz4.c: ret = crypto_register_scomp(&scomp); crypto/lz4hc.c: ret = crypto_register_scomp(&scomp); crypto/lzo-rle.c: ret = crypto_register_scomp(&scomp); crypto/lzo.c: ret = crypto_register_scomp(&scomp); crypto/zstd.c: ret = crypto_register_scomp(&scomp); drivers/crypto/cavium/zip/zip_main.c: ret = crypto_register_scomp(&zip_scomp_deflate); drivers/crypto/cavium/zip/zip_main.c: ret = crypto_register_scomp(&zip_scomp_lzs); which are the most common cases. > > Also, was this tested with debug options to catch any possible sleeps in > atomic context? yes. i have enabled CONFIG_DEBUG_ATOMIC_SLEEP=y. > > If the answer to both questions is yes, the change otherwise LGTM. Feel > free to add: > Acked-by: Yosry Ahmed <yosryahmed@google.com> Thanks! > > Thanks! > > > > > req = acomp_request_alloc(acomp_ctx->acomp); > > if (!req) { > > @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > > mutex_lock(&acomp_ctx->mutex); > > > > src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > > - if (!zpool_can_sleep_mapped(zpool)) { > > + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { > > memcpy(acomp_ctx->buffer, src, entry->length); > > src = acomp_ctx->buffer; > > zpool_unmap_handle(zpool, entry->handle); > > @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > > BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); > > mutex_unlock(&acomp_ctx->mutex); > > > > - if (zpool_can_sleep_mapped(zpool)) > > + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) > > zpool_unmap_handle(zpool, entry->handle); > > } > > > > -- > > 2.34.1 > > Thanks Barry
On 2024/2/16 12:08, Barry Song wrote: > From: Barry Song <v-songbaohua@oppo.com> > > Most compressors are actually CPU-based and won't sleep during > compression and decompression. We should remove the redundant > memcpy for them. > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > Reviewed-by: Nhat Pham <nphamcs@gmail.com> LGTM, thanks! Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com> > --- > mm/zswap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 350dd2fc8159..6319d2281020 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > struct crypto_wait wait; > u8 *buffer; > struct mutex mutex; > + bool is_sleepable; > }; > > /* > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > goto acomp_fail; > } > acomp_ctx->acomp = acomp; > + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); > > req = acomp_request_alloc(acomp_ctx->acomp); > if (!req) { > @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > mutex_lock(&acomp_ctx->mutex); > > src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > - if (!zpool_can_sleep_mapped(zpool)) { > + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { > memcpy(acomp_ctx->buffer, src, entry->length); > src = acomp_ctx->buffer; > zpool_unmap_handle(zpool, entry->handle); > @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); > mutex_unlock(&acomp_ctx->mutex); > > - if (zpool_can_sleep_mapped(zpool)) > + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) > zpool_unmap_handle(zpool, entry->handle); > } >
On Fri, Feb 16, 2024 at 11:10:04PM +1300, Barry Song wrote: > On Fri, Feb 16, 2024 at 9:30 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > > > On Fri, Feb 16, 2024 at 05:08:14PM +1300, Barry Song wrote: > > > From: Barry Song <v-songbaohua@oppo.com> > > > > > > Most compressors are actually CPU-based and won't sleep during > > > compression and decompression. We should remove the redundant > > > memcpy for them. > > > > > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > > > Reviewed-by: Nhat Pham <nphamcs@gmail.com> > > > --- > > > mm/zswap.c | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > > index 350dd2fc8159..6319d2281020 100644 > > > --- a/mm/zswap.c > > > +++ b/mm/zswap.c > > > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > > > struct crypto_wait wait; > > > u8 *buffer; > > > struct mutex mutex; > > > + bool is_sleepable; > > > }; > > > > > > /* > > > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > > > goto acomp_fail; > > > } > > > acomp_ctx->acomp = acomp; > > > + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); > > > > Just one question here. In patch 1, sleepable seems to mean "not async". > > IIUC, even a synchronous algorithm may sleep (e.g. if there is a > > cond_resched or waiting for a mutex). Does sleepable in acomp terms the > > same as "atomic" in scheduling/preemption terms? > > I think the answer is yes though async and sleepable are slightly > different semantically > generally speaking. but for comp cases, they are equal. > > We have two backends for compression/ decompression - scomp and acomp. if comp > is using scomp backend, we can safely think they are not sleepable at > least from the > below three facts. > > 1. in zRAM, we are using scomp APIs only - crypto_comp_decompress()/ > crypto_comp_compress(), which are definitely scomp, we have never considered > sleeping problem in zram drivers: > static int zram_read_from_zspool(struct zram *zram, struct page *page, > u32 index) > { > struct zcomp_strm *zstrm; > unsigned long handle; > unsigned int size; > void *src, *dst; > u32 prio; > int ret; > > handle = zram_get_handle(zram, index); > ... > src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); > if (size == PAGE_SIZE) { > dst = kmap_local_page(page); > memcpy(dst, src, PAGE_SIZE); > kunmap_local(dst); > ret = 0; > } else { > dst = kmap_local_page(page); > ret = zcomp_decompress(zstrm, src, size, dst); > kunmap_local(dst); > zcomp_stream_put(zram->comps[prio]); > } > zs_unmap_object(zram->mem_pool, handle); > return ret; > } > > 2. zswap used to only support scomp before we moved to use > crypto_acomp_compress() > and crypto_acomp_decompress() APIs whose backends can be either scomp > or acomp, thus new hardware-based compression drivers can be used in zswap. > > But before we moved to these new APIs in commit 1ec3b5fe6eec782 ("mm/zswap: > move to use crypto_acomp API for hardware acceleration") , zswap had > never considered > sleeping problems just like zRAM. > > 3. There is no sleeping in drivers using scomp backend. > > $ git grep crypto_register_scomp > crypto/842.c: ret = crypto_register_scomp(&scomp); > crypto/deflate.c: ret = crypto_register_scomp(&scomp); > crypto/lz4.c: ret = crypto_register_scomp(&scomp); > crypto/lz4hc.c: ret = crypto_register_scomp(&scomp); > crypto/lzo-rle.c: ret = crypto_register_scomp(&scomp); > crypto/lzo.c: ret = crypto_register_scomp(&scomp); > crypto/zstd.c: ret = crypto_register_scomp(&scomp); > drivers/crypto/cavium/zip/zip_main.c: ret = > crypto_register_scomp(&zip_scomp_deflate); > drivers/crypto/cavium/zip/zip_main.c: ret = > crypto_register_scomp(&zip_scomp_lzs); > > which are the most common cases. Thanks for explaining. Ideally we should be able to catch any violations with proper debug options as you mentioned. Please include more info the commit message about sleepability, a summarized version of what you described above.
On Sat, Feb 17, 2024 at 8:36 AM Yosry Ahmed <yosryahmed@google.com> wrote: > > On Fri, Feb 16, 2024 at 11:10:04PM +1300, Barry Song wrote: > > On Fri, Feb 16, 2024 at 9:30 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > > > > > On Fri, Feb 16, 2024 at 05:08:14PM +1300, Barry Song wrote: > > > > From: Barry Song <v-songbaohua@oppo.com> > > > > > > > > Most compressors are actually CPU-based and won't sleep during > > > > compression and decompression. We should remove the redundant > > > > memcpy for them. > > > > > > > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > > > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > > > > Reviewed-by: Nhat Pham <nphamcs@gmail.com> > > > > --- > > > > mm/zswap.c | 6 ++++-- > > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > > > index 350dd2fc8159..6319d2281020 100644 > > > > --- a/mm/zswap.c > > > > +++ b/mm/zswap.c > > > > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > > > > struct crypto_wait wait; > > > > u8 *buffer; > > > > struct mutex mutex; > > > > + bool is_sleepable; > > > > }; > > > > > > > > /* > > > > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > > > > goto acomp_fail; > > > > } > > > > acomp_ctx->acomp = acomp; > > > > + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); > > > > > > Just one question here. In patch 1, sleepable seems to mean "not async". > > > IIUC, even a synchronous algorithm may sleep (e.g. if there is a > > > cond_resched or waiting for a mutex). Does sleepable in acomp terms the > > > same as "atomic" in scheduling/preemption terms? > > > > I think the answer is yes though async and sleepable are slightly > > different semantically > > generally speaking. but for comp cases, they are equal. > > > > We have two backends for compression/ decompression - scomp and acomp. if comp > > is using scomp backend, we can safely think they are not sleepable at > > least from the > > below three facts. > > > > 1. in zRAM, we are using scomp APIs only - crypto_comp_decompress()/ > > crypto_comp_compress(), which are definitely scomp, we have never considered > > sleeping problem in zram drivers: > > static int zram_read_from_zspool(struct zram *zram, struct page *page, > > u32 index) > > { > > struct zcomp_strm *zstrm; > > unsigned long handle; > > unsigned int size; > > void *src, *dst; > > u32 prio; > > int ret; > > > > handle = zram_get_handle(zram, index); > > ... > > src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); > > if (size == PAGE_SIZE) { > > dst = kmap_local_page(page); > > memcpy(dst, src, PAGE_SIZE); > > kunmap_local(dst); > > ret = 0; > > } else { > > dst = kmap_local_page(page); > > ret = zcomp_decompress(zstrm, src, size, dst); > > kunmap_local(dst); > > zcomp_stream_put(zram->comps[prio]); > > } > > zs_unmap_object(zram->mem_pool, handle); > > return ret; > > } > > > > 2. zswap used to only support scomp before we moved to use > > crypto_acomp_compress() > > and crypto_acomp_decompress() APIs whose backends can be either scomp > > or acomp, thus new hardware-based compression drivers can be used in zswap. > > > > But before we moved to these new APIs in commit 1ec3b5fe6eec782 ("mm/zswap: > > move to use crypto_acomp API for hardware acceleration") , zswap had > > never considered > > sleeping problems just like zRAM. > > > > 3. There is no sleeping in drivers using scomp backend. > > > > $ git grep crypto_register_scomp > > crypto/842.c: ret = crypto_register_scomp(&scomp); > > crypto/deflate.c: ret = crypto_register_scomp(&scomp); > > crypto/lz4.c: ret = crypto_register_scomp(&scomp); > > crypto/lz4hc.c: ret = crypto_register_scomp(&scomp); > > crypto/lzo-rle.c: ret = crypto_register_scomp(&scomp); > > crypto/lzo.c: ret = crypto_register_scomp(&scomp); > > crypto/zstd.c: ret = crypto_register_scomp(&scomp); > > drivers/crypto/cavium/zip/zip_main.c: ret = > > crypto_register_scomp(&zip_scomp_deflate); > > drivers/crypto/cavium/zip/zip_main.c: ret = > > crypto_register_scomp(&zip_scomp_lzs); > > > > which are the most common cases. > > Thanks for explaining. Ideally we should be able to catch any violations > with proper debug options as you mentioned. Please include more info the > commit message about sleepability, a summarized version of what you > described above. ok. I will enhance the commit message of patch 1/3 with the summary. Thanks Barry
diff --git a/mm/zswap.c b/mm/zswap.c index 350dd2fc8159..6319d2281020 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { struct crypto_wait wait; u8 *buffer; struct mutex mutex; + bool is_sleepable; }; /* @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) goto acomp_fail; } acomp_ctx->acomp = acomp; + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) mutex_lock(&acomp_ctx->mutex); src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { memcpy(acomp_ctx->buffer, src, entry->length); src = acomp_ctx->buffer; zpool_unmap_handle(zpool, entry->handle); @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); mutex_unlock(&acomp_ctx->mutex); - if (zpool_can_sleep_mapped(zpool)) + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); }