Received: by 10.213.65.68 with SMTP id h4csp380999imn; Tue, 20 Mar 2018 05:52:25 -0700 (PDT) X-Google-Smtp-Source: AG47ELvRmRVsFw5tDQd2Sjs9KTr6StjL7fZimT3lM33sPpFJ+Hbjn1GzcOW3vmw1pRsApzChEc7f X-Received: by 10.99.171.11 with SMTP id p11mr9979561pgf.176.1521550345541; Tue, 20 Mar 2018 05:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521550345; cv=none; d=google.com; s=arc-20160816; b=kgTVDAV98Tjb/D/GMkg2Z0OoBvojK1vIM846tmrlTLxDHLYq4LDc1BG/4J33d99RIO c5ED5yN78Xf81A32nJT0S5mR2FIsFPfdVxbXFw9VT+h1UQH3/nw0R9X9pEm17rlDW0Dt y5+ICTlgXVTLeI3Y9fNHqIlt7zOZA6Kh+iWJVZoemF+A7FAwOey6flansBXstTXVakEa fheJqYmMLOKabit7rrL7Wz194rvSqfP1wsWBJDEO/Lgd/sBKc7TRIauW6M+W1mY14ep5 96Z4F7HhN4EXX2exzn2fMFkMEjt+QriqlX1tZJ12EGqJihftIzzdkaFyGDOR5NmN1k16 bz6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=6k1lSHK2a3IEUu/xP87LGQhLo0nRZPNOjfwZaIRKixw=; b=yLtoCRhUSUFh0s5xrCTOXqhwk8u2Tykn5viZFIMlrA2ikg97DmKeTkSZ+DoE6KEW+V G5xYOV7dnjsnjStt2v7Z1UG875SEJBew3kwn4U2pAHsrgINYaX8KEnH9k6g1YMlmAyIy n1/dkG/0OtP/Hm+Lz0kSZFPwYOt4fuZoKrqDbk2GPKJ599rcqstYbpf9tFAsbq7GHnUV wpCG15t83HVojmi0QZ6MxITCLGqm6kXn6nr7EGyztDwj5ZbfLMvWj3TAuSTs1vQp+hA5 Ktd0lPyWI9NAXbVaBp7a+/C3LyGq+b+k2TIKu6Z/CMcsqS6DSuKfx27X+nH+PEbfme/7 RAYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=PcgmJCjN; 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 1-v6si1593191plk.52.2018.03.20.05.52.11; Tue, 20 Mar 2018 05:52:25 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=PcgmJCjN; 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 S1753313AbeCTMvS (ORCPT + 99 others); Tue, 20 Mar 2018 08:51:18 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52593 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753170AbeCTMvQ (ORCPT ); Tue, 20 Mar 2018 08:51:16 -0400 Received: by mail-wm0-f65.google.com with SMTP id l9so3219597wmh.2 for ; Tue, 20 Mar 2018 05:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6k1lSHK2a3IEUu/xP87LGQhLo0nRZPNOjfwZaIRKixw=; b=PcgmJCjN765tuFCB8k6p7aa9US871gMoEKGMV01Efd1nVuy5BmofwMjXLEd4/TgDLl L8ljlQzUoApvcdoj0g/lDZY06vWhqRGrpkOqEEWWf5O9b85yHpBc2YOIBDhMcjuAoZVq L9o+Uar9sujnbrvohG9YqDm1VuMutRdGODCrBT4BbuN114HBBugbecOd03kDR4cfwMmX oSv0GCnQEn47ZKG+XClspMXGwGE5gKu4vtYt1pH5aSXOOD3e0aK6Rj8j+Y/q1Momw1Si uVFRr19NHb/QrJqW919NQ4JaqKBpGKFSlMkFmjTSWGzZVxdn0PiCYbpDzff9cbkbb/8p AJzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6k1lSHK2a3IEUu/xP87LGQhLo0nRZPNOjfwZaIRKixw=; b=PondYPhtNVJ5BAugmiLbh9Tt3Jlo2ZDe7yTXeTtcZtGkzya37mSmrIDKbHTaJxM4gx meogb9+hV7YqkHQcAasc+TCoOUmleXlwVEkH4h005tVfy8m4S2VNKEHaUhLWjpvCz3mr hGVb3HO0cWqMB9oMd1T9tvCHNxwyNCXOOCeMGL609QjSdXarzudKZUgmUD7ZG6O4Awjz 6MArE+7fQKfpdkB7ANskn6JEp46m3gFi7r5tOXU55slbjvxFvayxTOHJ3hOpZ1u5dc+M bAEPWAbVJ1n+6AaRjXF2SdldpoCdqFSmYNlKK0rgWvow6r8R55E3i4CRqTk9hG2uxtZ/ FMJg== X-Gm-Message-State: AElRT7ENJ9MKTMJEnIuZ4t4+8/z8FO+gVK1VxbZc8zD4usrqpUYjFrhO p6Jh5+POxno5ZJx1rhzREHPURg== X-Received: by 10.80.211.2 with SMTP id g2mr17223263edh.96.1521550275067; Tue, 20 Mar 2018 05:51:15 -0700 (PDT) Received: from node.shutemov.name ([93.84.73.24]) by smtp.gmail.com with ESMTPSA id l91sm1773563edl.4.2018.03.20.05.51.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Mar 2018 05:51:13 -0700 (PDT) Received: by node.shutemov.name (Postfix, from userid 1000) id 4A518648D520; Tue, 20 Mar 2018 15:50:46 +0300 (+03) Date: Tue, 20 Mar 2018 15:50:46 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC, PATCH 19/22] x86/mm: Implement free_encrypt_page() Message-ID: <20180320125046.zcefctri5rzronau@node.shutemov.name> References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> <20180305162610.37510-20-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 05, 2018 at 11:07:16AM -0800, Dave Hansen wrote: > On 03/05/2018 08:26 AM, Kirill A. Shutemov wrote: > > +void free_encrypt_page(struct page *page, int keyid, unsigned int order) > > +{ > > + int i; > > + void *v; > > + > > + for (i = 0; i < (1 << order); i++) { > > + v = kmap_atomic_keyid(page, keyid + i); > > + /* See comment in prep_encrypt_page() */ > > + clflush_cache_range(v, PAGE_SIZE); > > + kunmap_atomic(v); > > + } > > +} > > Have you measured how slow this is? Well, it's pretty bad. Tight loop of allocation/free a page (measured from within kernel) is 4-6 times slower: Encryption off Order-0, 10000000 iterations: 50496616 cycles Order-0, 10000000 iterations: 46900080 cycles Order-0, 10000000 iterations: 46873540 cycles Encryption on Order-0, 10000000 iterations: 222021882 cycles Order-0, 10000000 iterations: 222315381 cycles Order-0, 10000000 iterations: 222289110 cycles Encryption off Order-9, 100000 iterations: 46829632 cycles Order-9, 100000 iterations: 46919952 cycles Order-9, 100000 iterations: 37647873 cycles Encryption on Order-9, 100000 iterations: 222407715 cycles Order-9, 100000 iterations: 222111657 cycles Order-9, 100000 iterations: 222335352 cycles On macro benchmark it's not that dramatic, but still bad -- 16% down: Encryption off Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs): 6769369.623773 task-clock (msec) # 33.869 CPUs utilized ( +- 0.02% ) 1,086,729 context-switches # 0.161 K/sec ( +- 0.83% ) 193,153 cpu-migrations # 0.029 K/sec ( +- 0.72% ) 104,971,541 page-faults # 0.016 M/sec ( +- 0.01% ) 20,179,502,944,932 cycles # 2.981 GHz ( +- 0.02% ) 15,244,481,306,390 stalled-cycles-frontend # 75.54% frontend cycles idle ( +- 0.02% ) 11,548,852,154,412 instructions # 0.57 insn per cycle # 1.32 stalled cycles per insn ( +- 0.00% ) 2,488,836,449,779 branches # 367.661 M/sec ( +- 0.00% ) 94,445,965,563 branch-misses # 3.79% of all branches ( +- 0.01% ) 199.871815231 seconds time elapsed ( +- 0.17% ) Encryption on Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs): 8099514.432371 task-clock (msec) # 34.959 CPUs utilized ( +- 0.01% ) 1,169,589 context-switches # 0.144 K/sec ( +- 0.51% ) 198,008 cpu-migrations # 0.024 K/sec ( +- 0.77% ) 104,953,906 page-faults # 0.013 M/sec ( +- 0.01% ) 24,158,282,050,086 cycles # 2.983 GHz ( +- 0.01% ) 19,183,031,041,329 stalled-cycles-frontend # 79.41% frontend cycles idle ( +- 0.01% ) 11,600,772,560,767 instructions # 0.48 insn per cycle # 1.65 stalled cycles per insn ( +- 0.00% ) 2,501,453,131,164 branches # 308.840 M/sec ( +- 0.00% ) 94,566,437,048 branch-misses # 3.78% of all branches ( +- 0.01% ) 231.684539584 seconds time elapsed ( +- 0.15% ) I'll check what we can do here. -- Kirill A. Shutemov