From patchwork Wed Jan 3 02:57:58 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: 13509631 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 D308CC46CD2 for ; Wed, 3 Jan 2024 02:58:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CFA46B0306; Tue, 2 Jan 2024 21:58:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 257AC6B0307; Tue, 2 Jan 2024 21:58:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC616B0308; Tue, 2 Jan 2024 21:58:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E64926B0306 for ; Tue, 2 Jan 2024 21:58:25 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BA4A7C069C for ; Wed, 3 Jan 2024 02:58:25 +0000 (UTC) X-FDA: 81636491370.29.9261F3F Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 221741C0004 for ; Wed, 3 Jan 2024 02:58:23 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KT/7M14s"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704250704; 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=Ro8Y0j0Jt26z5Mz6Dk1T+PNwiPxDyxcm45d9joAfXn8=; b=Mq7bKPQRnI4kDKsYgWKqoKdfyd2gZRg2yOSSrQ1xIttdlP4hgKclRohO20zRCyJlmZOYAQ LE3ytmImXw4n44iOhfoaJMmXD22+QCyE1hMYeQ16Di7fpuEfhRg4BouBJnSo2f4N7KPO3K fjpCI5qLamvfuR0exs70eOT1YSh1eeg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704250704; a=rsa-sha256; cv=none; b=LcaugFcJYFiRrxcW5zTJSzLHBD1sunGVCkXwuC27w/WcUGslZ1Pn9U8rtjrCpKR611dqBb MQv5S1TolcxkuOmWXlTWCM823nRi9gXioOFV/a108rFYg2ZNvxQwjb7WaJ9sebMXSniT7t iY6xA1E0c/z/1MZ8eCo6mbNhsD1ljoA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KT/7M14s"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5c66b093b86so42049a12.0 for ; Tue, 02 Jan 2024 18:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704250703; x=1704855503; 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=Ro8Y0j0Jt26z5Mz6Dk1T+PNwiPxDyxcm45d9joAfXn8=; b=KT/7M14sLEhaUni/SMq0bHH/QbEy19UHGlqoDdT8v8QFK6cD8r52Jo579Sa17+dlv2 rjE/DDb6OkdJ0ye+qtsWUnf/JF4Fyn1QsTSfZBUnEEdQbmWWDAAQAAjS/+9eVoZJribK wQcafnySPEKCjyqmAw9Qg+vVlqeGKtRN6PWmxwQZTxBej3M5iwcPFSFCnWG4h2SaYIP+ 6SQfvjMtZUYEG8u30lGm7j/1RA9+g4hkMBCsE3b6Ry7MiCQFzyMQCIb6kEI+e0OE7Hog 4OJ3FLM7YdZj2stZ1BuLRhOAnv0uAL9ibTYhAqaJTVJDoq/1RqR+y6WKDavQ+/Ap2Hdq Ou7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704250703; x=1704855503; 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=Ro8Y0j0Jt26z5Mz6Dk1T+PNwiPxDyxcm45d9joAfXn8=; b=OLMJjp4la2VnmItoX6aosOk3Td45g5dDxWalHjWWgmwdUqOybGgrMzDnSvMbdPC6y9 nWPi9kqk+z2vWSCuhbYuocgA9t5AqXMI3QORVclF2PjIlB0bgeLUU0x5Xeszj1Qsn/j4 eRUWssljAOklXcsW3Yuy6Rqr+NmfaC57ebKjDDAt+EuKILmFB59Ga9gkABQzHamWuWXm YEWymVQlKCRgBpDiWOLWri81ktZpBU4/VPuJpgIQ9M96Ou11dymdXKn9vQHBw/MFs8A5 fpD/j4/J0L66462ZEoLdpW69If+zz44fqTA9oARZocsygbGYvSqTJkXCZSbGfHU17u61 CWhw== X-Gm-Message-State: AOJu0Yyr2uNgq8XHfnnPruk0GW5oeizyoWdrYtyt26YOaWR+STuXj9hj NEmWewfkho8BXRqppmgJozk= X-Google-Smtp-Source: AGHT+IHg0kL0VkhfiKjZqGlDkvzVw6ytZtdeJvrtTSssilg7C2zxj//va2NtexTtk2eArS6S4PPYUQ== X-Received: by 2002:a05:6a20:2443:b0:196:c543:abaf with SMTP id t3-20020a056a20244300b00196c543abafmr513723pzc.38.1704250702826; Tue, 02 Jan 2024 18:58:22 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a7d6:f37a:9130:cd96]) by smtp.gmail.com with ESMTPSA id d6-20020a63fd06000000b005cd8ada89e5sm21168572pgh.70.2024.01.02.18.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 18:58:22 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, hannes@cmpxchg.org, linux-mm@kvack.org, nphamcs@gmail.com, sjenning@redhat.com, vitaly.wool@konsulko.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Barry Song Subject: [PATCH RFC 2/2] mm/zswap: remove the memcpy if acomp is not asynchronous Date: Wed, 3 Jan 2024 15:57:58 +1300 Message-Id: <20240103025759.523120-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240103025759.523120-1-21cnbao@gmail.com> References: <20240103025759.523120-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 221741C0004 X-Rspam-User: X-Stat-Signature: 6dq9ojuw1xr1kfuweqket4mkr48yj3um X-Rspamd-Server: rspam03 X-HE-Tag: 1704250703-214039 X-HE-Meta: U2FsdGVkX1+SexM5br9XpfrMaG0ov6ZwAX876EuuamKRNOxI3Lx20G8t+/kMCPafAExJiqTS7sJQNlRvv8mo5w2yEBF5j8kv2fUGYL8KUh9eau2LW3Vp7Nt2KXjjm3eYKb6N9VEXDGCFvRJqKmSt6TREF0O+EI9LVHOZ6tDFE/Ck/1EvLsZq40CKp6RgTGfU/XcKXlnDnwrWHZvkdeATdka1CMndRCz19K4iVbikbDSdOP9ui+uy4mBfbPPbSOf330zFC59cJYFplTOgAnlDTNWzajkTe0wGQ9MhUPqHBz/F9hA+kByFoazTyXTRbDZ+kLbPOswUxuK+aOi0w0RBPg1A8l8GEWt0vQOiEPKwnk30FGJ31H6QGKWfhG3dnHgG8GOUT5/wxVy6chwlk7/VftY8doa2eSOc2tM6S3JYgOq1K8A1M8iX4RFj5pSfE/AXbx4HNkB6aVQNWjxhgML/qVqH/Dbxu5KSA7fEHCDsi5V9ECvDQl5kiQhdL+ZLBVIqfhf8UH7h4mBDFKwsNytuwJ85gbMRpnggRKww75OxdiZoSgudrly2a87R+f6LJu4hIZNPsv7GFDjds6IkcTkcaOQ2z6CvyKusGZ4ieJiDKI/qkibOIIxXux8ir2GEdVG6g/mFjgN6+HC6Q9uliskBNLpXMqmGNE+vzy2+NfalINute9aicoTsY6sTUkC7iSl5bVsFzp0p0hgr5+lBLjdfJIUP81UfmJaqMBrMIz+C1yHES1h0Jglpm6tiiNshvAsI/TIlDxb9x9CaHg2+GqMDz+rBROnB1/W+FtMsFfRzwbP1bMWazJxSm6Ueq+tCCblG14g1cRE3SeNIHxLRNOeIEpfnhp9c19s3jh78iVuHA9fPdJjXEotYq8RPe74wIrmiPUK1w1bWeYfsMLwPYMh8FSF6unZv72yPQRQ+7sngywMDvqgprJsN8CqK3Yykjf8T0XWxZWNY8rQ02Cb57eB KkWQbKOy 7bbMC+NGIBodqak/BaNIna75U3tMQu3bVLnka3L9txLL3OUyeziu8rEwxeWNuTFbqbm6U4tnzBINKy4o86Hf6SqPTAdLQwEeIKrj6G8jXvQ+5Esn9ljc/MSiPYg== 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, they won't sleep during decompression. we should be able to remove the redundant memcpy for them. Signed-off-by: Barry Song --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index ca25b676048e..36898614ebcc 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_async; /* if acomp can sleep */ }; /* @@ -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_async = acomp_is_async(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1370,7 +1372,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_async && !zpool_can_sleep_mapped(zpool)) { memcpy(acomp_ctx->buffer, src, entry->length); src = acomp_ctx->buffer; zpool_unmap_handle(zpool, entry->handle); @@ -1384,7 +1386,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_async || zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); }