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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 5A26DC2D0CE for ; Tue, 31 Dec 2019 22:31:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E18B2205ED for ; Tue, 31 Dec 2019 22:31:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nr/7kU80" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E18B2205ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EF8E8E0005; Tue, 31 Dec 2019 17:31:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1168E0003; Tue, 31 Dec 2019 17:31:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B5EE8E0005; Tue, 31 Dec 2019 17:31:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id 31F318E0003 for ; Tue, 31 Dec 2019 17:31:42 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id DBDD48249980 for ; Tue, 31 Dec 2019 22:31:41 +0000 (UTC) X-FDA: 76326884802.02.arm12_48fcfb521fb09 X-HE-Tag: arm12_48fcfb521fb09 X-Filterd-Recvd-Size: 3109 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Tue, 31 Dec 2019 22:31:41 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D60D205ED; Tue, 31 Dec 2019 22:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577831500; bh=KM5p8ihpfS2+8R6ide1WGJBZTuved5Co0AwYYP6njNM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Nr/7kU80+DKSDOwP+j9fFcLzZ7s0+Ey+zx9dPS/oakIoaXkeeJeXVylQCZFjrbBqR GwVO0dyDk3bFXq6o8+gNSW5Tg31fgrZ3+V8iyt5SseX9VIK5a90SqKXenQl1gQGM6A oprbtelqRhgyE9gKeG8klC5Ssz9JgpcEBJ0N0E9Q= Date: Tue, 31 Dec 2019 14:31:39 -0800 From: Andrew Morton To: Yafang Shao Cc: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, linux-mm@kvack.org Subject: Re: [PATCH] mm, memcg: reduce size of struct mem_cgroup by using bit field Message-Id: <20191231143139.20a912b3386548062343a5b2@linux-foundation.org> In-Reply-To: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com> References: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Fri, 27 Dec 2019 07:43:52 -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. > > ... > > --- 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; Kernel coding style for this is normally no-spaces: bool foo:1; More significantly... Now that these fields share the same word of memory, what prevents races when two CPUs do read-modify-write operations on adjacent bitfields? This: struct foo { int a; int b; }; doesn't need locking to prevent modifications of `a' from scribbling on `b'. But with this: struct foo { int a:1; int b:1; } a simple `a = 1' on CPU1 could race with a `b = 1' on CPU2. I think. Maybe the compiler can take care of this in some fashion, but it would require atomic bitops and I doubt if gcc does that for us?