From patchwork Tue Feb 20 06:44:12 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: 13563466 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 390C6C48BC3 for ; Tue, 20 Feb 2024 06:44:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEC466B0092; Tue, 20 Feb 2024 01:44:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9B1B6B0093; Tue, 20 Feb 2024 01:44:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3C056B0095; Tue, 20 Feb 2024 01:44:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 90D576B0092 for ; Tue, 20 Feb 2024 01:44:42 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 64955160581 for ; Tue, 20 Feb 2024 06:44:42 +0000 (UTC) X-FDA: 81811244004.05.886E70E Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 91BABA0011 for ; Tue, 20 Feb 2024 06:44:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BkdOxi0A; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.172 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=1708411480; 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=VwTIFpBnJrjGyIT/20HYU3RPVaQg5c8zhvFCBIT6Ljs=; b=AiVQCofWblk+ywrqb+gfIWlSfnwfGQ3POCDnh2JFVbdOdP1nz+PebIudUeCvbqtHHW+Vf2 kszKpqoar7Oq0mJFbksq5mW5GmrkofvG2HSdHTYv9mX6QF8PGi5FbhWNX2yaAy7wfdMIoz U1S3hqLwaD24AXCehWJ256CQl5HJeD4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BkdOxi0A; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411480; a=rsa-sha256; cv=none; b=CuL6QN2ahfmqSWI3jtU50OxxW7MWk48dM5zFdecv7kfY2OqzM+XKukrnlxpG7O0YXn/A6u J7icmRz+Rpdl7Pf1/agGX6CIflWTNgnHm6YCPGijRRfwGsm5Ssu43HUCHvyAery9DiUZIq AVxZ1yMHO7WpZcFbuBw82EFgSUcQJuE= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d91397bd22so42898945ad.0 for ; Mon, 19 Feb 2024 22:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708411479; x=1709016279; 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=VwTIFpBnJrjGyIT/20HYU3RPVaQg5c8zhvFCBIT6Ljs=; b=BkdOxi0Aj2l0yyxprtBIC8GZSwb7Pyds22Uw5gUnBApsuL+YclB2c4GcClnaE99jml 3CXXiO83tVlDjki1D1Ry7kZ+29DwQIlMlU2afjPM+2UtBELCgJ+xoQJPBhlGFa7CbXq0 H0zcITyTPs7vcbeiI/Yscyr8HowjmODP7RIJ4uhCd0BEMBeDztKMob7Af3TZsYmr0FEs VzD4W6GDF9UUE59cpTuegeZDTMgzCq8bAd10HJ8lPOoOri/ynUK/ZwEOHJt3nChUD1Fm Iyk2vU9WqRcyaFKlpiMko3g6mr8Q68+OFUd9X9johUZurqjUiArIxmN2MOoE4uNKeLKr rNlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708411479; x=1709016279; 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=VwTIFpBnJrjGyIT/20HYU3RPVaQg5c8zhvFCBIT6Ljs=; b=oPwosTjYU8wmZLxEXcPkUeIk5Y3GUjF6Kj4lxbPnGDRihMhTgc77Tgi1wiK5U0tBq0 KvweRhOGCjUiwkWFwBwO4s9Tj9QIYK0BOiobm9XYVX0NR7jPxfdjJClNMpEiFNgARBjo uCre1iEsrOYrzaA8r6IIrDsEhqpclLlkHzr/sM4L6L7DYZG/mxO5JzaNpUAEIHb4L9bL BwEEIiXhYHbiIqoQubZUE03EVFbWzhNq0jeDN4GajOVlRJ2z/Qky7Vc5FqMum3Nxcrhw XgH5/STFvQk2idrsaLsYFZ9Jcbh//SZth6xfTxXANI7nxdp6ZDA6blk47S5kbu1DBIfJ RS6g== X-Forwarded-Encrypted: i=1; AJvYcCUXlsrfSIlX9PgxKB97o1AaSQEkq6yKBEb3zy9tYvo1ywtWImyweHawt7KiAa8ouIV6NwkXx1zMtY0X5ohGlEFQkSI= X-Gm-Message-State: AOJu0YwebhBHQz2XfOzQyXBreaW1TelxaBa1tEXgiiqaTh24HPF45O9G C3U5eWosOFtpZEIcUxNOs057kmMyq64R5x/22wzFvF8Opb3lDUbO X-Google-Smtp-Source: AGHT+IGai50/e9Dq4GggyO4YXfBocAVgdbPmMRi2mn4PPi0R3OTzklhwKOf6W7+VfocVSf50DBd0sg== X-Received: by 2002:a17:902:dac8:b0:1db:cea0:9d62 with SMTP id q8-20020a170902dac800b001dbcea09d62mr7790208plx.9.1708411479355; Mon, 19 Feb 2024 22:44:39 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a5bd:9c11:af2b:aecf]) by smtp.gmail.com with ESMTPSA id w16-20020a1709029a9000b001db60446abdsm5419090plp.262.2024.02.19.22.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:44:39 -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 v5 1/3] crypto: introduce: acomp_is_async to expose if comp drivers might sleep Date: Tue, 20 Feb 2024 19:44:12 +1300 Message-Id: <20240220064414.262582-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220064414.262582-1-21cnbao@gmail.com> References: <20240220064414.262582-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 91BABA0011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: xcwqge9qj596yrqiiwxght5zgj6exe6y X-HE-Tag: 1708411480-319834 X-HE-Meta: U2FsdGVkX18kupH/XgfIl4s9MeTEsDfpgDutrGkDuXBbNPAq3vB4tA1PV+ygxPlLG/eKqBU6bbhf65RmBoOlHTvktxdDJs8jXAxrVqOyMdAOZa2FOh1P5o5buYETtkjA5KebcsL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y1IfFw/IBujybtqcTWPFOivAj0KUY7cvB85JfIcLQB5Ez7NA3G0L5Q0bvjpWzQBcThb8DWoZeyN/RDKQ8bHKAdbbjp2Yo7YjRyqK3aUC1oQj2T2ShbPnt9sgKlh+OW7LfI3PdqrHfrkbUfyUoDsZw+t2iUqDMA/v+H0UT2wyHmcW+ii61G5mjx/i/h0/qu6tshSjYRnswZeWo0IiGX5antFqzArSuU2re+UCI8CZaA1hzagRIJNhEHs4x8qorN5VuO3C+AWFyhZC9GPVUkXygRKctNNPrp2Jh0mt5tCmEidtl/3rlIe13QKUQDONyfYlxggay4flu 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 acomp's users might want to know if acomp is really async to optimize themselves. One typical user which can benefit from exposed async stat is zswap. In zswap, zsmalloc is the most commonly used allocator for (and perhaps the only one). For zsmalloc, we cannot sleep while we map the compressed memory, so we copy it to a temporary buffer. By knowing the alg won't sleep can help zswap to avoid the need for a buffer. This shows noticeable improvement in load/store latency of zswap. Signed-off-by: Barry Song Acked-by: Herbert Xu --- include/crypto/acompress.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..80e243611fe2 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -160,6 +160,12 @@ static inline void acomp_request_set_tfm(struct acomp_req *req, req->base.tfm = crypto_acomp_tfm(tfm); } +static inline bool acomp_is_async(struct crypto_acomp *tfm) +{ + return crypto_comp_alg_common(tfm)->base.cra_flags & + CRYPTO_ALG_ASYNC; +} + static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req) { return __crypto_acomp_tfm(req->base.tfm); From patchwork Tue Feb 20 06:44:13 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: 13563467 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 5F5BEC48BC4 for ; Tue, 20 Feb 2024 06:44:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5C616B0095; Tue, 20 Feb 2024 01:44:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E0C826B0096; Tue, 20 Feb 2024 01:44:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C86016B0098; Tue, 20 Feb 2024 01:44:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B51856B0095 for ; Tue, 20 Feb 2024 01:44:48 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 84B91120419 for ; Tue, 20 Feb 2024 06:44:48 +0000 (UTC) X-FDA: 81811244256.02.F0A4220 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf12.hostedemail.com (Postfix) with ESMTP id CB9F24000E for ; Tue, 20 Feb 2024 06:44:46 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="DqBs348/"; spf=pass (imf12.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411486; a=rsa-sha256; cv=none; b=xlt3sBF8Kryp2Jk1eK8j2cUzINKLSFHirOoSMD5K9FWwS+9GHXMzs9wdmp8nquhUB+DkpP lagamoIOj4bw4Xj4x97U5XYHCHErb1T3v8dDW3U239nZaNwqxjgE48F5QnblALnvd0rsTu Vz7UC93DsgKzoi4IA4XQqgbAik6ka+c= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="DqBs348/"; spf=pass (imf12.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 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=1708411486; 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=Z8rNl+BjuOiPHO8BwMbPluxA5iMY9ZQk2ZuevI5ELxs=; b=AaSyj/9l5rKvuShTca5dlQztJDdVUZdMN0Vc6t8FFV0oFZTKSXtAVnCbDIeFyi7T8eS1P/ Cs2hOqQ0a3NFS+lNdTujT1q1odPd9H8TzNo15FZSDr3C7M3E9TOBAfWupZvrX5f+VDx6WY P9eGnhyTkdh2UKbsP/XfboxWAjda/H4= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d7354ba334so46329365ad.1 for ; Mon, 19 Feb 2024 22:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708411485; x=1709016285; 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=Z8rNl+BjuOiPHO8BwMbPluxA5iMY9ZQk2ZuevI5ELxs=; b=DqBs348/t3GNwOHhIC/7q8TUPzaBCPJ+jkkydcJ+k1UZ2g53RBlOVf/qg5itaAOkFc Eisj8P4KFUwKWuMQapg4DHKcTbyZTVr79OoTr8GZFSQGX7y5Y/cRdJsCWx3Yo5teIFMp fe1wzThFVotpwN6+c2J845Qe8jSRtW0GcgEUo+V7s9nbkPD/JCiiIO9BZjYzrn0HRO80 tKiIXT3ufnMeizSB/8H+m6VR+Mfz23sDeZ2PCvS9h2iP9KryPvIBAiRW0TolCy6q2roW j9lgseh0KS9MR4Wnc62py+MBX2y00kulYfOusSdjwpVGLJy9qp7E93wCst4B3Va0VmqS Pz9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708411485; x=1709016285; 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=Z8rNl+BjuOiPHO8BwMbPluxA5iMY9ZQk2ZuevI5ELxs=; b=QjCcBPFhuN4AxG7DcrVnb1QtVQ1eHNFv2bIISmffQEdch2lHWfen6UMS+U5sbWZLo3 Yw512rQIyoiC38YOPWwlZqcTuT82/wCwpFARFcatQC1UmE3ucrqj9vEkudrzi6NBdE8P g0JPuaYCRFmKj0T+46ubuxY0b9i6BNDJ/OlYC2ZbukCll+sY/P5XbaCaCx3O0onKrTUM jF4EGbt+v/pzSRsu72ZSxcxpKNKO8GdTy8gWxFP89x1RsbgGAHloAc5k+dLfAiklw2sD qiU2rIm2cB3X0OG6CtiN6v+4TRtxNPvcfQO8jUeHg0biWOEAropSy+V2nIjzgpImtenr 0K1A== X-Forwarded-Encrypted: i=1; AJvYcCXgT1IRK7bpy1MPbT4JtKqViaAAp6rgazvKeDkLMkIi48Egg2JTMrI3pcdR48TOF4LSoOEOjahcqCz6hnB3sxFHbr8= X-Gm-Message-State: AOJu0Yzp9B17kIz7XrmSwD92SDDecBXBIaDlm0Pj7sqwL3N6mIWC2Y7b RipL+ZRa0m6oc/33q/sy50Y2POez/cEoCf+PIUY0g/GRXX1LIy9C X-Google-Smtp-Source: AGHT+IGjLI8WrT5H3cLslymf3abuNOE5Ga3w1JP7qFoprv9R9pGvpeHXjEqD7rjwt07BKGzckg9xsg== X-Received: by 2002:a17:903:11cd:b0:1db:82e3:8d7f with SMTP id q13-20020a17090311cd00b001db82e38d7fmr19374961plh.16.1708411485583; Mon, 19 Feb 2024 22:44:45 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a5bd:9c11:af2b:aecf]) by smtp.gmail.com with ESMTPSA id w16-20020a1709029a9000b001db60446abdsm5419090plp.262.2024.02.19.22.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:44:45 -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 v5 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Tue, 20 Feb 2024 19:44:13 +1300 Message-Id: <20240220064414.262582-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220064414.262582-1-21cnbao@gmail.com> References: <20240220064414.262582-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CB9F24000E X-Stat-Signature: 7xdjpzc9mncyw5ouuus4qkzy7neq1e3x X-Rspam-User: X-HE-Tag: 1708411486-841787 X-HE-Meta: U2FsdGVkX1/pq0fwlCu1MzmBlsIveoicAkowuXJYpPh60amIPkliLhnWMYw2EqFsuSH8V1MiInVUTS7gZisSskVMQ4vv5EhQvmDhjjgsCfUwEr27ya7OdwnOJPDL6EwpwTPPbXBahozyk35PuA7RpbyCbkuipEXaGEg/vaz9/Vgz3qI0diFZIHY38SuMvhII0LAxrPO3pO66LmGJ8Z7cN7u8EbGdB00ieM2MQL8sXd9it++IUCyhjrazRUqDIoCpS5ZQpSApDQhTUlK16SpgTKShFsCVde54xDpoQf6LfOMFeivAgsYTQbQ2bsb1Ns1kEbHxNifaCELmJBNX9F2PyoLuBv2v6YZ/aN++KDslbssreUn8z6qDwuc0LWniwwePz+pQZCg0nmV/iQ1LdQTc5BN2zQ4+p1C8Isv3kfSjr5JNseOEL6QVJYYG0Y0yFUZX9P4dtaVINwTmtAuALre6lWO3DyFtwxthf+IrbrlZ8fjFaeNqhYJkRc1fFZLZwBlBREzHIxaZq75Kr2wRv2RVOGEm99Q+8w2alVaIbstgbl1YU9yPpqqtK5OQc9+O3mK6ij1Kf6v6tKBKdXAfYftU7b+rwLCxU6/ibmxMCiHWhoWECRMs9q816tc/okUj8lzaw7b+StVe522jOpyhAKQyLmBTQX+Oaur7cYNKPewz3OywfGUj8al1vxLvQe5+juSBli5Q64wkCti9sn2Yy5xoCEbs1pqj0x+qTtR3vNZGnlHiCDIE7n2mnePGccMu1ZBDiDXS9Wpf3u2EBmAOltJOFLvxKvRJrMWbHBRSPK9o5peoxfFX+xQ50CBSF+ae3JzWRJN70bT+07Z9FhNwTYI6Q5iQxUYCg1O+Jn1MjXNoM9Or5Z2BnEXlfWI76ouMbwKAni5b4Yz7pw9jYd7sDdkYmKaVyQQOXyX1hIC249/TYPUJ9pqziMtdddKBWtHGItY4hjiHL3JQXMk4j3iDMVm 9II/I08u WRbSMK1kyBc77OEDZyq2PBwrzxOE+FFXNHokxVWj46BKYeW9iXY0CkEvUPvurkCBMUkANqNdCpXYYnKUHyCSSS+LbFRSop5gvwErHfDrR+H7qGe/jvoZry9W0FQ== 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. 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. 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 51de79aa8659..ef782879291a 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -162,6 +162,7 @@ struct crypto_acomp_ctx { struct crypto_wait wait; u8 *buffer; struct mutex mutex; + bool is_sleepable; }; /* @@ -973,6 +974,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_async(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1100,7 +1102,7 @@ static void zswap_decompress(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); @@ -1114,7 +1116,7 @@ static void zswap_decompress(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); } From patchwork Tue Feb 20 06:44:14 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: 13563468 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 08D94C48BC4 for ; Tue, 20 Feb 2024 06:44:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B73D6B0098; Tue, 20 Feb 2024 01:44:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 868EE6B0099; Tue, 20 Feb 2024 01:44:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 708456B009A; Tue, 20 Feb 2024 01:44:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5DD5D6B0098 for ; Tue, 20 Feb 2024 01:44:55 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2EC331403E8 for ; Tue, 20 Feb 2024 06:44:55 +0000 (UTC) X-FDA: 81811244550.23.81D0E09 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 4C3C214000C for ; Tue, 20 Feb 2024 06:44:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nnkdO20+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.51 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=1708411493; 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=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=YFYQ3v0ZGCEIX7V+o+HPJEP0SYcnSeNVx11vdaS6780nPZ0U13IbYuy3tSmkfZweVCnd+r UviDA3Da9MJ9TcI7QVl3Ia/fiQdNtKH6vt51UsNGH6IOydO65kof/OMCZrTO8SfyxOILsV 4bspq7kzomB7bTntY8+VS17ZYoeeQKI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nnkdO20+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708411493; a=rsa-sha256; cv=none; b=s3hLDOv84breQ6rnxiyro6eu9okdU8e2PrXF7zr6uMSnZROtBvBdQ56FOZSY3dN40Q9aJK +FYKtoBxfSlXNirRlPmoo9WxQBTvqtIcieAhyQdR0lJo+mWnj2i0l5dFu/SjgRAxNT/KnB 4M/aqqspOrfQPvoEEJS7utAbalrHUBo= Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2995185dbbbso2582079a91.3 for ; Mon, 19 Feb 2024 22:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708411492; x=1709016292; 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=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=nnkdO20+HWsnEtTpflkmaf6MCsV2K8xye8fX//80v23vL2TW6ibRBDi9Lszai6RX9r aB/tvRsY5nGrZfC4mrr5wOLDaKhOCn7noCam9+u8DQi12uAWmRmJI/SK1W1wrgf5F2eB tj/JqkBM76n+SEu7cSAKuyLP/RNAGNOENCEGbJgkiEM8FFhfJqgYGNrs7dLWgfW3JHm2 2UtkaxP5blbzAuDkGN7QYPnrq2NeZdwbvR82hZcueH2ARjL64kp9/NkXVSNzOGTVmfVG oGb4iN1Uszq10VhoNyPYnnpGT+twVkFlha/I9P/e0rAd0zEE6gO8FNpFqbC7Gj1NfUth LsAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708411492; x=1709016292; 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=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=FkBMzDZuc9rR1R5EehNbi5c87JPGVlY3bcr561H1NHdOT2hlRRZXJWLsm37Y0tLJPE UZ6St8dbY6DSjy+B18I/YGuu0ZdHdZtZvgR5C/QxyJUJLuc4Zqar7UqhzTxJ1ZX+/mfe YTAjY8qnQMPm6MXEZ8IXK7wsMBlBaX7PbWYmCWvr3Zoz7kO1qMnEnpbDmQvubw+6Y+eO 2gYebL9Nv0o7J71tGe9hA5DhmdLDEiszacY/XNry8HTuNiBe+htCWhi/wcwXRbnp96tV +M3Fsdp//dJs4pYFfkjAvTrgNDG9uoMUvWgysuRSVqvC5K0ZG7CVBvJe5j7KPNLW3SSf tPDA== X-Forwarded-Encrypted: i=1; AJvYcCUa6FU65KbssEChonVDcEIPDVK37OWkGpKEajsxUwKQgScD1dhr9P+gTQuK4Qya8jtpLjeNZ8CIR3lHkFQliKRVo+0= X-Gm-Message-State: AOJu0Yya3h9vCMg/Yaj9derSd4vt3Mbq11fkAQ9SAjRbfFmiUa3dmD3w Eg82IsklcjNl3berWkhyh95VAQpF5syD9rIbqrG4QN3aPLE8MSUX X-Google-Smtp-Source: AGHT+IFy6i7+4k/jye/gmwuX1sSdiY9dP1qorrai79dHWwgMgxT8+F/EE4GSmEybEa4pgheMKtFkLg== X-Received: by 2002:a17:90b:4a08:b0:299:951f:e7de with SMTP id kk8-20020a17090b4a0800b00299951fe7demr4537779pjb.14.1708411492102; Mon, 19 Feb 2024 22:44:52 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a5bd:9c11:af2b:aecf]) by smtp.gmail.com with ESMTPSA id w16-20020a1709029a9000b001db60446abdsm5419090plp.262.2024.02.19.22.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:44:51 -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 v5 3/3] crypto: scompress: remove memcpy if sg_nents is 1 Date: Tue, 20 Feb 2024 19:44:14 +1300 Message-Id: <20240220064414.262582-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220064414.262582-1-21cnbao@gmail.com> References: <20240220064414.262582-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: tahyj69cujmphzsdqfrpxquqisdem5ke X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4C3C214000C X-HE-Tag: 1708411493-104503 X-HE-Meta: U2FsdGVkX18P4IcH7S448IHbvZ3syGcf60vtKEsxNvZzlOtp4uiA27jAu+gvxu0kuG8azdBS3S1nBwTBggOUOyzVVQWYFxpQRv/qVkG1cAT9cDdgIJyswwTdMJfLGSNke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Ok5m8AU+3pe1EkLQu8/pEJtt4wjubZ5uNCN5qg/g+3s666tweNoczzdMQhlAyCHq9zjukPCW+jO8sb5fjdI4Ki7roNesYh2XzV0blfUQpYe1sv83uvH3s/0q71Gd4NifTIV0FHq8twtoOIRIRkWD3vzlifQWhkH/CpoCPJt6cFof0hAT4fhuAQ2RG+7dvB74ScxAThvBQx0n8bqnCmfrcdcmGZ7bnEJCsM2bxOYdILTi3g8aU5mNdCABmOSkM/4sWgE7wOq52Ds0hssMmmM++XG2rhB55VCnQTQj7DlIAxWjcUKZq97hIEVLnO+BIgtZ4p5vgSYDNIVhxUKZesx78je5QB4QVl44Ob7SpjRzJoEMoKZLitf1XU2vbtPSkFhK6JFxU/IE3Yscn9qSNLCrr+uqfbhjvWBCj8HQAnq/u220bbdK7ARmN4fkk7o87df6yb 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 while sg_nents is 1 which is always true for the current kernel as the only user - zswap is the case, we should remove two big memcpy. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/scompress.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/crypto/scompress.c b/crypto/scompress.c index b108a30a7600..50a487eac792 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -117,6 +117,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) struct crypto_scomp *scomp = *tfm_ctx; void **ctx = acomp_request_ctx(req); struct scomp_scratch *scratch; + void *src, *dst; unsigned int dlen; int ret; @@ -134,13 +135,25 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) scratch = raw_cpu_ptr(&scomp_scratch); spin_lock(&scratch->lock); - scatterwalk_map_and_copy(scratch->src, req->src, 0, req->slen, 0); + if (sg_nents(req->src) == 1) { + src = kmap_local_page(sg_page(req->src)) + req->src->offset; + } else { + scatterwalk_map_and_copy(scratch->src, req->src, 0, + req->slen, 0); + src = scratch->src; + } + + if (req->dst && sg_nents(req->dst) == 1) + dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset; + else + dst = scratch->dst; + if (dir) - ret = crypto_scomp_compress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_compress(scomp, src, req->slen, + dst, &req->dlen, *ctx); else - ret = crypto_scomp_decompress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_decompress(scomp, src, req->slen, + dst, &req->dlen, *ctx); if (!ret) { if (!req->dst) { req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); @@ -152,10 +165,19 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) ret = -ENOSPC; goto out; } - scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, - 1); + if (dst == scratch->dst) { + scatterwalk_map_and_copy(scratch->dst, req->dst, 0, + req->dlen, 1); + } else { + flush_dcache_page(sg_page(req->dst)); + } } out: + if (src != scratch->src) + kunmap_local(src); + if (dst != scratch->dst) + kunmap_local(dst); + spin_unlock(&scratch->lock); return ret; }