Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1108825imm; Wed, 1 Aug 2018 10:19:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfN1KhlRbSlCsL8BB7zEeoaJnvdOiqMRNVaP5G5+Cg/CDaqHq7LjNV0SSp2OWhzTfFIN5tp X-Received: by 2002:a17:902:5a4c:: with SMTP id f12-v6mr25588452plm.253.1533143954093; Wed, 01 Aug 2018 10:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533143954; cv=none; d=google.com; s=arc-20160816; b=1JKFmzI30YA7s6CMVnvSoyAqW650JwyZrNpWH4/4gj46fC8S2/4cMi+/cR5fhigGQY eN0kR8ZxxDJxsIZBpc6XsfU4vJNey6q6jfPCcmG1qnovCrCk71kdSLI5B3OMM8ZgwA9X rijlNRjlaVh4RBMfafz6QO4EU0VeRYJ93usgdPDDgT5uANhztEuQOPifrYJlvYXdkC1g WVJB05a91MNGbTpuKztXO1fzB3bxVxDQ7Iasj/n5MDT92Q20+ZEF3syQqdfeIiyDt+9L DqF0oyoM+OrsAdv8hQm/6205/wdIxeateFv0YvRBjLDeGgkw4psGQsChgUTP6gdg2tMP W8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=EFZUoe5pEtTv6Wkbsp9qcXbP4U+1lZmO9U/UNvwpXS8=; b=KabEZO95msZzsU0ieuDYchV/WGe/kZObZWfOxozg+srxX+8Lc9JcNW4hkMELZHBdhW 1oM96pJiS9t0BSR+OQN5Iu3QuC1Cvelx/8WjeUQ8mA7znWP1jvu+UPwuETLEEL+TqxXt 64OaWI9DePawkNYgEj1rnAzS2jFY08S9g8pHRYh9gV95g40tAN7zmFoOX45Gb62qbejg 9Sl6iKq4OKOqrz13d1xgo9ApLsDlvrHaFma9znJAwQWwtKEwLoaAGteOmHcs3MZkbl06 Th/Tl1mj27cURdG3hAKQwh5tP7CM+bXSSGQ+ZAe0iWE5dKKTLqjiZZBGAPseQCL4kL0e jG4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l67-v6si16713901pfl.167.2018.08.01.10.18.59; Wed, 01 Aug 2018 10:19:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404710AbeHATEO (ORCPT + 99 others); Wed, 1 Aug 2018 15:04:14 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46466 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404701AbeHATEN (ORCPT ); Wed, 1 Aug 2018 15:04:13 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DE67EC9E; Wed, 1 Aug 2018 17:17:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Theodore Tso , Sasha Levin Subject: [PATCH 4.14 116/246] fscrypt: use unbound workqueue for decryption Date: Wed, 1 Aug 2018 18:50:26 +0200 Message-Id: <20180801165017.256855363@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers [ Upstream commit 36dd26e0c8d42699eeba87431246c07c28075bae ] Improve fscrypt read performance by switching the decryption workqueue from bound to unbound. With the bound workqueue, when multiple bios completed on the same CPU, they were decrypted on that same CPU. But with the unbound queue, they are now decrypted in parallel on any CPU. Although fscrypt read performance can be tough to measure due to the many sources of variation, this change is most beneficial when decryption is slow, e.g. on CPUs without AES instructions. For example, I timed tarring up encrypted directories on f2fs. On x86 with AES-NI instructions disabled, the unbound workqueue improved performance by about 25-35%, using 1 to NUM_CPUs jobs with 4 or 8 CPUs available. But with AES-NI enabled, performance was unchanged to within ~2%. I also did the same test on a quad-core ARM CPU using xts-speck128-neon encryption. There performance was usually about 10% better with the unbound workqueue, bringing it closer to the unencrypted speed. The unbound workqueue may be worse in some cases due to worse locality, but I think it's still the better default. dm-crypt uses an unbound workqueue by default too, so this change makes fscrypt match. Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/crypto/crypto.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -446,8 +446,17 @@ fail: */ static int __init fscrypt_init(void) { + /* + * Use an unbound workqueue to allow bios to be decrypted in parallel + * even when they happen to complete on the same CPU. This sacrifices + * locality, but it's worthwhile since decryption is CPU-intensive. + * + * Also use a high-priority workqueue to prioritize decryption work, + * which blocks reads from completing, over regular application tasks. + */ fscrypt_read_workqueue = alloc_workqueue("fscrypt_read_queue", - WQ_HIGHPRI, 0); + WQ_UNBOUND | WQ_HIGHPRI, + num_online_cpus()); if (!fscrypt_read_workqueue) goto fail;