Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5467456ybi; Tue, 28 May 2019 13:38:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQPG8KdSHVsIon6JFvnq7k74IAPhSYU01P1fxeI+YrwJRmQxE90/Cs+PW2WhGThcElmuQ2 X-Received: by 2002:a63:e408:: with SMTP id a8mr47867932pgi.146.1559075934223; Tue, 28 May 2019 13:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559075934; cv=none; d=google.com; s=arc-20160816; b=GCzVAE2tWflQUMV3tZehFGRACfnrZbxaz6A9J3dgolfDYLGtWAJ64LoI10xfz8OqEu Z2H5hkwF5c/cn9RWTgo66L7NXH6kcpdeTlK3mq4N0116aHeeKqGvpr1+lZHvzoAaHORM yt7t0k5Gz4jsrYBGTjK62Vth924RwGi4LJPvs1wsHy8Ec4Au/2Jmd54ibBrEKJEb7pH/ 0GknDcX1Gg3yAtpB9wLRjfaefNZAlrCDzS7UuCEkT1PQRnCEb+hBjCRNdeMv/Gcl2ERt 9Ai5mEX958QMuhPWkY8ctSmI8tzp37yZ6s/i3p3i968roW4Nj716SqzB7cZMpXF1H7AH fojA== 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; bh=6BVjplRJjVAtzerMfL/A1WtErQukGLzsV7QIdL5tHLg=; b=sOw74FknVcpyFa0yHCdajtsw2Prb7DciulCli65jEQPwyatEbMnK0yPLzk36Rq0Uyi 9zc1/n/EW/1NKVJuyfNjK0aRixN7iEI1Weyacq5reey8OGxSvllFB9WM1wiqTAV/QqXd DICiz3A4A2Vp18R2eBJTWqXFwhNXrOK/+WqOqpi2jAvNrvDnlrBqKXjSScpE5Og/6vDj kVoeR5CusLpZqIyAtWZQNzWEITBzyS4RRxt4yxKuWvHo4oOsLSrbc6Ahe+Fe8S/Hxx9C 0z84VtbBrUcQIvAMlpQPfwE9yB/BalJuHjgRXCPPflT6SYQXkhxcvz8tNdWOFTQ9L7lE RNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=jALHoOYb; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si22748297pgd.557.2019.05.28.13.38.37; Tue, 28 May 2019 13:38:54 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=jALHoOYb; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727501AbfE1UcV (ORCPT + 99 others); Tue, 28 May 2019 16:32:21 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41743 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfE1UcV (ORCPT ); Tue, 28 May 2019 16:32:21 -0400 Received: by mail-pf1-f193.google.com with SMTP id q17so6157pfq.8 for ; Tue, 28 May 2019 13:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6BVjplRJjVAtzerMfL/A1WtErQukGLzsV7QIdL5tHLg=; b=jALHoOYbd78sWqXXZgYaR8eLxuPF63IYkarb8Baf2n7TaE6XnnepYOIMqCLibAQqG/ 0ZJcwCe35su/Un1bvTKr+H9yfbCkChIWYtLnHoLbFPQ+U51SOhGPOu4PDiNGWKDyuQHL 0/Bh3Wz253mmN/utA/8DiIGX5r6qBJPfGgk2oct7Uvpyn5Aq64Mj1G8+uxa7XdNfHW+L 8fhCvz7JKJm3Xx8NvpGLGFD4eU7BVn/g6ehW/Z+dcsnVXOV+p0CbvsIyL5hTi4cc4/M+ 4pbItZvCXZDDcetGaQGkGh6Bfg4tzcbzzSbFPSqysI8fYYPgfmUXhZy7tlj2NzsFGGpx tXyw== 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=6BVjplRJjVAtzerMfL/A1WtErQukGLzsV7QIdL5tHLg=; b=lqlNkLMBuNLBsaNgwUS7c1MC03+foKxyUZKpt8NJt7gkvnK+uaYxGBDQCMjrDSd4R2 d8B9QEnEI7xupQcyW6Itsk2rIaO04oQgltMv0YVXLrk4/xvyD7OS4u62Pp3Ty+lOBVul skPX+VofjKWAkqf+qzMqngrBsMY6DvGH1XwWKT7zFFOs+KK+ppas7Pt/dInqf5XovY/V 8dcC05gR5RVRWMCHT51vdQFcUz1Jn0hSE5Lf6P0TqitQZJExd4fvj6jlceC2utkHVRbf Y1O5x6FOVFqYXvT4p4aezL6tRAQVPQ8oZTIV9birVFL4l58FqpDpF0hHy7QAZgboFWho a7Xg== X-Gm-Message-State: APjAAAXalpEGWFWVDPc7ROZLjjDrkHUUAt/7SIXsQlWm521mCPn5LVC2 PNXml/pDAqE5t7sFKEmrxbim0Q== X-Received: by 2002:a63:4f07:: with SMTP id d7mr83629540pgb.77.1559075540928; Tue, 28 May 2019 13:32:20 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::1:6316]) by smtp.gmail.com with ESMTPSA id c15sm15664515pfi.172.2019.05.28.13.32.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:32:20 -0700 (PDT) Date: Tue, 28 May 2019 16:32:18 -0400 From: Johannes Weiner To: Linus Torvalds Cc: Shakeel Butt , Andrew Morton , kernel test robot , LKP , LKML , Michal Hocko , Roman Gushchin , Linux MM , Cgroups Subject: Re: [PATCH] mm: memcontrol: don't batch updates of local VM stats and events Message-ID: <20190528203218.GA20452@cmpxchg.org> References: <20190520063534.GB19312@shao2-debian> <20190520215328.GA1186@cmpxchg.org> <20190521134646.GE19312@shao2-debian> <20190521151647.GB2870@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 28, 2019 at 10:37:15AM -0700, Linus Torvalds wrote: > On Tue, May 28, 2019 at 9:00 AM Shakeel Butt wrote: > > > > I was suspecting the following for-loop+atomic-add for the regression. > > If I read the kernel test robot reports correctly, Johannes' fix patch > does fix the regression (well - mostly. The original reported > regression was 26%, and with Johannes' fix patch it was 3% - so still > a slight performance regression, but not nearly as bad). > > > Why the above atomic-add is the culprit? > > I think the problem with that one is that it's cross-cpu statistics, > so you end up with lots of cacheline bounces on the local counts when > you have lots of load. In this case, that's true for both of them. The workload runs at the root cgroup level, so per definition the local and the recursive counters at that level are identical and written to at the same rate. Adding the new counter obviously caused the regression, but they're contributing equally to the cost, and we could remove/per-cpuify either of them for the fix. So why did I unshare the old counter instead of the new one? Well, the old counter *used* to be unshared for the longest time, and was only made into a shared one to make recursive aggregation cheaper - before there was a dedicated recursive counter. But now that we have that recursive counter, there isn't much reason to keep the local counter shared and bounce it around on updates. Essentially, this fix-up is a revert of a983b5ebee57 ("mm: memcontrol: fix excessive complexity in memory.stat reporting") since the problem described in that patch is now solved from the other end. > But yes, the recursive updates still do show a small regression, > probably because there's still some overhead from the looping up in > the hierarchy. You still get *those* cacheline bounces, but now they > are limited to the upper hierarchies that only get updated at batch > time. Right, I reduce the *shared* data back to how it was before the patch, but it still adds a second (per-cpu) counter that needs to get bumped, and the loop adds a branch as well. But while I would expect that to show up in a case like will-it-scale, I'd be surprised if the remaining difference would be noticeable for real workloads that actually work with the memory they allocate.