From patchwork Sat Feb 17 04:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13561232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A410C48BF6 for ; Sat, 17 Feb 2024 04:51:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 964236B00A7; Fri, 16 Feb 2024 23:51:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 915986B00A9; Fri, 16 Feb 2024 23:51:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B6936B00AA; Fri, 16 Feb 2024 23:51:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 66FDB6B00A7 for ; Fri, 16 Feb 2024 23:51:37 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 401D0A0150 for ; Sat, 17 Feb 2024 04:51:37 +0000 (UTC) X-FDA: 81800072634.19.48E46C8 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) by imf06.hostedemail.com (Postfix) with ESMTP id 5B2D9180012 for ; Sat, 17 Feb 2024 04:51:35 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="S3BL/57n"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.160.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708145495; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=mzy2E1bclv4x5HKtMJz9DmH6fk1Z7IVgcrW+0pvdyAaZvx+u95m+Jevu/XVKSTPNzrqGvH F3Doi9FzFI1897fS5fSwqB7qu2YvMS7bp1JLdv0ydMsChVy+MUTrD7SAnO9g9U7iuoxeIc TDY1s0Ii6GKJGCG6Ka+t0MDTYda1SFE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="S3BL/57n"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.160.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708145495; a=rsa-sha256; cv=none; b=T6V2b7EoMxqy6Ot3manXk0K2oMM4nTAJ/VF7GaB7ePeLWFEQVxGn2WBOY6DFUsh/sJdILl LBQVaLCyDpjGMst9bcoUk+Tb2ZSrjDUCxE1webjUUWSV60UeJIJFr2KC6t2iza+WnyKxL7 cczLDjvxAV7aEWWHCKLHNq6III36JqY= Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-21e7c3e3cf3so630349fac.0 for ; Fri, 16 Feb 2024 20:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708145494; x=1708750294; darn=kvack.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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=S3BL/57nvKdpctnWzNNqSL6qiZuXHsZ6K0IJinMzONv34CaSlzA3B+bbpp8s4dE3gp /B7ctb8MmlGolRCbvJLeFnVQJTyTsP1pM6kL56N/FqRREoG/feDnq3dXQSEfXLCJ8v1p xO4Lvr5JqJ56qr1aaMZ1o5goEp+wfRsO/kQqjOUktZlnR0p4vRy/4n0VQFSnp7IPSicp fzzHoWpSFl3ShMnEPl6be+ulPljsdtXOAkZFMzqLS4jAktRc0Iv7RmgWePICab7b7JAM 8AHs0xsmwtGIcvn5eKlkQChIJBDOjmqBRiqbl7FQalJf5Rz+6WKK5T1yjjfKcNFIpg/i x4Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145494; x=1708750294; 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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=fxfGCsyCc1pwj1u1R/WM1C5OTVKe8eC7sMWay1d10I38qZQdw2AddqQB7Ah65BQcQU vDFBvoQkSEqS+Ud5p5xfHOoSG8I59MHruEYbwptf23bDlp9YwgkU570b7gBFQnPbpOiD BC9ETlbrf0pREA2abnhvYEeG4ksDaghmEpZBjI1z8B0qd+aYqSrC0NuZmvBchLM5cAPd iG29l1LBFenH/SikugOdj3BkFPJuObX+Fe7bI/uS/AUIRXxBPF+cLQa6atW9PAjHcu4N 0nOr9WN0wzg6jQRxvE46YzvtMRngSsooeBd90y8VlFbWif+FaidPlhw3Qjl7fKCT3uoM tq8Q== X-Forwarded-Encrypted: i=1; AJvYcCXZTGTmGMwci9LfkeNMdhw+jp7UZ7XfBJj/GK6q00OTxZ+dGMfprM9LoL3WnwBvmWIVsG/WOSZCwtdaHi9P+DnN3Jo= X-Gm-Message-State: AOJu0Yys5SQc7fpF7kWCi4bE0g0vblaIjOEX9/HuoeMT9RzH/z2sLAI3 0aZ5VhExtHBT0Zhwzjjt0gN3O3Ii3cqIqB9wqolaf7E0a0qYsR2b X-Google-Smtp-Source: AGHT+IGXBcB2jEgts68yjl1/2gfApQFlQtEQ7ti8tGvcpljUmlNkpP8SfC6UTw1pnxGbgjKEotNTBA== X-Received: by 2002:a05:6358:3a04:b0:178:f895:5978 with SMTP id g4-20020a0563583a0400b00178f8955978mr9891587rwe.10.1708145494362; Fri, 16 Feb 2024 20:51:34 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e82e:22f2:1bdb:989f]) by smtp.gmail.com with ESMTPSA id n14-20020a635c4e000000b005dc2ca5b667sm610703pgm.10.2024.02.16.20.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:34 -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 Subject: [PATCH v3 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Sat, 17 Feb 2024 17:51:01 +1300 Message-Id: <20240217045102.55339-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217045102.55339-1-21cnbao@gmail.com> References: <20240217045102.55339-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5B2D9180012 X-Stat-Signature: jk5gygupj9nwrbjez8safh8njbucnkce X-Rspam-User: X-HE-Tag: 1708145495-617485 X-HE-Meta: U2FsdGVkX1/wYQqRq6FCuyPnANXrbn3Kx0GGgH8VvTiRsG9KxKhuKqDjXWYDzLZUP5D5cMTrRcRID82dBDXySNAxiyWrSFwQTSve+NphnnNXgg46z4C4C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tn9znOXBm+3XhgPjSsza06LgAOke92goxzUuFgrypYLiZGGBccvdTi090NSj6gnk5imDBKoqQSidoUVXhLMsf88iAjqH/Vb8tF+pUFZ6DA7pIrsaIL5J+yYoFznDTthF39VnRFDkK57BCtdHksAMTP52dCRKJe8HBM8HGiWtNS9/VIHtZSoUggqCVQWgIRQoY+baG1+eGS2NTVfOOdjZAiTTsU48M7CovPNUC/eFWhxoRBm895LlNBH/jOEX0/ttzz4e4xE9l7Er5IBp8S0uX7LDV9HH8m7Rr/Ysjae9NMxaCt/Tz8LntNhumDygMXnFQ5FLb4Kf2VRcoao8v51KXKbPovzedfPJbgosz3M+VRpPc6OPtOyJM5YTEE0N+5A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Barry Song 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 Tested-by: Chengming Zhou Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- 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); }