Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4033374ybl; Mon, 3 Feb 2020 11:13:45 -0800 (PST) X-Google-Smtp-Source: APXvYqwNl3EA2hYskhYa7aJ6H6wvip5iAuawnCUII2x06397YyUGVKsVQW7cIA0oDaO1VDuOle8F X-Received: by 2002:a05:6808:8cd:: with SMTP id k13mr413923oij.4.1580757225368; Mon, 03 Feb 2020 11:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580757225; cv=none; d=google.com; s=arc-20160816; b=F8OXFU64JuXMdbZ1z1Bfe5w9nN9bKuuYekr2sVojzjDNdbB8T3O/Fea/LlOt3kemWd 2grgZ/7B+1KzrQPjMF+GJVNVOMjnE3BabMR+nueI1ovHTVa5B3iQEMmIg+xilr1DlBf+ La5ihWNCHlmxh0ktHvzbyac6XKGNmeUXpeBl0zUK0zv2J2aPs1EBe82MaT6eT0DnlGDH joImvNTj4V7fzUyoHx8nlkwF7fwWe091Z213dNB0nAF/Rta3H07XHj8A3wCScfjRXgfD iSPYqVVZsZnXGPXRJbzW8nBZFLogvMqu25ct+jATOd4KsTUG3d71uKUHps5NshLAQ+XU vB6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=45arIOagvyiMcACXk6TG313wTzmAuQ92wsNv5LJ1hc8=; b=lzr830x+BHG5N3JE44be2pOy+zkutTsIgBzsaQimMxjeKTLUOP/pdjA40csgfePQ7/ 4K/Y3o+l7iw7T7DRjwNTnCyAG+owkc8crgtXl7qxHoZdgsu4lyamvryV8i0E3R3Ff+S2 riGzqKFPRrg8WzReP2Oc+JabDMKzrS7Ua04ehkdJbWjy5yHLr3E2p8zBUjdd1vMoD3UU GCiIrr+ydRyb8ITCZAiP4ONvL/SpWUJuEdoAZNpKCXOpXM8WpnGCx6ENWUYDwk8j71Ee 4BuQKglJ3obxiCPSKkXfU0z5FFPA3MEo+lGO7w4DF8ru1tBoydrkLSUZj969V19VbYnt ktrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ASUufhoB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j65si9232566otc.308.2020.02.03.11.13.33; Mon, 03 Feb 2020 11:13:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ASUufhoB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729757AbgBCS2A (ORCPT + 98 others); Mon, 3 Feb 2020 13:28:00 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:32830 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729630AbgBCS17 (ORCPT ); Mon, 3 Feb 2020 13:27:59 -0500 Received: by mail-qt1-f195.google.com with SMTP id d5so12254054qto.0 for ; Mon, 03 Feb 2020 10:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=45arIOagvyiMcACXk6TG313wTzmAuQ92wsNv5LJ1hc8=; b=ASUufhoBL/L9gjOgIkVl+X/+1iojQplgBD0VuNH7dJxHS53U51nj9lk6T+XrOx1bGB 6FhwaIcWUq0m6oUsuoVUcq65SfGZGdkhEvUttST4cN9lGnIAU0ScWVV9D5UZTMHFF+9t 3ZZE+J67I0F2c5PI42St3dgAE1nhiLcm+xY79T2NG5ydHt5a4n4sG0k72KHVRHrB9Ftv 0VQhKUFhkklTI9/w4Fn6i9IokhCQmdMv6jXf3uRgmxp4O8LOPyncxuDrK0leF2VLWRBK updFD+lT5yCKK4RoOSfXt463oLuxlKB+5fW8Uz6zGwRAXzmbCjBT+q0/OL/O8UEQ0gTx xYZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=45arIOagvyiMcACXk6TG313wTzmAuQ92wsNv5LJ1hc8=; b=oMHqt2l1gEiBgMR7pafIjswzT6M/rE3AGb1D77g3jnv4V9ewjXKBoKyip9PYaBFSgc qI5Hn4qJkulESuUrwX2vWYFaYXy2Eqxa0jXOCt7wDMXj/DzYlPso4CtZdAw3+ELmh6dw +aamzT9PPOgVPppxG85jxOo03tzwhcgZXcmskNq+80jDk6R+fyzOtSFUHDSZG5FaEy1e IV5VEKs0zoKQD894Me0IUmQUfDX/bJPFYjIkc7Qk/Lb1fPIJwRGfCfYU/I3FMFDRHNLc m8zipGOjwx4+ugkVJmQfusV8SdV/9XbKMl+CSx91sAe1HtG+OSrYharKAEhEEdK6MDqw 9DLw== X-Gm-Message-State: APjAAAVfR40UkAxFNSPoQELHQNf2EM4QcnPp9jSPmJI/R/3HWNBPUF66 T9aJ0/EKHgmP/qtKadTyG9Gp5A== X-Received: by 2002:aed:25a4:: with SMTP id x33mr25400876qtc.165.1580754478425; Mon, 03 Feb 2020 10:27:58 -0800 (PST) Received: from localhost ([2620:10d:c091:500::e256]) by smtp.gmail.com with ESMTPSA id v10sm10134764qtq.58.2020.02.03.10.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 10:27:57 -0800 (PST) Date: Mon, 3 Feb 2020 13:27:56 -0500 From: Johannes Weiner To: Roman Gushchin Cc: linux-mm@kvack.org, Andrew Morton , Michal Hocko , Shakeel Butt , Vladimir Davydov , linux-kernel@vger.kernel.org, kernel-team@fb.com, Bharata B Rao , Yafang Shao Subject: Re: [PATCH v2 16/28] mm: memcg/slab: allocate obj_cgroups for non-root slab pages Message-ID: <20200203182756.GG1697@cmpxchg.org> References: <20200127173453.2089565-1-guro@fb.com> <20200127173453.2089565-17-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200127173453.2089565-17-guro@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 27, 2020 at 09:34:41AM -0800, Roman Gushchin wrote: > Allocate and release memory to store obj_cgroup pointers for each > non-root slab page. Reuse page->mem_cgroup pointer to store a pointer > to the allocated space. > > To distinguish between obj_cgroups and memcg pointers in case > when it's not obvious which one is used (as in page_cgroup_ino()), > let's always set the lowest bit in the obj_cgroup case. > > Signed-off-by: Roman Gushchin > --- > include/linux/mm.h | 25 ++++++++++++++++++-- > include/linux/mm_types.h | 5 +++- > mm/memcontrol.c | 5 ++-- > mm/slab.c | 3 ++- > mm/slab.h | 51 +++++++++++++++++++++++++++++++++++++++- > mm/slub.c | 2 +- > 6 files changed, 83 insertions(+), 8 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 080f8ac8bfb7..65224becc4ca 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1264,12 +1264,33 @@ static inline void set_page_links(struct page *page, enum zone_type zone, > #ifdef CONFIG_MEMCG > static inline struct mem_cgroup *page_memcg(struct page *page) > { > - return page->mem_cgroup; > + struct mem_cgroup *memcg = page->mem_cgroup; > + > + /* > + * The lowest bit set means that memcg isn't a valid memcg pointer, > + * but a obj_cgroups pointer. In this case the page is shared and > + * isn't charged to any specific memory cgroup. Return NULL. > + */ > + if ((unsigned long) memcg & 0x1UL) > + memcg = NULL; > + > + return memcg; That should really WARN instead of silently returning NULL. Which callsite optimistically asks a page's cgroup when it has no idea whether that page is actually a userpage or not? > static inline struct mem_cgroup *page_memcg_rcu(struct page *page) > { > + struct mem_cgroup *memcg = READ_ONCE(page->mem_cgroup); > + > WARN_ON_ONCE(!rcu_read_lock_held()); > - return READ_ONCE(page->mem_cgroup); > + > + /* > + * The lowest bit set means that memcg isn't a valid memcg pointer, > + * but a obj_cgroups pointer. In this case the page is shared and > + * isn't charged to any specific memory cgroup. Return NULL. > + */ > + if ((unsigned long) memcg & 0x1UL) > + memcg = NULL; > + > + return memcg; Same here. > } > #else > static inline struct mem_cgroup *page_memcg(struct page *page) > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 270aa8fd2800..5102f00f3336 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -198,7 +198,10 @@ struct page { > atomic_t _refcount; > > #ifdef CONFIG_MEMCG > - struct mem_cgroup *mem_cgroup; > + union { > + struct mem_cgroup *mem_cgroup; > + struct obj_cgroup **obj_cgroups; > + }; Since you need the casts in both cases anyway, it's safer (and simpler) to do unsigned long mem_cgroup; to prevent accidental direct derefs in future code. Otherwise, this patch looks good to me!