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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85E7FC433F5 for ; Mon, 8 Nov 2021 22:10:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA2A36162E for ; Mon, 8 Nov 2021 22:10:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA2A36162E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fromorbit.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E6BD26B006C; Mon, 8 Nov 2021 17:10:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1B6F6B0072; Mon, 8 Nov 2021 17:10:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D09FA6B0073; Mon, 8 Nov 2021 17:10:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id BE34E6B006C for ; Mon, 8 Nov 2021 17:10:53 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 72A0A18033E46 for ; Mon, 8 Nov 2021 22:10:53 +0000 (UTC) X-FDA: 78787158786.18.4AA0E42 Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by imf19.hostedemail.com (Postfix) with ESMTP id AC31AB0001A1 for ; Mon, 8 Nov 2021 22:10:44 +0000 (UTC) Received: from dread.disaster.area (pa49-195-103-97.pa.nsw.optusnet.com.au [49.195.103.97]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 3779B88A346; Tue, 9 Nov 2021 09:10:48 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1mkCql-006Vr8-Sv; Tue, 09 Nov 2021 09:10:47 +1100 Date: Tue, 9 Nov 2021 09:10:47 +1100 From: Dave Chinner To: Mina Almasry Cc: Michal Hocko , Theodore Ts'o , Greg Thelen , Shakeel Butt , Andrew Morton , Hugh Dickins , Roman Gushchin , Johannes Weiner , Tejun Heo , Vladimir Davydov , riel@surriel.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org Subject: Re: [PATCH v1 1/5] mm/shmem: support deterministic charging of tmpfs Message-ID: <20211108221047.GE418105@dread.disaster.area> References: <20211108211959.1750915-1-almasrymina@google.com> <20211108211959.1750915-2-almasrymina@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211108211959.1750915-2-almasrymina@google.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.4 cv=epq8cqlX c=1 sm=1 tr=0 ts=6189a06b a=fP9RlOTWD4uZJjPSFnn6Ew==:117 a=fP9RlOTWD4uZJjPSFnn6Ew==:17 a=kj9zAlcOel0A:10 a=vIxV3rELxO4A:10 a=7-415B0cAAAA:8 a=N7MhG7qYPJZj-3uz0y4A:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AC31AB0001A1 X-Stat-Signature: z65crfbe8scu87b1i6qute1nrwdw3rsx Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=none (imf19.hostedemail.com: domain of david@fromorbit.com has no SPF policy when checking 211.29.132.246) smtp.mailfrom=david@fromorbit.com X-HE-Tag: 1636409444-98538 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, Nov 08, 2021 at 01:19:55PM -0800, Mina Almasry wrote: > Add memcg= option to shmem mount. > > Users can specify this option at mount time and all data page charges > will be charged to the memcg supplied. ..... > +/* > + * Returns the memcg to charge for inode pages. If non-NULL is returned, caller > + * must drop reference with css_put(). NULL indicates that the inode does not > + * have a memcg to charge, so the default process based policy should be used. > + */ > +static struct mem_cgroup * > +mem_cgroup_mapping_get_charge_target(struct address_space *mapping) > +{ > + struct mem_cgroup *memcg; > + > + if (!mapping) > + return NULL; > + > + rcu_read_lock(); > + memcg = rcu_dereference(mapping->host->i_sb->s_memcg_to_charge); Anything doing pointer chasing to obtain static, unchanging superblock state is poorly implemented. The s_memcg_to_charge value never changes, so this code should associate the memcg to charge directly on the mapping when the mapping is first initialised by the filesystem. We already do this with things like attaching address space ops and mapping specific gfp masks (i.e mapping_set_gfp_mask()), so this association should be set up that way, too (e.g. mapping_set_memcg_to_charge()). And because this memcg pointer is static and unchanging for the entire life of the superblock, the superblock *must* pin the memcg into memory and that means we can elide the rcu locking altogether in the fast path for all filesystems that don't support this functionality. i.e. we can simply do: if (!mapping || !mapping->memcg_to_charge) return NULL; And then only if there is a memcg to charge, we do the slow path locking and lookup stuff... Cheers, Dave. -- Dave Chinner david@fromorbit.com