From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86DBCC433FE for ; Mon, 7 Dec 2020 15:19:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EBBAE23730 for ; Mon, 7 Dec 2020 15:19:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBBAE23730 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0EB18D0003; Mon, 7 Dec 2020 10:19:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBFE88D0001; Mon, 7 Dec 2020 10:19:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD5648D0003; Mon, 7 Dec 2020 10:19:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id C661C8D0001 for ; Mon, 7 Dec 2020 10:19:47 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8A847181AEF23 for ; Mon, 7 Dec 2020 15:19:47 +0000 (UTC) X-FDA: 77566846014.03.whip00_0614294273df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 6F36728A4EC for ; Mon, 7 Dec 2020 15:19:47 +0000 (UTC) X-HE-Tag: whip00_0614294273df X-Filterd-Recvd-Size: 5387 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 7 Dec 2020 15:19:46 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id h7so82984pjk.1 for ; Mon, 07 Dec 2020 07:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K/8cl08sjjk7XgilYCDYzD/2g3tf6PI2yGU88Vpkn4A=; b=ZvtKJVWdEcz//9OHUucVTATmSAQTbpHT3os9hXUq1tI7hELUplnd8MnB7mAvrNTInG SXI4kX0qtpGl8NvMOqSz5ZfaT6by3X4IlHRJ1dCjN4mp9fiOygwBLBo7DGq6ShDGEAMz WOxaCJUpmiWjCm5juhwKjGc9XjQPRQSDnwAnhRxXwXihS5IazI64FczZA+mpY0zxmNqP YYzLxnSOq2ftnzGeU0a1TunNkm9DRSp+d30U4zGh7ThlOaZsMr5s5OIoy/merSHADQDV oWro9DLx5fUohiW9xYkhz0afQc7YYyYicgJicsHm+hnFVkW3yDp8CndN/hXzNdmyz8pw Zh0w== 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=K/8cl08sjjk7XgilYCDYzD/2g3tf6PI2yGU88Vpkn4A=; b=qTHxaQprYKkN7YnkEuaAQqPUX9kQP+SfW+RUWY9MtcUI1/U2UqvuTLBmddN5eLyrSe kpC0lYZIr/jYZTr6jbmeaVN+b4uew2XUtdleRt88rAUQ1E67qcToLqD/Zdu4EWR6qmJX hMoxr9TaU8ygzhOEdWOl+h796kXfAEku3EBGlQqCSFg18GzW4LJnivyfOGGmOxeAyEbl 4vti+6MP7ksdYR2tvlwF0LRFjiXb0SjbWKBYbsIkNi8YJ7gjSZxZKJ/f4BQA8zSsx45q 2Nj/gmUvdVGzs+AFDz98copnVxtFbAeNJ+Fv5IvN8yC5ZiuPOF8UpoGenb8UWjSbZjlN Bu0A== X-Gm-Message-State: AOAM530MfWOE8u3wWph7m7FKdS3xU59b+mtokLWsSNMcsZ1Yj2g+jwn1 sEgc+LWURT+t6apM2MvQAgO5x72AFvsSaUtWyOlvIw== X-Google-Smtp-Source: ABdhPJwiNRhdrT0KFjUxeAEE1uHOTXZ12d5p6D3NspJJwi6Ek+Zsfu2cWBdWyw/wt0Qc/Ccs+HbGXutwFHtLoEgc6+s= X-Received: by 2002:a17:90a:ae14:: with SMTP id t20mr17277340pjq.13.1607354385273; Mon, 07 Dec 2020 07:19:45 -0800 (PST) MIME-Version: 1.0 References: <20201206085639.12627-1-songmuchun@bytedance.com> <20201207123605.GH25569@dhcp22.suse.cz> <20201207150847.GM25569@dhcp22.suse.cz> In-Reply-To: <20201207150847.GM25569@dhcp22.suse.cz> From: Muchun Song Date: Mon, 7 Dec 2020 23:19:09 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: memcontrol: optimize per-lruvec stats counter memory usage To: Michal Hocko Cc: Johannes Weiner , Vladimir Davydov , Andrew Morton , Shakeel Butt , Roman Gushchin , Stephen Rothwell , Chris Down , Yafang Shao , richard.weiyang@gmail.com, LKML , Cgroups , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Dec 7, 2020 at 11:09 PM Michal Hocko wrote: > > On Mon 07-12-20 20:56:58, Muchun Song wrote: > > On Mon, Dec 7, 2020 at 8:36 PM Michal Hocko wrote: > > > > > > On Sun 06-12-20 16:56:39, Muchun Song wrote: > > > > The vmstat threshold is 32 (MEMCG_CHARGE_BATCH), so the type of s32 > > > > of lruvec_stat_cpu is enough. And introduce struct per_cpu_lruvec_stat > > > > to optimize memory usage. > > > > > > How much savings are we talking about here? I am not deeply familiar > > > with the pcp allocator but can it compact smaller data types much > > > better? > > > > It is a percpu struct. The size of struct lruvec_stat is 304(tested on the > > linux-5.5). So we can save 304 / 2 * nproc bytes per memcg where nproc > > is the number of the possible CPU. If we have n memory cgroup in the > > system. Finally, we can save (152 * nproc * n) bytes. In some configurations, > > nproc here may be 512. And if we have a lot of dying cgroup. The n can be > > 100, 000 (I once saw it on my server). > > This should be part of the changelog. In general, any optimization > should come with some numbers showing the effect of the optimization. > > As I've said I am not really familiar with pcp internals and how > efficiently it can organize smaller objects. Maybe it can really half > the memory consumption. > > My only concern is that using smaller types for these counters can fire > back later on because we have an inderect dependency between the batch > size and the data type. In general I do not really object to the patch > as long as savings are non trivial so that we are not creating a > potential trap for something that is practically miniscule > microptimization. There is a similar structure named struct per_cpu_nodestat. struct per_cpu_nodestat { s8 stat_threshold; s8 vm_node_stat_diff[NR_VM_NODE_STAT_ITEMS]; }; The s8 is enough for per-node vmstat counters. This also depends on the batch size. It can be s8 for a long time. Why not s32 is not suitable for the per-memcg vmstat counters? They are very similar, right? Thanks. > -- > Michal Hocko > SUSE Labs -- Yours, Muchun