Received: by 10.213.65.68 with SMTP id h4csp729596imn; Tue, 27 Mar 2018 07:46:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELte0NlZNCUkmPEkwPERLj/kNpQIZvaYzSZMyBJbsHZG1lH0seE2mQGjGbi6gt5i5nv7Tb/G X-Received: by 10.99.173.7 with SMTP id g7mr16515135pgf.170.1522161972412; Tue, 27 Mar 2018 07:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522161972; cv=none; d=google.com; s=arc-20160816; b=V3K/FF74usdH4zaw9FnfEVFRru4BP6Bo42SsUd+sTAthcuuqGlc/PVM9gdIDucqy30 4uFzkmu7Q1iz6tdtS4Ns8rUV51/JFgbvfzNLWCLwv1c9dNbJP/fKFZMEfPBTPFLXYI9b TO0eELBM4jq0qSY8vgRA7qUXQbNmDGauqQ6J4LqnH96QCHN6152jvr995rSka84j6LfM D/UdvHFAJVEiVilJ71nv2hDD8/0iCa1zHC4FfsNO4p9LVx5SJO9eCyoGn8sReMcVBaSb aFe7gzBgReVG+FTqyHPBNTYyRQ3qLsOh66Mx/MDjiy3yyyvxn1Y3PwUBy10WOmUXn8+J 0bBw== 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=8bfCX5P/s/P0uTjTWDqlze7lMSuh5dTJHMYKbinIWM8=; b=z4c8KTM3X2DxYZXtOS4hqPvtG1xIACb7CamjNW+gcvDyBqwu2swAtVqwh0/l3KLGHI rqeNYsZRcg4u9ltVaXVbSeYImsrFNlY/dcuQHf0a9FtYwaWQ+7eVyrTfkVJxGyteSdaI 4H7oJj6j9k4eTNAIkn1YGBpE+I/eb/nJ3SBB1W5b2nOY6xDsngmisgZyG/vircww68TN Zj312pxWw34lkQJtx4fSkL6gKcgSIroH2CNDrOI5Epo5WR5dBfquk+lis2nW3dZGkb9p be182bIXzBfQefxTE7sD9S+EkbCpGhfMqfUbZXAriIQjlLQixCtTO+XLmERN6I9qAEnc vxIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=epegq+pv; 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 e1-v6si1325979pln.578.2018.03.27.07.45.57; Tue, 27 Mar 2018 07:46:12 -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=epegq+pv; 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 S1752077AbeC0Oo4 (ORCPT + 99 others); Tue, 27 Mar 2018 10:44:56 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:40461 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbeC0Ooy (ORCPT ); Tue, 27 Mar 2018 10:44:54 -0400 Received: by mail-wm0-f66.google.com with SMTP id x4so9902236wmh.5 for ; Tue, 27 Mar 2018 07:44:53 -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=8bfCX5P/s/P0uTjTWDqlze7lMSuh5dTJHMYKbinIWM8=; b=epegq+pvtiojZGbjYMLoywS/kzD54B/hbldeT147ufLKqIbdQS1uRqY/MkWIiljHDp bSnIKZwJLuqx28C+PFGy86tvt/k7ByEaeK6+aNc5aAYjB+F6rSU9GqN+OuX3qYDimR4w 3o2HS+ZXF6cstN58OHGvR8/uMSxHoRmElO/SekxvrTjLETZlES6F8CEh/X82nSkAG4UJ 0i1ql8C4jczdjuKxuYi5QszC7nlXUkeheP15nScy3P5hv6qlvUo0wKNr5h/Beykvpw3j kP3q3ETpFXbQROnipk86HZoiVVom75e1niG+andiy3f724ZGZP8+blQzphmATOvddklv XfjA== 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=8bfCX5P/s/P0uTjTWDqlze7lMSuh5dTJHMYKbinIWM8=; b=a8zgK+X1HgfFTiGfcxtD7OjxbCZZnDpH/umG80lKkkDMBZ/XKHaG0s5soVyeo1QoNv xGSj439au6lxFlk9JfBzdgk+tLT/y7sMzcXp6AZ8cLSAfqvAO6bZoZ/ZXjuEhKUTcoMF PWdFMfXMJKtQCrZcaokh1i9E+y/5sBRoIxXBb2++TB/XOzAzfTd/dQ+wNEdOe9TktXQy dImeslc1g5eO/8DliN0YdIa0hQXDt7K3acx+BpUEwamTa1eCmFR1Kv5syNqYitZQEfa2 Wdx2lOr2/Yu4Co81dVRtb1012QDuAOJiuwKdSfYWbh10H+BH/pZANY5RVSDU9gEHN/7E H8Yw== X-Gm-Message-State: AElRT7EJpW7q2t/eLHHfZYKkDgGBiAz8j7pcl1UfPUbm8OdKojygzqJb tNoHv6K7XtTDY0AeIVemxuGhHQ== X-Received: by 10.80.178.5 with SMTP id o5mr43379735edd.142.1522161893207; Tue, 27 Mar 2018 07:44:53 -0700 (PDT) Received: from node.shutemov.name (mm-57-194-122-178.brest.dynamic.pppoe.byfly.by. [178.122.194.57]) by smtp.gmail.com with ESMTPSA id a7sm978371edl.11.2018.03.27.07.44.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 07:44:51 -0700 (PDT) Received: by node.shutemov.name (Postfix, from userid 1000) id C9740648D520; Tue, 27 Mar 2018 17:44:17 +0300 (+03) Date: Tue, 27 Mar 2018 17:44:17 +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: <20180327144417.szgqjpa6wqzluppc@node.shutemov.name> References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> <20180305162610.37510-20-kirill.shutemov@linux.intel.com> <20180320125046.zcefctri5rzronau@node.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180320125046.zcefctri5rzronau@node.shutemov.name> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 20, 2018 at 03:50:46PM +0300, Kirill A. Shutemov wrote: > 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. Okay, I've rework the patchset (will post later) to store KeyID per-page in page_ext->flags. The KeyID is preserved for freed pages and we can avoid cache flushing if the new KeyID we want to use for the page matches the previous one. With the change microbenchmark I used before is useless as it will keep allocating the same page avoiding cache flushes all the time. On macrobenchmark (kernel build) we still see slow down, but it's ~3.6% instead of 16%. It's more acceptable. I guess we can do better than this and I will look more into performance once whole stack will be functional. Performance counter stats for 'sh -c make -j100 -B -k >/dev/null' (5 runs): 7045275.657792 task-clock (msec) # 34.007 CPUs utilized ( +- 0.02% ) 1,122,659 context-switches # 0.159 K/sec ( +- 0.50% ) 197,678 cpu-migrations # 0.028 K/sec ( +- 0.50% ) 104,958,956 page-faults # 0.015 M/sec ( +- 0.01% ) 21,003,977,611,574 cycles # 2.981 GHz ( +- 0.02% ) 16,057,772,099,500 stalled-cycles-frontend # 76.45% frontend cycles idle ( +- 0.02% ) 11,563,935,077,599 instructions # 0.55 insn per cycle # 1.39 stalled cycles per insn ( +- 0.00% ) 2,492,841,089,612 branches # 353.832 M/sec ( +- 0.00% ) 94,613,299,643 branch-misses # 3.80% of all branches ( +- 0.02% ) 207.171360888 seconds time elapsed ( +- 0.07% ) -- Kirill A. Shutemov