Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3243237ybz; Sun, 19 Apr 2020 21:50:42 -0700 (PDT) X-Google-Smtp-Source: APiQypIhL6O13qYloIORuYRxEPWzY1XiymGjXfUiDjKZ6Zd07u05XMy4GF4A8lDNNZAGvOrpuvCl X-Received: by 2002:a17:907:b11:: with SMTP id h17mr15029773ejl.371.1587358242159; Sun, 19 Apr 2020 21:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587358242; cv=none; d=google.com; s=arc-20160816; b=v/EbFaFk+GXzP4OAr4L/2hKHIdq14xpZchpPu3O/VroJ92N2ojovotvN0anK7ApY3K AUqwrtmoRR+HWBuzFe/coyetXFWqy7aTFru23TUrUR9kMZyknCi8WJyRwEa5BBCXO1of CROIMd9sInDIhoLJioPeXNSH9wYG5FGrU3/3i4nd9zwhT67YbLSub5J9lKbLWVspmoM1 1s4dJ93Sdf6sICgvoNH5NQcE7T70gNIaBLFRO/qmKTpszqI2g4gRWW7xMEpNWl0meSfk vsdIO6yPXBStkxQDVhesKi3M6CBifajF2KPfZjYiiidnmUYYPMciHQ8eTzOdal1pHLl7 rV7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bYADXM3fnqTfOLHn4Df6MYywErUdtpTsT63FwdWOqRk=; b=1HrkdVLarX8QVomosSTnFFA1ITMbqD9NgOQsGfvPBrYQTDKJSnt9b8t68KwDXHZac2 FX611Zarc8FKIf4hWdBYajwdma9KvM7ogTLvLSdp2jiGQi3LNlvVv0ZNQOJyV/Uagg2q qEb4DmTuVWh6zqdQZLzeRSoTcoctw+ofwuKLRYxo//0p3oV7vorxnLTt7nwX7o3ex7h8 ABZnNbjPDC51kOLQGIdlQac6yoEKYpeyedHaHVkISwKMH4TnuOFBk8k6YfL0pwQgamF1 T0EeLPzuAnNzrTQ9TYUI2XBHTBHdqvEQYHApTHwN6q9FVs6TERU4raoWRc5+5B14fRBw 0RQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=nISDxD3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo10si1096247edb.19.2020.04.19.21.50.18; Sun, 19 Apr 2020 21:50:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=nISDxD3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725971AbgDTEtS (ORCPT + 99 others); Mon, 20 Apr 2020 00:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbgDTEtR (ORCPT ); Mon, 20 Apr 2020 00:49:17 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BEFDC061A0C for ; Sun, 19 Apr 2020 21:49:17 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id pg17so6816118ejb.9 for ; Sun, 19 Apr 2020 21:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bYADXM3fnqTfOLHn4Df6MYywErUdtpTsT63FwdWOqRk=; b=nISDxD3HO2jVVJbdvMhiaYcZtVzlGcweDRXzQY92JFIkrrQ7r/xRLigEEOLCujOL+I hG9XJbHC8L03WDMy90kKhhG5++FUfqGBeDWN7uGC4p9/ldHu9J3u74miQSCAfK7qWa0n lbNvMbMpMN2lq9MDNLSr0dyqgCTQfNdzI1B5p6kZ1JGEJ3PJPohL17GTbeNDIqR+o/ah /D1uxeYF+nsnbnA8wvGfsrhW0RriE5UuKNuexQ5IGSb6uwKoyeE3qodhdhtsHkfS91r/ d8gjqFSrkUeBH5BoicjM4RpME5ipKP9pXu6Lg9CsEtnsRcHbRGDowZN1WeYx7YLu9zwz LQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bYADXM3fnqTfOLHn4Df6MYywErUdtpTsT63FwdWOqRk=; b=AorFdyhPmWYfft10jTCCEnjwnz6EmKE1mErm26Wk0m7nJpxC5j3ORpw89kOx8NVUxl aaHErcSq+Hw1GOLCbpAqtK0ugZFRnKqQa6zvtfOsRjHLT2NLqRkzs+HH5c6OfGXKeqyR 9bxJMkO5kykbT99H8Dx+W/ru1FoSTZdex8yo6VKqEfzLM/daW3iwOLOdVbFC2KzL24o6 EGPY8U9ItIAsqpdchVW7TKIiIAWa/FjInxVOAqEm7b26tEzjwZnuVmRt+YzQcF/E1nw3 9tvH/k2ApITZdBBji0gJ2mtZvh2+6D0ZDKgLaWiier+1WwmjWo/0/Oqz5HBGCBiZM76A 5WCw== X-Gm-Message-State: AGi0PuZh9FZopxuOp2r9yCph84C/fsW7tsSAAr11p1RhEs5e+8uASl1n SKPyQJw/J1FCXpCzgLXaq6ct29YwqY9jMmFVXzL9LA== X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr14356816ejw.211.1587358155985; Sun, 19 Apr 2020 21:49:15 -0700 (PDT) MIME-Version: 1.0 References: <69c2e011c5814255926f309dd50e6d67@AcuMS.aculab.com> <8452b36a07b1440a8da6d4a1623858c1@AcuMS.aculab.com> In-Reply-To: <8452b36a07b1440a8da6d4a1623858c1@AcuMS.aculab.com> From: Dan Williams Date: Sun, 19 Apr 2020 21:49:05 -0700 Message-ID: Subject: Re: [PATCH] x86: introduce memcpy_flushcache_clflushopt To: David Laight Cc: Mikulas Patocka , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Peter Zijlstra , X86 ML , Linux Kernel Mailing List , device-mapper development 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 On Sun, Apr 19, 2020 at 10:49 AM David Laight wrote: > > From: Mikulas Patocka > > Sent: 18 April 2020 16:21 > > > > On Sat, 18 Apr 2020, David Laight wrote: > > > > > From: Mikulas Patocka > > > > Sent: 17 April 2020 13:47 > > > ... > > > > Index: linux-2.6/drivers/md/dm-writecache.c > > > > =================================================================== > > > > --- linux-2.6.orig/drivers/md/dm-writecache.c 2020-04-17 14:06:35.139999000 +0200 > > > > +++ linux-2.6/drivers/md/dm-writecache.c 2020-04-17 14:06:35.129999000 +0200 > > > > @@ -1166,7 +1166,10 @@ static void bio_copy_block(struct dm_wri > > > > } > > > > } else { > > > > flush_dcache_page(bio_page(bio)); > > > > - memcpy_flushcache(data, buf, size); > > > > + if (likely(size > 512)) > > > > + memcpy_flushcache_clflushopt(data, buf, size); > > > > + else > > > > + memcpy_flushcache(data, buf, size); > > > > > > Hmmm... have you looked at how long clflush actually takes? > > > It isn't too bad if you just do a small number, but using it > > > to flush large buffers can be very slow. > > > > Yes, I have. It's here: > > http://people.redhat.com/~mpatocka/testcases/pmem/microbenchmarks/pmem.txt > > > > sequential write 8 + clflush - 0.3 GB/s on nvdimm > > sequential write 8 + clflushopt - 1.6 GB/s on nvdimm > > sequential write-nt 8 bytes - 1.3 GB/s on nvdimm > > That table doesn't give enough information to be useful. > The cpu speed, memory speed and transfer lengths are all relevant. > > > > I've an Ivy bridge system where the X-server process requests the > > > frame buffer be flushed out every 10 seconds (no idea why). > > > With my 2560x1440 monitor this takes over 3ms. > > > > > > This really needs a cond_resched() every few clflush instructions. > > > > > > David > > > > AFAIK Ivy Bridge doesn't have clflushopt, it only has clflush. clflush > > only allows one outstanding cacle line flush, so it's very slow. > > clflushopt and clwb relaxed this restriction and there can be multiple > > cache-invalidation requests in flight until the user serializes it with > > the sfence instruction. > > It isn't that simple. > While clflush on Ivybridge is slower than clflushopt on newer processors > both instructions are (relatively) fast for something like 16 or 32 > iterations. After that they get much slower. > I can't remember where I found the relevant figures, even the ones I > found didn't show how large the transfers needed to be before the bytes/sec > became constant. > > > The patch checks for clflushopt with > > "static_cpu_has(X86_FEATURE_CLFLUSHOPT)" and if it is not present, it > > falls back to non-temporal stores. > > Ok, I was expecting you'd be falling back to clflush first. clflush is a serializing instruction, clflushopt and non-temporal stores are not.