From patchwork Fri Apr 9 12:29:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12194039 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=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 4162BC433ED for ; Fri, 9 Apr 2021 12:31:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B562B610CA for ; Fri, 9 Apr 2021 12:31:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B562B610CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 39FB06B006E; Fri, 9 Apr 2021 08:31:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34F546B0070; Fri, 9 Apr 2021 08:31:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0586B0071; Fri, 9 Apr 2021 08:31:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id 02E826B006E for ; Fri, 9 Apr 2021 08:31:56 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9CF178248047 for ; Fri, 9 Apr 2021 12:31:56 +0000 (UTC) X-FDA: 78012765432.15.3A90EC9 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf27.hostedemail.com (Postfix) with ESMTP id A9BA980192FB for ; Fri, 9 Apr 2021 12:31:46 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id kk2-20020a17090b4a02b02900c777aa746fso3113435pjb.3 for ; Fri, 09 Apr 2021 05:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fpGPZ/lJV4md7gBypR0OCCiHuyZq6QhPBcCfYgEbJEM=; b=sh/mgJLYQRmgQqkTLmkyeqBnWjzmX2I5489hGKjNCA9muzF5do0dhJVzBP1ATVHIRx Dq0iBxD8XgO5kkLHoXnwiig9phEyFzVFSIinjz5pAXkMGSSbK4/VpowoOMYEf3MgFQsH WPTGvQoGystqgsHXHODZ59kWSvv7GQlSv7e8nJxlpgyvC68Ym1KN0qpaoqQesk4t5ctd 9swBfdviVAyeUbTaZ+6TDk8W0S/jA/NvaN5atJHadAYCjSMtfqSsKXQ2IMfGsWeM+Nyh kKPgup/IvQHBp6mG6mFyPZLHtoeX9IH0SXC9HRnJA7vHCMHdoQfvrEGkkwahFkBF0kpu vY4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fpGPZ/lJV4md7gBypR0OCCiHuyZq6QhPBcCfYgEbJEM=; b=uEJEHmCZHr2I0YUZ0mhGeIs6mUZhKenINnlb42zUf24JkOiyrlCaN6WqdteI1T6t6E jvtYyn+1DbaNdbLsyyRH6JPDK800cbF9TAsmVWIh/pkUDNpa1QU8NHzfvsR8bT8cdDp+ niXzZI2ZvHEIb6Iulb1b8sygm6Dd5Jrs4dOn7WVAfEqqMg8UpZxrG4X28CJQk58/M7Xu W4FnnRcDrTjsSmqLR9h6gspLh4Ygx59PXt5Sch/P9PcofrFfc4TjqDog9vgJZ6yUtDKB 3rbGKIRCirw2BvJTzf7Z2DGNwLOWqKPw6AHKPezu83HVW1wbIl0TUqyxSoIc/eSiOWmx AuKg== X-Gm-Message-State: AOAM530sEtb6KQZFSu1Ag8FSuWTWxsMcnap6HF+MeFc4sAWYid3c6FK/ S34hq26s3ReGU1Ek1XVP8HSrXw== X-Google-Smtp-Source: ABdhPJyT7hPDnhRsvstpcwogIpoqHm14u2ElWSIC9KQSpWaWDTBWQd7RYVX7IxVOSA8SDR6JU/1ptw== X-Received: by 2002:a17:90a:9404:: with SMTP id r4mr13397950pjo.64.1617971512869; Fri, 09 Apr 2021 05:31:52 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id t3sm2167785pfg.176.2021.04.09.05.31.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 05:31:52 -0700 (PDT) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: 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, Muchun Song Subject: [RFC PATCH v2 00/18] Use obj_cgroup APIs to charge the LRU pages Date: Fri, 9 Apr 2021 20:29:41 +0800 Message-Id: <20210409122959.82264-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A9BA980192FB X-Stat-Signature: 83w4tzdbzhpzyq68o3ky598afkawk4kx Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=mail-pj1-f41.google.com; client-ip=209.85.216.41 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617971506-361274 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: 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. Changlogs in RFC v2: 1. Collect Acked-by tags by Johannes. Thanks. 2. Rework lruvec_holds_page_lru_lock() suggested by Johannes. Thanks. 3. Fix move_pages_to_lru(). Muchun Song (18): mm: memcontrol: fix page charging in page replacement mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec mm: memcontrol: simplify lruvec_holds_page_lru_lock mm: memcontrol: simplify the logic of objcg pinning memcg mm: memcontrol: move the objcg infrastructure out of CONFIG_MEMCG_KMEM mm: memcontrol: introduce compact_lock_page_lruvec_irqsave mm: memcontrol: make lruvec lock safe when the LRU pages reparented mm: vmscan: remove noinline_for_stack mm: vmscan: rework move_pages_to_lru() mm: thp: introduce lock/unlock_split_queue{_irqsave}() mm: thp: make deferred split queue lock safe when the LRU pages reparented mm: memcontrol: make all the callers of page_memcg() safe mm: memcontrol: introduce memcg_reparent_ops mm: memcontrol: use obj_cgroup APIs to charge the LRU pages mm: memcontrol: rename {un}lock_page_memcg() to {un}lock_page_objcg() mm: lru: add VM_BUG_ON_PAGE to lru maintenance function mm: lru: use lruvec lock to serialize memcg changes Documentation/admin-guide/cgroup-v1/memory.rst | 2 +- fs/buffer.c | 13 +- fs/fs-writeback.c | 23 +- fs/iomap/buffered-io.c | 4 +- include/linux/memcontrol.h | 216 +++++---- include/linux/mm_inline.h | 6 + mm/compaction.c | 40 +- mm/filemap.c | 2 +- mm/huge_memory.c | 171 ++++++- mm/memcontrol.c | 622 ++++++++++++++++++------- mm/migrate.c | 4 + mm/page-writeback.c | 24 +- mm/page_io.c | 5 +- mm/rmap.c | 14 +- mm/swap.c | 48 +- mm/vmscan.c | 58 ++- mm/workingset.c | 2 +- 17 files changed, 841 insertions(+), 413 deletions(-) Acked-by: Johannes Weiner