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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 4DD1AC4363D for ; Thu, 24 Sep 2020 19:55:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9634B2220D for ; Thu, 24 Sep 2020 19:55:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="ob57nNMk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9634B2220D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D6E038E0001; Thu, 24 Sep 2020 15:55:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1EA56B0068; Thu, 24 Sep 2020 15:55:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C34658E0001; Thu, 24 Sep 2020 15:55:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id AE6986B005D for ; Thu, 24 Sep 2020 15:55:30 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5B9813635 for ; Thu, 24 Sep 2020 19:55:30 +0000 (UTC) X-FDA: 77299009620.13.honey04_290b20827161 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 3A041181415A0 for ; Thu, 24 Sep 2020 19:55:30 +0000 (UTC) X-HE-Tag: honey04_290b20827161 X-Filterd-Recvd-Size: 5743 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 19:55:29 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id c62so720174qke.1 for ; Thu, 24 Sep 2020 12:55:29 -0700 (PDT) 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=5Op4Hiq5hd5n1kw3kp86fKeHLeQWSXD9jmdVx/Yl5kY=; b=ob57nNMkag2afv4/5GijO9UhiVrufPCWTRekf9ZnP9YnX0uOutw01N8roWEPAYX1Y3 GSIrgdgC4g2Ba3SCB+RIRl8VAqs8HofBralaCoTnhLk3C81eHmjWM6a/Sm76Zvb5NgQV zVJ/GR5X1x0usbNS6ElCjXwqfkzNMGYVLhhB/IJ6qKK9tSd8SEKviN8xLHq2UJzBlqgT UlH9lYz91lhJIggqVW2FcOhAPOUKfnAi8YRTEzZBospPmZ1HqV+g6dY0Dh+0a88f0MPI enXA8rziuHCgvdLYaxFWllxDb7l5KZdV0rxnhsRC6GpYdAZy+x7cTbnnGggJGwkW9MvE ARDg== 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=5Op4Hiq5hd5n1kw3kp86fKeHLeQWSXD9jmdVx/Yl5kY=; b=mOPqENL7gORV2Y8b9aXKsiv6n9ojvYwMiKnvFlp2B8XelP2Q1hRNcH/vipM4sEDkgj 7WSw7xGvqFjamhCxe+W2GrET1eXnyQnsjn+Rj7/agkyQI9lleeaUeGmmtmvjpa6oD+c5 Pe72YfSiBbtxM6w+XfT4ZsWVhG6PZJGqVnbftwVZAb/179JAiPm17Z0K74IW217Vbr7W RUbQS1Pvx5rS/s/NHuVq9NNXYPqqSy1Cn/t+HoLd3Soldt+UF2tJKDdz7eTvMCIzc1Iz 19CJrlGajaINJtwhJ9o6oyiISrfZ39l3eCV/xtKzv/mZnRlzV+sp4UmZjoeEMdv+wXpB j6AQ== X-Gm-Message-State: AOAM532dx3MSPhxjYTHYHd16YdNy4dN7WmRGroRwuvP4Zbvlj1IeYvMJ dstMcue5jJh2X3b0r/9l5x20zA== X-Google-Smtp-Source: ABdhPJzJhT+2V8A7srU+lM90cHNW9zHPG/nmTnkKCgw4lydnSvLO3hoGvxPMcONsFz47UpyXnRrHuA== X-Received: by 2002:a37:a87:: with SMTP id 129mr699650qkk.13.1600977328765; Thu, 24 Sep 2020 12:55:28 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:4d7a]) by smtp.gmail.com with ESMTPSA id d76sm297769qkc.81.2020.09.24.12.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:55:28 -0700 (PDT) Date: Thu, 24 Sep 2020 15:53:56 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Shakeel Butt , Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: Re: [PATCH v1 2/4] mm: memcontrol/slab: use helpers to access slab page's memcg_data Message-ID: <20200924195356.GB329853@cmpxchg.org> References: <20200922203700.2879671-1-guro@fb.com> <20200922203700.2879671-3-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922203700.2879671-3-guro@fb.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000272, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 22, 2020 at 01:36:58PM -0700, Roman Gushchin wrote: > To gather all direct accesses to struct page's memcg_data field > in one place, let's introduce 4 new helper functions to use in > the slab accounting code: > struct obj_cgroup **page_obj_cgroups(struct page *page); > struct obj_cgroup **page_obj_cgroups_check(struct page *page); > bool set_page_obj_cgroups(struct page *page, struct obj_cgroup **objcgs); > void clear_page_obj_cgroups(struct page *page); > > They are similar to the corresponding API for generic pages, except > that the setter can return false, indicating that the value has been > already set from a different thread. > > Signed-off-by: Roman Gushchin > Reviewed-by: Shakeel Butt > --- > include/linux/memcontrol.h | 80 ++++++++++++++++++++++++++++++++++++++ > mm/memcontrol.c | 4 +- > mm/slab.h | 27 ++----------- > 3 files changed, 85 insertions(+), 26 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 3313e7c21534..ab3ea3e90583 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -409,6 +409,86 @@ static inline void clear_page_mem_cgroup(struct page *page) > page->memcg_data = 0; > } > > +#ifdef CONFIG_MEMCG_KMEM > +/* > + * page_obj_cgroups - get the object cgroups vector associated with a page > + * @page: a pointer to the page struct > + * > + * Returns a pointer to the object cgroups vector associated with the page, > + * or NULL. This function assumes that the page is known to have an > + * associated object cgroups vector. It's not safe to call this function > + * against pages, which might have an associated memory cgroup: e.g. > + * kernel stack pages. > + */ > +static inline struct obj_cgroup **page_obj_cgroups(struct page *page) > +{ > + return (struct obj_cgroup **)(page->memcg_data & ~0x1UL); page_mem_cgroup() has a VM_BUG_ON() if the page is in fact a slab type. Should this also check that if memcg_data is set, it MUST have the lower bit set? In line with page_memcg(), I think page_objcgs() would be nicer. As in 'memcg_reparent_objcgs()' :-) :-) :-) > @@ -2923,7 +2923,7 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p) > * Memcg membership data for each individual object is saved in > * the page->obj_cgroups. > */ > - if (page_has_obj_cgroups(page)) { > + if (page_obj_cgroups_check(page)) { > struct obj_cgroup *objcg; > unsigned int off; Similar to the previous patch: do we have anybody passing in objects that aren't actual objects in the obj_cgroup sense?