From patchwork Mon Apr 20 22:11:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 11499933 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9D0814DD for ; Mon, 20 Apr 2020 22:11:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9566A20BED for ; Mon, 20 Apr 2020 22:11:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="W5pshhSf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9566A20BED 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 BF4BB8E0005; Mon, 20 Apr 2020 18:11:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BA5EE8E0003; Mon, 20 Apr 2020 18:11:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6B698E0005; Mon, 20 Apr 2020 18:11:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 884C18E0003 for ; Mon, 20 Apr 2020 18:11:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 48E964DCB for ; Mon, 20 Apr 2020 22:11:40 +0000 (UTC) X-FDA: 76729631160.28.bee07_65d44aeed3331 X-Spam-Summary: 40,2.5,0,2ecd43c7c9eb3311,d41d8cd98f00b204,hannes@cmpxchg.org,,RULES_HIT:41:69:355:379:541:973:988:989:1260:1311:1314:1345:1437:1515:1535:1542:1711:1730:1747:1777:1792:1981:2194:2198:2199:2200:2393:2553:2559:2562:2693:2731:2898:2907:2911:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4250:4425:4605:5007:6261:6653:7808:7875:7903:10011:11026:11232:11473:11658:11914:12043:12296:12297:12517:12519:12663:12683:13053:13161:13229:13548:13894:14096:14394:14721:14819:21080:21444:21450:21627:21740:21939:30012:30054:30056:30070:30075:30090,0,RBL:209.85.219.65:@cmpxchg.org:.lbl8.mailshell.net-62.14.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: bee07_65d44aeed3331 X-Filterd-Recvd-Size: 5902 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Apr 2020 22:11:39 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id t8so3637054qvw.5 for ; Mon, 20 Apr 2020 15:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RujGPQ/aToLYsclK+dnkQViuIsABafgZ1mMvYzjDw+g=; b=W5pshhSfzWc52vhfUDfjZfdL/VdXS7EEmH4WjupWl3cqVRvkzHRdMif9qdTKIowIS8 jtAAJQYEqixojOHZBAwYKYIBNXmiy8H0Znbn4GFingRmwQ/ryMs/wRbcV99z5DKszZwZ GbgekrRWQE4KOkzLdPImbNSlOrGNU8w67KZmcdmNmfQOQVhtUaPVQiBErlyrTzPIcazY BRDGb/AZnkYJcLUppRNHWkNHEhMfWC4TcYa+/yWj+QlRtp3A+M3prGSzj0ZLK2Nu+BF0 flSMwNBRQYoSupuvRlDAnT/pL5UqpV/xfRbMu34r/69y9f8lmUPSyX8hJ2LF1Afg5ZiR aLhA== 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=RujGPQ/aToLYsclK+dnkQViuIsABafgZ1mMvYzjDw+g=; b=OfFHxD0I/1duMa8u0L2zWOjfZsTsUbQs8XKgCPQnwiISXNd6nsloi6B1WJR18v/60p 3u4N9RYhmsIHwZBRdts3n8Apb1obSKYX2FzMdGLqKcBRj9jil49feL7htHnQqkAA2cA+ bD14Mhr5LbgEzA1hc7aaUuRpudKiPJT5r0YvmkYOrLYUbCX6kIkHJg17myUFcetSjH0u YEQmGCeC9GWE6r52Aeht3ls2fonKiebSv4ij4rTBr/7oCnHBBdmaJVfCpBxLZf1z6Y15 yhrsy7IdbIaxGOOYs/7qSupsb1NjVeknRM7IiOUyl2LWWTRKngkZTFqSFodErVlUiL3/ 9HFA== X-Gm-Message-State: AGi0PubbqNnDA5dv+mK9SjRBRQG60wk09+Mc3nzadERA1SCm7o8yuz7V kzhcxCGAw0JmLfhGH7kUTYHeTA== X-Google-Smtp-Source: APiQypKHvBq1G1X6GokIqQMrcn6gfp4oAZoCTpAjG1OT2zuEPvkxv8ga5ahrNVdcrKu2Sq1g82edeQ== X-Received: by 2002:a0c:fd8c:: with SMTP id p12mr17566981qvr.163.1587420698518; Mon, 20 Apr 2020 15:11:38 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:e6b6]) by smtp.gmail.com with ESMTPSA id s125sm622755qkf.9.2020.04.20.15.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 15:11:37 -0700 (PDT) From: Johannes Weiner To: Joonsoo Kim , Alex Shi Cc: Shakeel Butt , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 00/18] mm: memcontrol: charge swapin pages on instantiation Date: Mon, 20 Apr 2020 18:11:08 -0400 Message-Id: <20200420221126.341272-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 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: This patch series reworks memcg to charge swapin pages directly at swapin time, rather than at fault time, which may be much later, or not happen at all. The delayed charging scheme we have right now causes problems: - Alex's per-cgroup lru_lock patches rely on pages that have been isolated from the LRU to have a stable page->mem_cgroup; otherwise the lock may change underneath him. Swapcache pages are charged only after they are added to the LRU, and charging doesn't follow the LRU isolation protocol. - Joonsoo's anon workingset patches need a suitable LRU at the time the page enters the swap cache and displaces the non-resident info. But the correct LRU is only available after charging. - It's a containment hole / DoS vector. Users can trigger arbitrarily large swap readahead using MADV_WILLNEED. The memory is never charged unless somebody actually touches it. - It complicates the page->mem_cgroup stabilization rules In order to charge pages directly at swapin time, the memcg code base needs to be prepared, and several overdue cleanups become a necessity: To charge pages at swapin time, we need to always have cgroup ownership tracking of swap records. We also cannot rely on page->mapping to tell apart page types at charge time, because that's only set up during a page fault. To eliminate the page->mapping dependency, memcg needs to ditch its private page type counters (MEMCG_CACHE, MEMCG_RSS, NR_SHMEM) in favor of the generic vmstat counters and accounting sites, such as NR_FILE_PAGES, NR_ANON_MAPPED etc. To switch to generic vmstat counters, the charge sequence must be adjusted such that page->mem_cgroup is set up by the time these counters are modified. The series is structured as follows: 1. Bug fixes 2. Decoupling charging from rmap 3. Swap controller integration into memcg 4. Direct swapin charging The patches survive a simple swapout->swapin test inside a virtual machine. Because this is blocking two major patch sets, I'm sending these out early and will continue testing in parallel to the review. include/linux/memcontrol.h | 53 +---- include/linux/mm.h | 4 +- include/linux/swap.h | 6 +- init/Kconfig | 17 +- kernel/events/uprobes.c | 10 +- mm/filemap.c | 43 ++--- mm/huge_memory.c | 45 ++--- mm/khugepaged.c | 25 +-- mm/memcontrol.c | 448 ++++++++++++++----------------------------- mm/memory.c | 51 ++--- mm/migrate.c | 20 +- mm/rmap.c | 53 +++-- mm/shmem.c | 117 +++++------ mm/swap_cgroup.c | 6 - mm/swap_state.c | 89 +++++---- mm/swapfile.c | 25 +-- mm/userfaultfd.c | 5 +- 17 files changed, 367 insertions(+), 650 deletions(-)