Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1424379imm; Thu, 6 Sep 2018 23:21:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZakdNo4bdfnJATS6p9l0fUzZvFsjXJKpt8FQ6S7KM59s955VG9sTs5mMFrR8EZ+92ugvR/ X-Received: by 2002:a17:902:7488:: with SMTP id h8-v6mr6398175pll.16.1536301313545; Thu, 06 Sep 2018 23:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536301313; cv=none; d=google.com; s=arc-20160816; b=vxTnW1jHbITCix02HizY2gIUHUeQ3ltnWeIBXN+Ycy8PkJUC27XxwgOHuumsspOP6G bA23G6Dw2boA+X6SnN6EZMqYG4Gk5klE4BZTuPo3/ktNNJvkAkXtsNBQIMXpalBfXauw 3/Q58Z+1eY/osx7mCUj4ZLo4C/UYkGz7+VVVWw/NK7AJcqo+ej2O17+FzJ9QNFbBGa4H WJVFs/814YQutFmFcA33zoJ0v8f1YQ08l7A92cw6GmXMFmCfmWR8v9OQXjoLq6zs9H3k LraBasVk5AKMiXiyVzNEsQh3X0uU1rHWt11JoqAIA+ze2VrGO59v6JBeqg9EWRF6XuCM UT2g== 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 :references:in-reply-to:mime-version:dkim-signature; bh=jYByNgF3zqi2EFRNT1ofdcx5HbePs2BpzvOyEMD6zPg=; b=Hv+I3W47YU/hJwReEBGymEVkGCa1/XGyOMYFKm3w4GEPP8LBg/9sp6KWHVZBwq7doE yb6ff60s/8Rx+vScdoKvHxJeZI6kGmZcZ7GhkWAI3shOLdmJekKoUQKTBq3suDdfz+Ca M4oY2k76k+9PHmavLi0VMO/lfdRbcphQks0n4pztcK9D+n5tHDLpaW2qdWtUki8ApHRj y9jyAXQXHnB/deISvf5t3ZK4RRvv3DgVqZMhnrdFJNSQnamBppotjU066XDjObLAoaE6 CO5r8ebMd4yMaQYYOm00G5Iwu7GA+VAu/ZzvzjNg34zOIaT7qDPT5nW4jIDZJqFxTICy Zppw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lixom-net.20150623.gappssmtp.com header.s=20150623 header.b=AicLtXEJ; 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 m2-v6si7324242pfi.351.2018.09.06.23.21.35; Thu, 06 Sep 2018 23:21:53 -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=@lixom-net.20150623.gappssmtp.com header.s=20150623 header.b=AicLtXEJ; 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 S1726717AbeIGK7k (ORCPT + 99 others); Fri, 7 Sep 2018 06:59:40 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41211 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbeIGK7k (ORCPT ); Fri, 7 Sep 2018 06:59:40 -0400 Received: by mail-lj1-f194.google.com with SMTP id y17-v6so11317420ljy.8 for ; Thu, 06 Sep 2018 23:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lixom-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jYByNgF3zqi2EFRNT1ofdcx5HbePs2BpzvOyEMD6zPg=; b=AicLtXEJUQ4DyRUnciKQ7JRQi0osTqS53cY/iwRRpU8KK17kHxZHsDbGmSBEAQ8sj1 rvZH7jVhidg5JikWude/dzZk/kL/eHGr3i/MkklnaEZJfR6hgYbfFWxsoJjqmjGqqyBb nTENR5nzjkWYuX3+YPcNH+xOFrYaS4Tny5LQA43NsmmFVBYevcyhb3TLIcpSymaPM3Hu buGa7tuk+PUuI02qivwpsmClBKA7Imycm+w+PhkGBauOmpaclCWhlLKehPWP5Tqcuv+0 QDatIVfvAkatxvvONGB2u8Ym7St1sv+IoJAxOW9puoJbhtUJ5j1KZnTT+xIzII4Tu9gB tEDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jYByNgF3zqi2EFRNT1ofdcx5HbePs2BpzvOyEMD6zPg=; b=tmMo1vPI+KE2nkbv3AHyWTz6qjYz5o6X15oOrsgQvohfG/CaFAQRow2WA1Pcdg6zJF 5RLF2/DhoXLzlt9faFchA/ImGHh26TA0ne/xpm1PeffTdXfPM8T5Go8T1Vy7+IHAKLgY GOXxcW8nu7OXltrB8FaaNkQ6VJLmKyoUFZ6tL/FJThdetXvCmVwnfQyYN07Myl9d75em 2Btep33WkGvdV+Fq23M5YnC6TGKdiqVdIOeloodS0fJtXzuzSES0XSazcQonk7PncmJJ Fx06KpohzFjVHrCyvZI7mMijM6wlZ058qmSGftowgOUFDF5QBIuhqfSq9yVYiYoI5yVi ooDA== X-Gm-Message-State: APzg51D263ZkFuHwWrXZNUnZN73CQfDjyBVgwp1Phpm5eSKyPuNNQFBf PC0q8WCASrG8Wga4xF2oqvjDxphzcyVFlFCVNWWCRg== X-Received: by 2002:a2e:8188:: with SMTP id e8-v6mr3739401ljg.138.1536301216923; Thu, 06 Sep 2018 23:20:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:d984:0:0:0:0:0 with HTTP; Thu, 6 Sep 2018 23:20:15 -0700 (PDT) X-Originating-IP: [2620:10d:c090:180::1:f544] In-Reply-To: <20180907033257.2nlgiqm2t4jiwhzc@gondor.apana.org.au> References: <20180906192034.8467-1-olof@lixom.net> <20180907033257.2nlgiqm2t4jiwhzc@gondor.apana.org.au> From: Olof Johansson Date: Thu, 6 Sep 2018 23:20:15 -0700 Message-ID: Subject: Re: [PATCH] net/sock: move memory_allocated over to percpu_counter variables To: Herbert Xu Cc: Eric Dumazet , David Miller , Neil Horman , Marcelo Ricardo Leitner , Vladislav Yasevich , Alexey Kuznetsov , Hideaki YOSHIFUJI , linux-crypto@vger.kernel.org, LKML , linux-sctp@vger.kernel.org, netdev , linux-decnet-user@lists.sourceforge.net, kernel-team 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 Hi, On Thu, Sep 6, 2018 at 8:32 PM, Herbert Xu wrote: > On Thu, Sep 06, 2018 at 12:33:58PM -0700, Eric Dumazet wrote: >> On Thu, Sep 6, 2018 at 12:21 PM Olof Johansson wrote: >> > >> > Today these are all global shared variables per protocol, and in >> > particular tcp_memory_allocated can get hot on a system with >> > large number of CPUs and a substantial number of connections. >> > >> > Moving it over to a per-cpu variable makes it significantly cheaper, >> > and the added overhead when summing up the percpu copies is still smaller >> > than the cost of having a hot cacheline bouncing around. >> >> I am curious. We never noticed contention on this variable, at least for TCP. > > Yes these variables are heavily amortised so I'm surprised that > they would cause much contention. > >> Please share some numbers with us. > > Indeed. Certainly, just had to collect them again. This is on a dual xeon box, with ~150-200k TCP connections. I see about .7% CPU spent in __sk_mem_{reduce,raise}_allocated in the inlined atomic ops, most of those in reduce. Call path for reduce is practically all from tcp_write_timer on softirq: __sk_mem_reduce_allocated tcp_write_timer call_timer_fn run_timer_softirq __do_softirq irq_exit smp_apic_timer_interrupt apic_timer_interrupt cpuidle_enter_state With this patch, I see about .18+.11+.07 = .36% in percpu-related functions called from the same __sk_mem functions. Now, that's a halving of cycles samples on that specific setup. The real difference though, is on another platform where atomics are more expensive. There, this makes a significant difference. Unfortunately, I can't share specifics but I think this change stands on its own on the dual xeon setup as well, maybe with slightly less strong wording on just how hot the variable/line happens to be. -Olof