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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 AB127C433ED for ; Mon, 12 Apr 2021 17:15:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DDB9361222 for ; Mon, 12 Apr 2021 17:15:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDB9361222 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 ED6F46B006C; Mon, 12 Apr 2021 13:15:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E87EE6B006E; Mon, 12 Apr 2021 13:15:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D00736B0070; Mon, 12 Apr 2021 13:15:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id AE3B96B006C for ; Mon, 12 Apr 2021 13:15:00 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 627C0824934B for ; Mon, 12 Apr 2021 17:15:00 +0000 (UTC) X-FDA: 78024365160.14.6598E75 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf09.hostedemail.com (Postfix) with ESMTP id D23B16000123 for ; Mon, 12 Apr 2021 17:14:56 +0000 (UTC) Received: by mail-qk1-f172.google.com with SMTP id d23so2929189qko.12 for ; Mon, 12 Apr 2021 10:14:59 -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=mztj3YmmozSjsP7YF+63NXvn93gX18LsCcbiTCMKvuY=; b=AgXmby4EVK1M9TaU93B0tvhyMIuWu1mucIXPlFBgZh+Uei4TlJqKcr4+2w0hcxhqKg Ni687E83GTPBCZY6MUE7ZFFPAPV7SaFYPuEoWz3bq6lrWz8yJ43FT8cjzI1l69D3n+ij pwLRZDACu8Y/WOnVkI7/P1+TuM8HbDZ0ZIOLIUQCKPu5nPz2p3+WLDs5FOrehowpd++b XMd3QZJdoCGZb+owWdzYXdfRV/LiuxOIcP9e2S8qMoJH/5VgqgPxksHCuoK4O4ZKwHTC 6eArC8aBWrX9Jt4uLHQqqV7uR4wkMEcD7SY+laxxtsqUyIvZ3Zr/esGFEuOGWZEt2kz3 LMsQ== 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=mztj3YmmozSjsP7YF+63NXvn93gX18LsCcbiTCMKvuY=; b=uEqw1S8waQysayrvb9e8VEGqvfA8xyjxSEpUWHf217YGvgopJ0GWJv8m8cYgHheuBx Rel86FFAYfoNmUNQJvqMnpjxg+1Vm47Pd0WAgPTIigGR1DJNrLC09ndAaLynzbvsBj33 mVseXaCTb3hxbU+VOSRn+3bsJbv1ys58f5L77UpFBn8f+zPfzdhvNaksCrUFPqvJk1/i EzWfMicJV32fNu3baxqLFS/1Q8e54YWw9i8eYbyHpB60GArislzmkQkpGValtvwr1fH0 HdkEEBqRjpBDABJOtaO9/YiVY1cuwiFpKpyLiXmI5V5YuXPPSuycMZ3nRrt79GA8wnOa DIuQ== X-Gm-Message-State: AOAM533tT9Fc82BNEZsq+/O/btUxktFwN2ptyqOfeKUTHsWrpymCwGpf XYUA6YtTr/EoQeCowUoUtETqzQ== X-Google-Smtp-Source: ABdhPJzvnpOuvYh0cOa1StH86GYB6t9o7Bd+ieLigHO1L6X8LfilAKfKSk5JVsXaFyfgTECudYTAhA== X-Received: by 2002:a37:63ce:: with SMTP id x197mr13758669qkb.341.1618247698869; Mon, 12 Apr 2021 10:14:58 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id z7sm8156745qkf.136.2021.04.12.10.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 10:14:58 -0700 (PDT) Date: Mon, 12 Apr 2021 13:14:57 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Muchun Song , 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, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alex.shi@linux.alibaba.com Subject: Re: [RFC PATCH v2 00/18] Use obj_cgroup APIs to charge the LRU pages Message-ID: References: <20210409122959.82264-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D23B16000123 X-Stat-Signature: 11uhxxoowsayxmxezeg4g5k1o847g414 Received-SPF: none (cmpxchg.org>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail-qk1-f172.google.com; client-ip=209.85.222.172 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618247696-440207 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 Fri, Apr 09, 2021 at 06:29:46PM -0700, Roman Gushchin wrote: > On Fri, Apr 09, 2021 at 08:29:41PM +0800, Muchun Song wrote: > > Since the following patchsets applied. All the kernel memory are charged > > with the new APIs of obj_cgroup. > > > > [v17,00/19] The new cgroup slab memory controller > > [v5,0/7] Use obj_cgroup APIs to charge kmem pages > > > > But user memory allocations (LRU pages) 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 LRU pages will not pin the memcgs. > > > > This patchset aims to make the LRU pages to drop the reference to memory > > cgroup by using the APIs of obj_cgroup. Finally, we can see that the number > > of the dying cgroups will not increase if we run the following test script. > > > > ```bash > > #!/bin/bash > > > > cat /proc/cgroups | grep memory > > > > cd /sys/fs/cgroup/memory > > > > for i in range{1..500} > > do > > mkdir test > > echo $$ > test/cgroup.procs > > sleep 60 & > > echo $$ > cgroup.procs > > echo `cat test/cgroup.procs` > cgroup.procs > > rmdir test > > done > > > > cat /proc/cgroups | grep memory > > ``` > > > > Patch 1 aims to fix page charging in page replacement. > > Patch 2-5 are code cleanup and simplification. > > Patch 6-18 convert LRU pages pin to the objcg direction. > > > > Any comments are welcome. Thanks. > > Indeed the problem exists for a long time and it would be nice to fix it. > However I'm against merging the patchset in the current form (there are some > nice fixes/clean-ups, which can/must be applied independently). Let me explain > my concerns: > > Back to the new slab controller discussion obj_cgroup was suggested by Johannes > as a union of two concepts: > 1) reparenting (basically an auto-pointer to a memcg in c++ terms) > 2) byte-sized accounting > > I was initially against this union because I anticipated that the reparenting > part will be useful separately. And the time told it was true. "The idea of moving stocks and leftovers to the memcg_ptr/obj_cgroup level is really good." https://lore.kernel.org/lkml/20191025200020.GA8325@castle.DHCP.thefacebook.com/ If you recall, the main concern was how the byte charging interface was added to the existing page charging interface, instead of being layered on top of it. I suggested to do that and, since there was no other user for the indirection pointer, just include it in the API. It made sense at the time, and you seemed to agree. But I also agree it makes sense to factor it out now that more users are materializing. > I still think obj_cgroup API must be significantly reworked before being > applied outside of the kmem area: reparenting part must be separated > and moved to the cgroup core level to be used not only in the memcg > context but also for other controllers, which are facing similar problems. > Spilling obj_cgroup API in the current form over all memcg code will > make it more complicated and will delay it, given the amount of changes > and the number of potential code conflicts. > > I'm working on the generalization of obj_cgroup API (as described above) > and expect to have some patches next week. Yeah, splitting the byte charging API from the reference API and making the latter cgroup-generic makes sense. I'm looking forward to your patches. And yes, the conflicts between that work and Muchun's patches would be quite large. However, most of them would come down to renames, since the access rules and refcounting sites will remain the same, so it shouldn't be too bad to rebase Muchun's patches on yours. And we can continue reviewing his patches for correctness for now. Thanks