From patchwork Tue Feb 14 03:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "T.J. Alumbaugh" X-Patchwork-Id: 13139348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B05BC05027 for ; Tue, 14 Feb 2023 03:55:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F5EB6B0078; Mon, 13 Feb 2023 22:54:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A733280004; Mon, 13 Feb 2023 22:54:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E65280001; Mon, 13 Feb 2023 22:54:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6177C6B0078 for ; Mon, 13 Feb 2023 22:54:59 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3514C1C6441 for ; Tue, 14 Feb 2023 03:54:59 +0000 (UTC) X-FDA: 80464531518.28.6D7664E Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 6948C18000F for ; Tue, 14 Feb 2023 03:54:57 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DNQ50Sta; spf=pass (imf06.hostedemail.com: domain of 3EAbrYwgKCO0iPajbQPjVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--talumbau.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=3EAbrYwgKCO0iPajbQPjVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--talumbau.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676346897; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M7z7DhJJ7GQp6CX5gwTveavGyOgqeiEEFMgrBGxLBZ8=; b=QGSn/IzYWm0G5Bd141/f59DT1kNjnuC9RtPAu5z9LWsW72ylDbRgKDrNQLIpXfM2TQ04Iy OCZYeJOP5d9FUhjq/l8nEgAJDXhYCZaPEIeUmPfTq2FOflHDoSVvlyes32hSJp1VsjAEtU mlLRO0FV9zLjzVnOqdmYo+DXK1v21jM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DNQ50Sta; spf=pass (imf06.hostedemail.com: domain of 3EAbrYwgKCO0iPajbQPjVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--talumbau.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=3EAbrYwgKCO0iPajbQPjVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--talumbau.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676346897; a=rsa-sha256; cv=none; b=ESN13VX/w9psCXW+E5QH5YJ1LWj+uu3WfH8drsLlUgqOTgrPVaL5B/ezapyAl4mjLAfUV5 cfBFdcEcNDUibkAnilMrRXpggtmLS/z6wt+ABJvTcyWY8keH2eOHK9j//qJvWnohzfO6it eqlUlrLh9/zohQ4tiAsERNEOH4NBkQc= Received: by mail-il1-f201.google.com with SMTP id b8-20020a920b08000000b00315565cf4b2so1382649ilf.1 for ; Mon, 13 Feb 2023 19:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=M7z7DhJJ7GQp6CX5gwTveavGyOgqeiEEFMgrBGxLBZ8=; b=DNQ50StaD0fjmUsChg+gdyZp+khgLhAxfrWnJb2OjAvyrOWHpTYym5niXksLMEJ48x BFErgHn8aGfTbHqafwyUa+VSRZMfJwNGCIxqG8OfEHYlw+yRb1MLm/hOBe4f395C77aS 8o8OrnaN+u5BXtjEcUB5UxWiVYbSKJJXRBfRQJwjc245KCkYJcXUBmS0XQlJf0QNXJgt 26nrLQVjHocIy1JIQXEKFZZeyDCQ+PJ1u48kYdY0zT7qb6xgcy3KPPoD2wZ337KrikqS C7DCmeU96uqcKBYo2fglHR6luPpVgGamDa7H/Gr2E071d0jxmUgB8Sl5pmiGqHgDLx78 VpHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M7z7DhJJ7GQp6CX5gwTveavGyOgqeiEEFMgrBGxLBZ8=; b=qEIR1ISw11oJLmvUvnouvsaQOa+FOLyLFJ1Wv0rQm7hbDxotVQpLCbJcnC7xxEgWDZ Lz4gjN4ZoPIWhZaIKzv3FZCfleu3Pd0JFvT3rB896R3gdFC6r1v0JriDzPmB6Tnvuh0c jSNgvpiiMixloy3P/JvHBDQmNIVaIYdfEsE+adpRWOFidXZra53LDhT+grE4SpHX38Kr cXYm7G53yxN8VBIIy8Onlci2Ob11JJMKUu8rMhGy0REDj6ymWJ95dtyufrBlgQSw1oCY S0hBcgIUDx8Kyp59FKqQnjNbphYgV4NHVfSd4yobJE+2g5itOf1iAew1IjMkuFzGG4xy ykhQ== X-Gm-Message-State: AO0yUKWLvQRVmxm5DNN8F3PSSPHJsHDd4XCbk/pHu9tDTNvWiwbLqOPX GGkuHCnSOV+BolCmoiUVGspCC5U9bPEhqQ== X-Google-Smtp-Source: AK7set8/q1DBAyzD2gxm/b23P4hXajELnAW83AEicocg/SCqMKehiAlBF9FRSqCCo2kQBEB9XFjy0MU/dkxFHQ== X-Received: from talumbau.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:90d]) (user=talumbau job=sendgmr) by 2002:a6b:4a13:0:b0:740:694b:54b2 with SMTP id w19-20020a6b4a13000000b00740694b54b2mr112310iob.21.1676346896619; Mon, 13 Feb 2023 19:54:56 -0800 (PST) Date: Tue, 14 Feb 2023 03:54:45 +0000 In-Reply-To: <20230214035445.1250139-1-talumbau@google.com> Mime-Version: 1.0 References: <20230214035445.1250139-1-talumbau@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230214035445.1250139-2-talumbau@google.com> Subject: [PATCH mm-unstable v1 2/2] mm: multi-gen LRU: improve design doc From: "T.J. Alumbaugh" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, "T.J. Alumbaugh" X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6948C18000F X-Stat-Signature: fiy3s7wmnntytctt4q6ubqok8pqdfsge X-HE-Tag: 1676346897-950504 X-HE-Meta: U2FsdGVkX1/uqf9UbHKbHnKnx2oFzADF9UamxjoSPxlEsfPdCpwXYQoaL4ApCHD7NhS89HMKv6Mk7gUF7ZRHwKt3LYV5W0DyU8uCZV3aNiP85a++wLzQZwW/0JI7Cib59ToDjXB/8+BehGt5otdsezG/tshAmBN2W0mcMGNtoSh0sBzDoy0hi4uY5LjR+edzPexw30ad6Eea4HKK2fNeZ2IPWvSyayDyR78I0/81Gt5yfpVtSd8ktrY8kB1PW6QrPa0qwPo4iwhaXMiNRDsTxdeZDlE2v4lXqoyAHRJDPU8Rdm+A+s2sBIDtK+ChQBNYN3cSTaU36xvKcKHHYGPlSBWVoyZhIPBU4xGiZ2zc6LkY2zxJMJb+js2mpmU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BmcAytX4FX/R5fzC5bhhfsQRNN6V2wJE4xoTIySqcctLSQiuNZvViF2pPEl9WaEozs40XP1Qhk7Yqt9lQ2xm+EDsgUc3WJGZxWKNEd54wjoQJvl+Ajh/t/cG9MJ6d3sUOUVwtNIVbLNn8+AkcDEN1LypSVins+ERK2AMNLpelDRzgJjvNU3RwaTfCI= 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 improves the design doc. Specifically, 1. add a section for the per-memcg mm_struct list, and 2. add a section for the PID controller. Signed-off-by: T.J. Alumbaugh --- Documentation/mm/multigen_lru.rst | 44 +++++++++++++++++++++++++++---- mm/vmscan.c | 2 +- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Documentation/mm/multigen_lru.rst b/Documentation/mm/multigen_lru.rst index 5f1f6ecbb79b..52ed5092022f 100644 --- a/Documentation/mm/multigen_lru.rst +++ b/Documentation/mm/multigen_lru.rst @@ -103,7 +103,8 @@ moving across tiers only involves atomic operations on ``folio->flags`` and therefore has a negligible cost. A feedback loop modeled after the PID controller monitors refaults over all the tiers from anon and file types and decides which tiers from which types to -evict or protect. +evict or protect. The desired effect is to balance refault percentages +between anon and file types proportional to the swappiness level. There are two conceptually independent procedures: the aging and the eviction. They form a closed-loop system, i.e., the page reclaim. @@ -156,6 +157,27 @@ This time-based approach has the following advantages: and memory sizes. 2. It is more reliable because it is directly wired to the OOM killer. +``mm_struct`` list +------------------ +An ``mm_struct`` list is maintained for each memcg, and an +``mm_struct`` follows its owner task to the new memcg when this task +is migrated. + +A page table walker iterates ``lruvec_memcg()->mm_list`` and calls +``walk_page_range()`` with each ``mm_struct`` on this list to scan +PTEs. When multiple page table walkers iterate the same list, each of +them gets a unique ``mm_struct``, and therefore they can run in +parallel. + +Page table walkers ignore any misplaced pages, e.g., if an +``mm_struct`` was migrated, pages left in the previous memcg will be +ignored when the current memcg is under reclaim. Similarly, page table +walkers will ignore pages from nodes other than the one under reclaim. + +This infrastructure also tracks the usage of ``mm_struct`` between +context switches so that page table walkers can skip processes that +have been sleeping since the last iteration. + Rmap/PT walk feedback --------------------- Searching the rmap for PTEs mapping each page on an LRU list (to test @@ -170,7 +192,7 @@ promotes hot pages. If the scan was done cacheline efficiently, it adds the PMD entry pointing to the PTE table to the Bloom filter. This forms a feedback loop between the eviction and the aging. -Bloom Filters +Bloom filters ------------- Bloom filters are a space and memory efficient data structure for set membership test, i.e., test if an element is not in the set or may be @@ -186,6 +208,18 @@ is false positive, the cost is an additional scan of a range of PTEs, which may yield hot pages anyway. Parameters of the filter itself can control the false positive rate in the limit. +PID controller +-------------- +A feedback loop modeled after the Proportional-Integral-Derivative +(PID) controller monitors refaults over anon and file types and +decides which type to evict when both types are available from the +same generation. + +The PID controller uses generations rather than the wall clock as the +time domain because a CPU can scan pages at different rates under +varying memory pressure. It calculates a moving average for each new +generation to avoid being permanently locked in a suboptimal state. + Memcg LRU --------- An memcg LRU is a per-node LRU of memcgs. It is also an LRU of LRUs, @@ -223,9 +257,9 @@ parts: * Generations * Rmap walks -* Page table walks -* Bloom filters -* PID controller +* Page table walks via ``mm_struct`` list +* Bloom filters for rmap/PT walk feedback +* PID controller for refault feedback The aging and the eviction form a producer-consumer model; specifically, the latter drives the former by the sliding window over diff --git a/mm/vmscan.c b/mm/vmscan.c index 09c064accdb1..43e69dc8b4bd 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3604,7 +3604,7 @@ static bool iterate_mm_list_nowalk(struct lruvec *lruvec, unsigned long max_seq) } /****************************************************************************** - * refault feedback loop + * PID controller ******************************************************************************/ /*