Received: by 10.223.164.202 with SMTP id h10csp553127wrb; Tue, 7 Nov 2017 10:27:30 -0800 (PST) X-Google-Smtp-Source: ABhQp+S/0HV5mdyvnQzukx2WJnbT/a/LfGYp6P8N1J7St0Bsg5y2eC1EIyEsZUy2PakqcOFW4qdy X-Received: by 10.99.121.130 with SMTP id u124mr19956511pgc.124.1510079250525; Tue, 07 Nov 2017 10:27:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510079250; cv=none; d=google.com; s=arc-20160816; b=fOUntMM9wbwFTltGMVRdUC4D8TLxHjLkL2ioSHg7MCdOSC77GY7TRTXaPEaEZ785sN OrA8t++cvWyy5dGP7Pdv4exM03rEhJdCWfoTqpG4Y7JPrUkKgUz2IhPJRstCPzBA3hnu //I+T9mU9Gj9QYL5c9qOMj7zRKI/M+oNyZB0pduvwvXzxEbs67G6aq3AOsk51JUSlsuf S/eMR5KJHw36yjzzbnD8prLpJ/pAzuZCkEfXZ2pmwVzCzfBSdXvjg7+RuYmF645B7ywH sUd6eTykh7HTXuEhlL26DsGaF4mgkpLMnOLVlYN8L4M+MO1tExbilfCC3AVPqXHKTDPs vPCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=DxwvL26vgkA6tSlkr1B1BF/A/MY/SgmsfTLhOgbKmRw=; b=XIEJ7J9rBqPtnoVIBCApM7wFPU+QuEq+KbJn//437fXDDQ5JWvZC9aFPkA3lraUXoz iIzbWgYqQ4PRGqio37xNxdjBk1mrbhMpxLb1BzjzePQAo/jCc39Q+4u4b2snF3J4Uy7w CHCcLdKQT04jm0SYWkd8RCqMUtgSCyO7xj2QYVNU4uq4KkKdSL4eZwlTMyvjEgNdjzW6 Nw7Fv61pixdRzmGgTf+0ZxoWGhLHovIR90x9QmPwHJYVah4eDSJn8R9u2Pr47eIzbwNV 6uKNfSvFkUK+7wd6sha/Y4rG/hh6179UGdzDU/3yh5bmPbfD0jUjAiMsaF83erU1W/ui DIbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vSLxGa6p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f126si1939621pfg.410.2017.11.07.10.27.17; Tue, 07 Nov 2017 10:27:30 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=vSLxGa6p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933818AbdKGJwM (ORCPT + 91 others); Tue, 7 Nov 2017 04:52:12 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:47375 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933753AbdKGJwI (ORCPT ); Tue, 7 Nov 2017 04:52:08 -0500 Received: by mail-lf0-f65.google.com with SMTP id k40so13728432lfi.4; Tue, 07 Nov 2017 01:52:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DxwvL26vgkA6tSlkr1B1BF/A/MY/SgmsfTLhOgbKmRw=; b=vSLxGa6pfslBXOjbVy7vflQbVfPQBMy/wD5/3bma7bCvJx7vfp/gmjHmFmR/iAHJRz okOENxeKVe+Gvfn+SzVSGNYlBFBExMZCmrax/f1T6qQ5sXXm0hVplULNl8Ya0aZ4km7/ CcqYPOtCeJ+28SicDuNh0aErJEAlyX2AnVMiYo33OheFR8EvOyuzcC1nUqOYUiUAAk1w gD0d3OAWNJ9r5iMxaOj3zpYOEsv3vaaCxA4jMF+TlmQWt95eO9E1oqEWcxhM1drmrwCy cz7U5lcGv4+BIG8YM4S2yHA3ndiLVIVR8zdFTSOw/qAtjjDTD78eiKWwqRelhX8A0AR2 Sfzg== 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; bh=DxwvL26vgkA6tSlkr1B1BF/A/MY/SgmsfTLhOgbKmRw=; b=O+s3+2jXY2x7iI/NMFmedNJXSqiui5uaR8IRajsT58r2fyMNguuURFLx9Bhulfp/bv uPnE8EphR6vnv+24b139zFpFvrAmXO4sn9IwVVzKcalACp4Bg3DNVYGfpISuRKJD9jww SBlGUNnN7csEthQUuyfTIa35DnRMnFS13YmEbBDqGqbXW0ubm6VMAcDprEOtGBc+SetA W5GGsAUe86UYmq1LgkbM3ZsYDbluksmXIJFFP5HnvIstqGQ0DzpfcqryfBoC/DaEFFT7 /UWMOD1j7Kpvi64hxBOvYxxVqRQBSxyiCW2rZW0qWAoPDHq8MKcHQD3UgSn6WTeB54qE 88sA== X-Gm-Message-State: AMCzsaXc90sAzeGoKSw8X27Ta9xySNarmd2VZPKe3sbE6QdJ0sXfxcIz GNOqqbJIfTrC5bxaOwDn2ihYtQ== X-Received: by 10.46.83.20 with SMTP id h20mr7789793ljb.144.1510048326556; Tue, 07 Nov 2017 01:52:06 -0800 (PST) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id h82sm144771lfb.21.2017.11.07.01.52.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2017 01:52:05 -0800 (PST) Date: Tue, 7 Nov 2017 12:52:03 +0300 From: Vladimir Davydov To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 3/3] mm: memcontrol: fix excessive complexity in memory.stat reporting Message-ID: <20171107095203.wmxs4z2qpms27t5b@esperanza> References: <20171103153336.24044-1-hannes@cmpxchg.org> <20171103153336.24044-3-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171103153336.24044-3-hannes@cmpxchg.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 03, 2017 at 11:33:36AM -0400, Johannes Weiner wrote: > We've seen memory.stat reads in top-level cgroups take up to fourteen > seconds during a userspace bug that created tens of thousands of ghost > cgroups pinned by lingering page cache. > > Even with a more reasonable number of cgroups, aggregating memory.stat > is unnecessarily heavy. The complexity is this: > > nr_cgroups * nr_stat_items * nr_possible_cpus > > where the stat items are ~70 at this point. With 128 cgroups and 128 > CPUs - decent, not enormous setups - reading the top-level memory.stat > has to aggregate over a million per-cpu counters. This doesn't scale. > > Instead of spreading the source of truth across all CPUs, use the > per-cpu counters merely to batch updates to shared atomic counters. > > This is the same as the per-cpu stocks we use for charging memory to > the shared atomic page_counters, and also the way the global vmstat > counters are implemented. > > Vmstat has elaborate spilling thresholds that depend on the number of > CPUs, amount of memory, and memory pressure - carefully balancing the > cost of counter updates with the amount of per-cpu error. That's > because the vmstat counters are system-wide, but also used for > decisions inside the kernel (e.g. NR_FREE_PAGES in the > allocator). Neither is true for the memory controller. > > Use the same static batch size we already use for page_counter updates > during charging. The per-cpu error in the stats will be 128k, which is > an acceptable ratio of cores to memory accounting granularity. > > Signed-off-by: Johannes Weiner > --- > include/linux/memcontrol.h | 96 +++++++++++++++++++++++++++--------------- > mm/memcontrol.c | 101 +++++++++++++++++++++++---------------------- > 2 files changed, 113 insertions(+), 84 deletions(-) Acked-by: Vladimir Davydov From 1583059644730153766@xxx Fri Nov 03 15:35:24 +0000 2017 X-GM-THRID: 1583059644730153766 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread