Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp584036pxk; Thu, 24 Sep 2020 12:58:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxTL1KfN9UAJO5m+ntmkrXBRN4FE3RdjzYs1GPlYNYeRg6N2pluFeGkac97QPyotzxZBn2 X-Received: by 2002:a05:6402:6d6:: with SMTP id n22mr443518edy.79.1600977491852; Thu, 24 Sep 2020 12:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600977491; cv=none; d=google.com; s=arc-20160816; b=0Zs1lzAYqlfm6cM+4O9gGr1v80O5Nj9g3H96fxgO/AxLF3xU2WOn0iMKtGlt5Gz6G4 PBXDhHEqWF4hhtUYrcIrW8mYIBL5qZ0ybBHRr3cvypCz6Z/WNwaEWcxYi77vqTYWYQsV fWCWiMZGK7UxbU1YwZE0hLk6U36/ktE1siNP0ffUI9bDhoadSksHvfEmmlfP9Hdk4OF0 O4VD7JPPiKGEcgevFIo/560hv5DY9okeR5yt0LDLjfg3gQ7PB1u7Qe+VphR0IX1/n0j1 16cv3IKbP6SN/CwcvfgiNEy8JRHqAs/06I9k53OYnYcy1a9j1+P6taHQopZ2llrjdGAs 02ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5Op4Hiq5hd5n1kw3kp86fKeHLeQWSXD9jmdVx/Yl5kY=; b=saHPF4WksUIm8f5SVw5I4Wqbt5k+jjGbzumSIOkFCEQskvrfiYN2MzZTMWw8hLnCsV rLakdcpd0Hjx3zbTTYfzUulFhGurMx/bhdUslWxMboaY58tWeuRfwscCIF85zWzABWrK IjI5RshkFA7qFI6xs0lGI2GBFcylV03Jj0PYmkp8YXQrBAsr3TiVD0KgwbBnPKiXTAjz QaPu+QsEUhCtbOi1GkZ30Tqk7Kr9DHHrAaQFbN0nVnHig+r5fY62CDA7ZAYGELiI6RGE vAxy+CuyMSE6hEz//YVNaaoCcDs18oQPiNCww6JbpjFO1nWPwlu3rKwm6/rdLyuQxn0z ui9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ob57nNMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id k19si386420ejx.426.2020.09.24.12.57.48; Thu, 24 Sep 2020 12:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ob57nNMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726414AbgIXTzc (ORCPT + 99 others); Thu, 24 Sep 2020 15:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbgIXTz3 (ORCPT ); Thu, 24 Sep 2020 15:55:29 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92204C0613CE for ; Thu, 24 Sep 2020 12:55:29 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id q5so717424qkc.2 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=d9rx45sWJrOn51fluhgfR6gc5hWfgQkgPg4qhvK4w+vP0kXymjNltqDOQ0AiKL7l9K aUN4e/2R8icQTptpRs/QmROSE8qNO3VYuAgssNN0bZ2me3f0bsJY9VKvp7O7l6zdjpMO JkqYIcQA4luKB/8i1Pb2JAaZEXN0zS0I+okQp511AYiZcNmK3RslAQMOCkFN+sUrhKWZ ruocw1E+Fs12A41vNVDrOHkRi+QgQ28R6z/jiuqh0QWBajE9g7WRPCj5JDv4FjJp/k69 crj+7Rf7rcWg1xKQ5r+QSH+cqZcrurrB0HVUsx0TnmL5kOviP5Mt6EEPo6fe2dqIJvNC P+5g== X-Gm-Message-State: AOAM531N1OeaoLRoWlUosseO2bAWTsjoxwAdhyJA6rsajSn+wxeRAJ6m 6Pq8K8tkNQnsOY3JoOA5529kjEsIO3GDyw== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?