Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1986120iog; Sun, 26 Jun 2022 03:47:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v8R4pcMgwBqmO8nH3MdelA2YhNBlepOqUcp0tBSvNv87S/6+DWnwXwVTcomC9ARLyjdTrK X-Received: by 2002:a17:906:9b8a:b0:722:e6e0:33d with SMTP id dd10-20020a1709069b8a00b00722e6e0033dmr7383134ejc.317.1656240479480; Sun, 26 Jun 2022 03:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656240479; cv=none; d=google.com; s=arc-20160816; b=asSpRmCAHX/60pFaKkcD/8lhaRzlCSkFp0EMG5BvVJWjvdsVF4pEco3n7sj94POdsJ mhEPvc7ngPh37J56lEuc0CJ1472nq+VJErisnIT5QOYxKWVycrIuwoLXENR3NLSWxzwq TkESKYtLwLN4RdgVXWp0Af48jj0rWwz0+m2C/qSqeqMZoga8FZf+M2xW6l4kgVkFmQyg zNoauqSsJYIMF8oGi+r2o1+zDFeaWk/5CPN61dgZr3djbxsDnUTgEU+MIbDr1yP93v80 5EgKXc1WJcwc6m9sq/oYdbWsjmNInEK2GWzwVvUoAAKDqLbRlfpjMJwaEpqBJ2yB2DlD Kt/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FGwBQWTfDP6NE9brdT5NpzAYQxVOdxA8Jol43hGxIq4=; b=RG1UN14/X1Go8G58TbcxnZzi3Yq8BI/VsWo1q+S6XgF3up3EbqaYzNH82gePA2T9XK 5xqm5si54c54UnWLE9Us28Q9RFqK4nXahGFUXE+Nv4vxGfcjqDGjwP5A2TwucXYu5CFJ BzYl5sISuApWKb1F0GamokEcXSTirEuF6blPjJDFCW94IzoyVKej6krKzcDwtsOr5pxx C+nNFSduaghluW7GiBctYDuIh/5GMSZZHMFafJ9p91uA5UwPW/lAKAcAUSSXrd0MgvKx CgFsboRbKbl3XzjSn6t25+2xVuHvJ8LDZwKzwhJXi7kpr5nLdtgtwO9jQi3dO8E7jGV1 gOuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F1UaSNRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020a50c38c000000b004358145e6e1si9039022edf.209.2022.06.26.03.47.34; Sun, 26 Jun 2022 03:47:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F1UaSNRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbiFZKco (ORCPT + 99 others); Sun, 26 Jun 2022 06:32:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232828AbiFZKcm (ORCPT ); Sun, 26 Jun 2022 06:32:42 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA08B12760 for ; Sun, 26 Jun 2022 03:32:40 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v14so9081298wra.5 for ; Sun, 26 Jun 2022 03:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=FGwBQWTfDP6NE9brdT5NpzAYQxVOdxA8Jol43hGxIq4=; b=F1UaSNRjTXS2/5lwFjrcRrOhaAihT2PhrHs5IN+vAP194dJCSPRi2f4Wcy4HRiDFXr z9RDXTNqOU8Kor9bg9JVir4Vq1k19REe1H5I9Yjy7dNSfJYwYekTzJoXw7e1AoTZp57e 3P3jhkbyobnGxWKU+R7p5c3t7y5IIGmC+Nyc6P+5+xlPi2UXxrMKgCvMQYpWxMtSPBUP Te6C9AT25mJZlhbY2bK4jnMlOGbUUjrpwvIViYOVxV+DSQnWYjhxxQZ+z32yRES3lIYz qazhfNZa+OE63i9s+VfcF1R3VF0rS92upyMIr1LKocriqOvOnHdajyRRg6AfL3KW7frF 8aVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FGwBQWTfDP6NE9brdT5NpzAYQxVOdxA8Jol43hGxIq4=; b=zCCWCpe8GqpFitI8Yjvp6U/4S6AGoGfPcdnTwNqhfF6F+VFrCbCLk6pvBsXWDf3LSw MggNwTG4tIpI9Ccpf/8AB+yxSYGkqceToa3MjQLs0H3BOGScA+G3jqBIrjlH5ZcI5ieC RxhaoyoAIdorFcSpzzUNUG7Op0MxevOBll/Gxq59IPeEi9ZuG3tM7zkip5ZFK3dBJoxL 7QhAKggEFn5sqWN5+fT0PKwQuaTY8dxBSx/r0QvKyKdf+l6PZJNCP7vTha5FfXGNMNdB PTrAo4eLDv96SoYBl3beQKtlp0C5R5EuqipQ0o5xcW6fkI2UuwvEnJ1eFIs6rMRNi1XI upaQ== X-Gm-Message-State: AJIora/9Bxt9EunZNHjGevJE12FEN2Hl4TrduedgL0pGA0jle1HJiYtO CCqdq4xrfH5LGySolrp6+Lgjd6X1jpqRkVqu6V45ww== X-Received: by 2002:a5d:4308:0:b0:219:e5a4:5729 with SMTP id h8-20020a5d4308000000b00219e5a45729mr7761939wrq.210.1656239559155; Sun, 26 Jun 2022 03:32:39 -0700 (PDT) MIME-Version: 1.0 References: <20220621125658.64935-1-songmuchun@bytedance.com> In-Reply-To: <20220621125658.64935-1-songmuchun@bytedance.com> From: Yosry Ahmed Date: Sun, 26 Jun 2022 03:32:02 -0700 Message-ID: Subject: Re: [PATCH v6 00/11] Use obj_cgroup APIs to charge the LRU pages To: Muchun Song Cc: Andrew Morton , Johannes Weiner , longman@redhat.com, Michal Hocko , Roman Gushchin , Shakeel Butt , Cgroups , duanxiongchun@bytedance.com, Linux Kernel Mailing List , Linux-MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 21, 2022 at 5:57 AM Muchun Song wrot= e: > > This version is rebased on mm-unstable. Hopefully, Andrew can get this se= ries > into mm-unstable which will help to determine whether there is a problem = or > degradation. I am also doing some benchmark tests in parallel. > > Since the following patchsets applied. All the kernel memory are charged > with the new APIs of obj_cgroup. > > commit f2fe7b09a52b ("mm: memcg/slab: charge individual slab obje= cts instead of pages") > commit b4e0b68fbd9d ("mm: memcontrol: use obj_cgroup APIs to char= ge 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 th= e > second, third, fourth, ... instance of the same job that was restarted in= to > a new cgroup every time. Unreclaimable dying cgroups pile up, waste memor= y, > and make page reclaim very inefficient. > > We can convert LRU pages and most other raw memcg pins to the objcg direc= tion > 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 numb= er > of the dying cgroups will not increase if we run the following test scrip= t. This is amazing work! Sorry if I came late, I didn't follow the threads of previous versions so this might be redundant, I just have a couple of questions. a) If LRU pages keep getting parented until they reach root_mem_cgroup (assuming they can), aren't these pages effectively unaccounted at this point or leaked? Is there protection against this? b) Since moving charged pages between memcgs is now becoming easier by using the APIs of obj_cgroup, I wonder if this opens the door for future work to transfer charges to memcgs that are actually using reparented resources. For example, let's say cgroup A reads a few pages into page cache, and then they are no longer used by cgroup A. cgroup B, however, is using the same pages that are currently charged to cgroup A, so it keeps taxing cgroup A for its use. When cgroup A dies, and these pages are reparented to A's parent, can we possibly mark these reparented pages (maybe in the page tables somewhere) so that next time they get accessed we recharge them to B instead (possibly asynchronously)? I don't have much experience about page tables but I am pretty sure they are loaded so maybe there is no room in PTEs for something like this, but I have always wondered about what we can do for this case where a cgroup is consistently using memory charged to another cgroup. Maybe when this memory is reparented is a good point in time to decide to recharge appropriately. It would also fix the reparenty leak to root problem (if it even exists). Thanks again for this work and please excuse my ignorance if any part of what I said doesn't make sense :) > > ```bash > #!/bin/bash > > dd if=3D/dev/zero of=3Dtemp bs=3D4096 count=3D1 > cat /proc/cgroups | grep memory > > for i in {0..2000} > do > mkdir /sys/fs/cgroup/memory/test$i > echo $$ > /sys/fs/cgroup/memory/test$i/cgroup.procs > cat temp >> log > echo $$ > /sys/fs/cgroup/memory/cgroup.procs > rmdir /sys/fs/cgroup/memory/test$i > done > > cat /proc/cgroups | grep memory > > rm -f temp log > ``` > > v5: https://lore.kernel.org/all/20220530074919.46352-1-songmuchun@bytedan= ce.com/ > v4: https://lore.kernel.org/all/20220524060551.80037-1-songmuchun@bytedan= ce.com/ > v3: https://lore.kernel.org/all/20220216115132.52602-1-songmuchun@bytedan= ce.com/ > v2: https://lore.kernel.org/all/20210916134748.67712-1-songmuchun@bytedan= ce.com/ > v1: https://lore.kernel.org/all/20210814052519.86679-1-songmuchun@bytedan= ce.com/ > RFC v4: https://lore.kernel.org/all/20210527093336.14895-1-songmuchun@byt= edance.com/ > RFC v3: https://lore.kernel.org/all/20210421070059.69361-1-songmuchun@byt= edance.com/ > RFC v2: https://lore.kernel.org/all/20210409122959.82264-1-songmuchun@byt= edance.com/ > RFC v1: https://lore.kernel.org/all/20210330101531.82752-1-songmuchun@byt= edance.com/ > > v6: > - Collect Acked-by and Reviewed-by from Roman and Michal Koutn=C3=BD. Th= anks. > - Rebase to mm-unstable. > > v5: > - Lots of improvements from Johannes, Roman and Waiman. > - Fix lockdep warning reported by kernel test robot. > - Add two new patches to do code cleanup. > - Collect Acked-by and Reviewed-by from Johannes and Roman. > - I didn't replace local_irq_disable/enable() to local_lock/unlock_irq()= since > local_lock/unlock_irq() takes an parameter, it needs more thinking to = transform > it to local_lock. It could be an improvement in the future. > > v4: > - Resend and rebased on v5.18. > > v3: > - Removed the Acked-by tags from Roman since this version is based on > the folio relevant. > > v2: > - Rename obj_cgroup_release_kmem() to obj_cgroup_release_bytes() and the > dependencies of CONFIG_MEMCG_KMEM (suggested by Roman, Thanks). > - Rebase to linux 5.15-rc1. > - Add a new pacth to cleanup mem_cgroup_kmem_disabled(). > > v1: > - Drop RFC tag. > - Rebase to linux next-20210811. > > RFC v4: > - Collect Acked-by from Roman. > - Rebase to linux next-20210525. > - Rename obj_cgroup_release_uncharge() to obj_cgroup_release_kmem(). > - Change the patch 1 title to "prepare objcg API for non-kmem usage". > - Convert reparent_ops_head to an array in patch 8. > > Thanks for Roman's review and suggestions. > > RFC v3: > - Drop the code cleanup and simplification patches. Gather those patches > into a separate series[1]. > - Rework patch #1 suggested by Johannes. > > RFC v2: > - Collect Acked-by tags by Johannes. Thanks. > - Rework lruvec_holds_page_lru_lock() suggested by Johannes. Thanks. > - Fix move_pages_to_lru(). > > Muchun Song (11): > mm: memcontrol: remove dead code and comments > mm: rename unlock_page_lruvec{_irq, _irqrestore} to > lruvec_unlock{_irq, _irqrestore} > mm: memcontrol: prepare objcg API for non-kmem usage > mm: memcontrol: make lruvec lock safe when LRU pages are reparented > mm: vmscan: rework move_pages_to_lru() > mm: thp: make split queue lock safe when LRU pages are reparented > mm: memcontrol: make all the callers of {folio,page}_memcg() safe > mm: memcontrol: introduce memcg_reparent_ops > mm: memcontrol: use obj_cgroup APIs to charge the LRU pages > mm: lru: add VM_WARN_ON_ONCE_FOLIO to lru maintenance function > mm: lru: use lruvec lock to serialize memcg changes > > fs/buffer.c | 4 +- > fs/fs-writeback.c | 23 +- > include/linux/memcontrol.h | 218 +++++++++------ > include/linux/mm_inline.h | 6 + > include/trace/events/writeback.h | 5 + > mm/compaction.c | 39 ++- > mm/huge_memory.c | 153 ++++++++-- > mm/memcontrol.c | 584 +++++++++++++++++++++++++++------= ------ > mm/migrate.c | 4 + > mm/mlock.c | 2 +- > mm/page_io.c | 5 +- > mm/swap.c | 49 ++-- > mm/vmscan.c | 66 ++--- > 13 files changed, 776 insertions(+), 382 deletions(-) > > > base-commit: 882be1ed6b1b5073fc88552181b99bd2b9c0031f > -- > 2.11.0 > >