Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp512608ybk; Wed, 20 May 2020 05:29:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxT7zpMZzCOgPmA8vgzv3iNBKLIYBz3tBcV0Va1Gu+fPwYNOhUxj90Xx2bPaTDVl3Idqhyk X-Received: by 2002:a17:906:9a1:: with SMTP id q1mr3328077eje.296.1589977760070; Wed, 20 May 2020 05:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589977760; cv=none; d=google.com; s=arc-20160816; b=yXydo9FFWXe6pGvhoyJx3SKg6BS3GCCK4Pm0P7dEXCfRZKnp1tvzyfZYwx71xrmwOI Racm7r9NYTBO5GDUAwQnC9whEeDLYtha1CFpvXcFKuFe6T2DpaizZaF6Xec0DeT9yEte 8hfRyt6vc43khhw8lgi3HKxHm/67/HhHzAfBHdb6Xm/pJEH4noQc8wOObBUEI089e5hA bzmPVQlzmcgwjhLoGzrUc40EcI1GpfICKgO4gaZnXqVEKk2LoCKwRg8B0pq1Li08M/gB FgcCtoapi4cvrbK/C1u9hQh3k4iWAK1UxAauxhAss2+zLSkEuG4zOFg61NzftgbX+GR1 tF6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=/YM98kndEZn1vw32xoF7T6SFICVlZewvV0t6LDH+94U=; b=E7e/8f8+nbzqXhuyiZz1EWKMYNOxS6RTwcPgQf9umVlZ+1TrBVtGXzAu9FaD+SivO3 YHb8VXTaG1hjb1XvvQPCswPXyeEFnoxBg2NUjOPegWX7NIWbnHntu5tSCYAs39R33p+U x4wzOvqwhkYAZTIZAOBTwhr6/lAokrSwcm9sgHLqw8bEAajyfLzJK7fQhZs+lyPCqzJF ZgkMYhwdgYf2EW9ug00nIaTmFLwWRooz/IbQlnDyxPZHriZA48EJyem44A7V/CtksDG+ nfjXQqAXyHk1aJ8NIS6gvPQeBbhfA0OIE+hF+JSs7dKnb3j/OlSC87oofUwm7Sa68ip0 kbPg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si1561482ejx.250.2020.05.20.05.28.54; Wed, 20 May 2020 05:29:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbgETMZ0 (ORCPT + 99 others); Wed, 20 May 2020 08:25:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:56438 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbgETMZZ (ORCPT ); Wed, 20 May 2020 08:25:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 66EF5AEA7; Wed, 20 May 2020 12:25:26 +0000 (UTC) Subject: Re: [PATCH v3 03/19] mm: memcg: convert vmstat slab counters to bytes To: Roman Gushchin , Andrew Morton Cc: Johannes Weiner , Michal Hocko , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org References: <20200422204708.2176080-1-guro@fb.com> <20200422204708.2176080-4-guro@fb.com> From: Vlastimil Babka Message-ID: Date: Wed, 20 May 2020 14:25:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200422204708.2176080-4-guro@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/22/20 10:46 PM, Roman Gushchin wrote: > In order to prepare for per-object slab memory accounting, convert > NR_SLAB_RECLAIMABLE and NR_SLAB_UNRECLAIMABLE vmstat items to bytes. > > To make it obvious, rename them to NR_SLAB_RECLAIMABLE_B and > NR_SLAB_UNRECLAIMABLE_B (similar to NR_KERNEL_STACK_KB). > > Internally global and per-node counters are stored in pages, > however memcg and lruvec counters are stored in bytes. > This scheme may look weird, but only for now. As soon as slab > pages will be shared between multiple cgroups, global and > node counters will reflect the total number of slab pages. > However memcg and lruvec counters will be used for per-memcg > slab memory tracking, which will take separate kernel objects > in the account. Keeping global and node counters in pages helps > to avoid additional overhead. > > The size of slab memory shouldn't exceed 4Gb on 32-bit machines, > so it will fit into atomic_long_t we use for vmstats. > > Signed-off-by: Roman Gushchin > --- > drivers/base/node.c | 4 ++-- > fs/proc/meminfo.c | 4 ++-- > include/linux/mmzone.h | 16 +++++++++++++--- > kernel/power/snapshot.c | 2 +- > mm/memcontrol.c | 11 ++++------- > mm/oom_kill.c | 2 +- > mm/page_alloc.c | 8 ++++---- > mm/slab.h | 15 ++++++++------- > mm/slab_common.c | 4 ++-- > mm/slob.c | 12 ++++++------ > mm/slub.c | 8 ++++---- > mm/vmscan.c | 3 ++- > mm/workingset.c | 6 ++++-- > 13 files changed, 53 insertions(+), 42 deletions(-) > @@ -206,7 +206,17 @@ enum node_stat_item { > > static __always_inline bool vmstat_item_in_bytes(enum node_stat_item item) > { > - return false; > + /* > + * Global and per-node slab counters track slab pages. > + * It's expected that changes are multiples of PAGE_SIZE. > + * Internally values are stored in pages. > + * > + * Per-memcg and per-lruvec counters track memory, consumed > + * by individual slab objects. These counters are actually > + * byte-precise. > + */ > + return (item == NR_SLAB_RECLAIMABLE_B || > + item == NR_SLAB_UNRECLAIMABLE_B); > } Ok, so this is no longer a no-op, but __always_inline here and inline in global_node_page_state() should hopefully mean that for all users of global_node_page_state() the compiler will eliminate the branch for non-slab counters. But there are also functions such as si_mem_available() that use non-constant item. Maybe compiler is smart enough anyway, but perhaps it's better to use global_node_page_state_pages() in such callers? However __mod_node_page_state() and mode_node_state() will now branch always. I wonder if the "API clean" goal is worth it... > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1409,9 +1409,8 @@ static char *memory_stat_format(struct mem_cgroup *memcg) > (u64)memcg_page_state(memcg, MEMCG_KERNEL_STACK_KB) * > 1024); > seq_buf_printf(&s, "slab %llu\n", > - (u64)(memcg_page_state(memcg, NR_SLAB_RECLAIMABLE) + > - memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE)) * > - PAGE_SIZE); > + (u64)(memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + > + memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B))); > seq_buf_printf(&s, "sock %llu\n", > (u64)memcg_page_state(memcg, MEMCG_SOCK) * > PAGE_SIZE); > @@ -1445,11 +1444,9 @@ static char *memory_stat_format(struct mem_cgroup *memcg) > PAGE_SIZE); > > seq_buf_printf(&s, "slab_reclaimable %llu\n", > - (u64)memcg_page_state(memcg, NR_SLAB_RECLAIMABLE) * > - PAGE_SIZE); > + (u64)memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B)); > seq_buf_printf(&s, "slab_unreclaimable %llu\n", > - (u64)memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE) * > - PAGE_SIZE); > + (u64)memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B)); So here we are now printing in bytes instead of pages, right? That's fine for OOM report, but in sysfs aren't we breaking existing users?