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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,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 19B42C433E0 for ; Thu, 18 Mar 2021 15:23:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6F11264ED2 for ; Thu, 18 Mar 2021 15:23:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F11264ED2 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 ADE796B007D; Thu, 18 Mar 2021 11:23:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8F018D0001; Thu, 18 Mar 2021 11:23:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F4046B0080; Thu, 18 Mar 2021 11:23:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id 719D76B007D for ; Thu, 18 Mar 2021 11:23:55 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1B28D181AF5CC for ; Thu, 18 Mar 2021 15:23:55 +0000 (UTC) X-FDA: 77933365188.01.2651CA0 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 174AAC0042D4 for ; Thu, 18 Mar 2021 15:23:50 +0000 (UTC) Received: by mail-qk1-f176.google.com with SMTP id n24so2326475qkh.9 for ; Thu, 18 Mar 2021 08:23:50 -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=83eSfMshydOehdsQas9XVeyiqjOb6ETR5e73nz99axM=; b=FNs7oGhmem/QqkDrdV/bSV0IrY6lwraMRbypnquZjTYMqSPez0sxTQMUgXb3xR+tkt c+/Kmqf1+nBgWgVev7X8BpTA8pZnJGJ0QH3oHhb/V0IbKKhPfqZAxJNFL1amw2h8pdJC P3psE1zU5P3VFHUf7sMO+b43jQwMWtWMF0wN/7mT2w/b0aLLBhNbVQim3LSMNoy5x0wv yb8IqIWtslHSVVt5cKwbFB/GVNVjm8yAnjfHX7ESih022t1rZUNF2iUHQG9SReH9s8OV XdqzdX1C+/2qqbZ1hJhmYB3QfjiA/HHll4Zd9zZL7MyLpWb7VF8WAhjTL92bYkt6dax+ WFgw== 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=83eSfMshydOehdsQas9XVeyiqjOb6ETR5e73nz99axM=; b=g3CsUGnwZ44QQbgeAR7R/LTp9JMLyV/sH1nxGYk2faer7HKuLxpkl+QymXo/Vx/Eg3 mZhIlbDaGo1Ccu8VLZeVTmxHq88dKiSXOaKGKedLMgd1CsHfBKeS+QxtrwUUgg09n2zS ZBx+1Y4GMr4gARwu08RAYf9+GxmpFVNlatLiOBWHnJ/aRTBKXZXaz9id/ZbF/bu5HAkI KCoFsygIb/k3omgDyhZrJYYVJrEkbz4IiEoLbe7VNgEbXEYmYa65tQsiiiKihw+3zCde qIUehxVD3xvTQWfOxFFiLdbuSfRjdbdYG+z9sv+0z8a9P7dEuc2TVBc4osi9hEUkWOU/ 4oNw== X-Gm-Message-State: AOAM530IFVmt/y34ZJDPq+51KTTKBpu7l+tdZyXv2cZQOjRzoFuG9LgS DBr+rYIfmKeNq3syEwW2A6Vhgw== X-Google-Smtp-Source: ABdhPJwmywL6WZSKRco5PsaSF2jLsPauxK+yvfTRzPnity0ONAhCMbUrBMzI0Qgl2cX+fLYv1aVgHw== X-Received: by 2002:a05:620a:1502:: with SMTP id i2mr4826610qkk.373.1616081028824; Thu, 18 Mar 2021 08:23:48 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:e46c]) by smtp.gmail.com with ESMTPSA id 30sm1624852qta.38.2021.03.18.08.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 08:23:48 -0700 (PDT) Date: Thu, 18 Mar 2021 11:23:47 -0400 From: Johannes Weiner To: Muchun Song Cc: guro@fb.com, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com Subject: Re: [PATCH v4 4/5] mm: memcontrol: use obj_cgroup APIs to charge kmem pages Message-ID: References: <20210318110658.60892-1-songmuchun@bytedance.com> <20210318110658.60892-5-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210318110658.60892-5-songmuchun@bytedance.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 174AAC0042D4 X-Stat-Signature: jd66666qfoh4o5bioirwd56kbi3jeor8 Received-SPF: none (cmpxchg.org>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-qk1-f176.google.com; client-ip=209.85.222.176 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616081030-271718 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 Thu, Mar 18, 2021 at 07:06:57PM +0800, Muchun Song wrote: > Since Roman series "The new cgroup slab memory controller" applied. All > slab objects are charged via the new APIs of obj_cgroup. The new APIs > introduce a struct obj_cgroup to charge slab objects. It prevents > long-living objects from pinning the original memory cgroup in the memory. > But there are still some corner objects (e.g. allocations larger than > order-1 page on SLUB) which are not charged via the new APIs. Those > objects (include the pages which are allocated from buddy allocator > directly) are charged as kmem pages which still hold a reference to > the memory cgroup. > > We want to reuse the obj_cgroup APIs to charge the kmem pages. > If we do that, we should store an object cgroup pointer to > page->memcg_data for the kmem pages. > > Finally, page->memcg_data will have 3 different meanings. > > 1) For the slab pages, page->memcg_data points to an object cgroups > vector. > > 2) For the kmem pages (exclude the slab pages), page->memcg_data > points to an object cgroup. > > 3) For the user pages (e.g. the LRU pages), page->memcg_data points > to a memory cgroup. > > We do not change the behavior of page_memcg() and page_memcg_rcu(). > They are also suitable for LRU pages and kmem pages. Why? > > Because memory allocations pinning memcgs for a long time - it exists > at a larger scale and is causing recurring problems in the real world: > page cache doesn't get reclaimed for a long time, or is used by the > second, third, fourth, ... instance of the same job that was restarted > into a new cgroup every time. Unreclaimable dying cgroups pile up, > waste memory, and make page reclaim very inefficient. > > We can convert LRU pages and most other raw memcg pins to the objcg > direction to fix this problem, and then the page->memcg will always > point to an object cgroup pointer. At that time, LRU pages and kmem > pages will be treated the same. The implementation of page_memcg() > will remove the kmem page check. > > This patch aims to charge the kmem pages by using the new APIs of > obj_cgroup. Finally, the page->memcg_data of the kmem page points to > an object cgroup. We can use the __page_objcg() to get the object > cgroup associated with a kmem page. Or we can use page_memcg() > to get the memory cgroup associated with a kmem page, but caller must > ensure that the returned memcg won't be released (e.g. acquire the > rcu_read_lock or css_set_lock). > > Signed-off-by: Muchun Song Thanks for the updated version, looks good to me! Acked-by: Johannes Weiner