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=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 F20DAC2D0C8 for ; Sat, 28 Dec 2019 04:23:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8FDA920722 for ; Sat, 28 Dec 2019 04:23:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Agd9c24p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FDA920722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D8AFD8E0005; Fri, 27 Dec 2019 23:23:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3AF88E0001; Fri, 27 Dec 2019 23:23:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2A228E0005; Fri, 27 Dec 2019 23:23:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id AAE5D8E0001 for ; Fri, 27 Dec 2019 23:23:04 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 291528249980 for ; Sat, 28 Dec 2019 04:23:04 +0000 (UTC) X-FDA: 76313255088.30.town61_8f26cd645e316 X-HE-Tag: town61_8f26cd645e316 X-Filterd-Recvd-Size: 5877 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Dec 2019 04:23:03 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id c16so25854661ioh.6 for ; Fri, 27 Dec 2019 20:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bAVEjAKn0jGZi2p1gUUgZlWANldhZraqvtNORHEys4g=; b=Agd9c24pFAje2RvSwK9eyENDA3Et5qKaSLaIWl60J5pQSRW32WexYBOnPanCM5API6 Gxb0dHD/Ojp9d6U+a30lPWm+se6vXmuSRSdhudvuBlpSm83bNYxMxM6L5+IhzVHF5HG3 XJ+ve6ZEggaCJnwXv0fYAighIPn8xh6OQf6gZBgUDt2YxfE/6AUiGMj2DJADXu4NQKLs Wq5dn6EFQ4/RxJJ+/oJSPV3IR0UJVpX6aw+3x8R5XuxmRzZdG25FpIteAz5O8p4da048 npYlJz4RmqJIxg97GO7WZRKfDGJQ2aSS2CcQhAABz1JOyhdqau0L/wj/ya1/6E/80HoM JQVw== 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=bAVEjAKn0jGZi2p1gUUgZlWANldhZraqvtNORHEys4g=; b=jlHxOkIY3xZHUSmaoIqkrQMmQqkbqt2bgjhPkPnYahHI/jsJx6LeMuBobP+mTELLQr 7XZjc/cQqJPMiF9n2vTxd960zWaNHsSF2kG6ewFBxx4p7swLmWnqHOKB9NXkcuBWWSMj x3CaLn33dZyWtK/tfeuWDIWLlf2/UT6HpaVhur8FFOD+WH8EWzz3GHi2feW+735hsTnN f1E97zWmWX9weQfP/P8dEbWqmyZW2stNDMnqUzPyCR1a9SkX9y5VYbao94rod9Gl9mjp cdkklQioFC4UNGG1fco26kY/rWyRAgAaSfUBI2ryC2STjX5cRdgTWQGY6CzN5naBoPZa 3ADA== X-Gm-Message-State: APjAAAVebK3GHvXGmzGjG1VvHCUn5AC8+D5ox0N0IZ6fIS8ryaG0s1x4 J6u/N+dsjo8wV8vHvNAjMK3SNBAW3RUVG60HiZI= X-Google-Smtp-Source: APXvYqzIRZghRtf8DCKpnVJ6WzgLvehauWBRQE8LjZUZ4S3K7ptNSFn/l3gb9lUdnatYr0GA5yocDnK0SFLbOMXYuts= X-Received: by 2002:a02:cd31:: with SMTP id h17mr42115923jaq.94.1577506982964; Fri, 27 Dec 2019 20:23:02 -0800 (PST) MIME-Version: 1.0 References: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com> <20191227235537.GB6742@localhost.localdomain> In-Reply-To: <20191227235537.GB6742@localhost.localdomain> From: Yafang Shao Date: Sat, 28 Dec 2019 12:22:26 +0800 Message-ID: Subject: Re: [PATCH] mm, memcg: reduce size of struct mem_cgroup by using bit field To: Roman Gushchin Cc: "hannes@cmpxchg.org" , "mhocko@kernel.org" , "vdavydov.dev@gmail.com" , "akpm@linux-foundation.org" , "linux-mm@kvack.org" 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 Sat, Dec 28, 2019 at 7:55 AM Roman Gushchin wrote: > > On Fri, Dec 27, 2019 at 07:43:52AM -0500, Yafang Shao wrote: > > There are some members in struct mem_group can be either 0(false) or > > 1(true), so we can define them using bit field to reduce size. With this > > patch, the size of struct mem_cgroup can be reduced by 64 bytes in theory, > > but as there're some MEMCG_PADDING()s, the real number may be different, > > which is relate with the cacheline size. Anyway, this patch could reduce > > the size of struct mem_cgroup more or less. > > > > Signed-off-by: Yafang Shao > > Cc: Roman Gushchin > > --- > > include/linux/memcontrol.h | 21 ++++++++++++--------- > > 1 file changed, 12 insertions(+), 9 deletions(-) > > > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index a7a0a1a5..f68a9ef 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -229,20 +229,26 @@ struct mem_cgroup { > > /* > > * Should the accounting and control be hierarchical, per subtree? > > */ > > - bool use_hierarchy; > > + unsigned int use_hierarchy : 1; > > + > > + /* Legacy tcp memory accounting */ > > + unsigned int tcpmem_active : 1; > > + unsigned int tcpmem_pressure : 1; > > > > /* > > * Should the OOM killer kill all belonging tasks, had it kill one? > > */ > > - bool oom_group; > > + unsigned int oom_group : 1; > > > > /* protected by memcg_oom_lock */ > > - bool oom_lock; > > - int under_oom; > > + unsigned int oom_lock : 1; > > Hm, looking at the original code, it was clear that oom_lock > and under_oom are protected with memcg_oom_lock; but not oom_kill_disable. > > This information seems to be lost. > Should add this comment. Thanks for pointing this out. > Also, I'd look at the actual memory savings. Is it worth it? > Or it's all eaten by the padding. > As explained in the commit log, the real size depends on the cacheline size, and in the future we may introduce other new bool members. I have verified it on my server with 64B-cacheline, and the saveing is 0. Actually there's no strong reason to make this minor optimization. > Thanks! > > > > > - int swappiness; > > /* OOM-Killer disable */ > > - int oom_kill_disable; > > + unsigned int oom_kill_disable : 1; > > + > > + int under_oom; > > + > > + int swappiness; > > > > /* memory.events and memory.events.local */ > > struct cgroup_file events_file; > > @@ -297,9 +303,6 @@ struct mem_cgroup { > > > > unsigned long socket_pressure; > > > > - /* Legacy tcp memory accounting */ > > - bool tcpmem_active; > > - int tcpmem_pressure; > > > > #ifdef CONFIG_MEMCG_KMEM > > /* Index in the kmem_cache->memcg_params.memcg_caches array */ > > -- > > 1.8.3.1 > >