Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp120330rwb; Wed, 14 Dec 2022 14:53:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7FBTeQYOGzpHMj4TT3j00Z976Bh3r0FNWlSFT5cQ4PAa9ecoRD0PCS74vJ/l7byCPhgJqt X-Received: by 2002:a62:be0c:0:b0:56c:410f:7db8 with SMTP id l12-20020a62be0c000000b0056c410f7db8mr24409006pff.28.1671058434330; Wed, 14 Dec 2022 14:53:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671058434; cv=none; d=google.com; s=arc-20160816; b=LwCHb16EAURecqZFBAK5OnPtUTP405Vo08FjnzAVgJtwnPErN9HMOzLb98dQfNnC89 fyhW2dTzjKKqkrU2/g98MEAd8bVz3IVgixHU71xOIK5Z0SJsN2+1UR+85IDDrKEdQR/o TFhG+PDMfwkn1VhawyhGq3zrgpH7f740d3bJnCGxUzjXOzTgf/6hkgbccJdOH0z02c+m wIIfoY8Q2rVbhusCT/W7dGcaoIW8/z2KSGF5vp+D6qbihu3OARBO6OUX8QTnDcAzL6Yi ImTsnbIn7lzMvEADw9zTzb23BK3PVmB14QJpL/XPk5qAYW2wYCJvK4T3EyWOlCRkZ7zI wxYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=nWNYEkPGu4xeEk865eL9sMmuW2qvvMiYdO6LZIHyaa0=; b=ZNIgeTBiwjXPVfAJnTdFJ/bqK6wNMUzEXhaq0gYFrh1DK9kA6BXs22z5BaIBEPpy00 EhhdwJSU5o05hB8rrOBBMKRWzUUWJRSYL1qz/GB8ukvCbKdcqOdU38B5sNATc6Dovueh 67urxX1pNVH6c7wHFvqYFTyzZVyzpXN4hgCR65p/6MY9g3pr7XA/JnDnermnj5ECA14s RUwVXH0WMv6LdA8JfiGw9guDfJn4haX6PrvdGnb4y3uwb0naAm0wETTJ6G9aJZW8IxQw sAhkVwlcQ1cWJ9tEiTCYcViM8KemtWq9FegBzMJUrp44L+j6MSl2TGstX8PBssP0igrA mOzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=myX2b9us; 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 u20-20020aa78394000000b005731d316830si925404pfm.23.2022.12.14.14.53.26; Wed, 14 Dec 2022 14:53:54 -0800 (PST) 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=myX2b9us; 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 S229562AbiLNWvt (ORCPT + 70 others); Wed, 14 Dec 2022 17:51:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbiLNWvo (ORCPT ); Wed, 14 Dec 2022 17:51:44 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86E93723F for ; Wed, 14 Dec 2022 14:51:42 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3b0af5bcbd3so15728137b3.0 for ; Wed, 14 Dec 2022 14:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nWNYEkPGu4xeEk865eL9sMmuW2qvvMiYdO6LZIHyaa0=; b=myX2b9usISZoaAY5lU77WMryQ3aiX1kl/4FYrRRu2anLDBwXSbsBolikYQkFrE5uPw lKs2zBenkmqM7nk4VAPKqxphYh/C85VVm75JcjKuqBNO7N+RCTdsu9AKHgx8EHirHk0T w2r7juJ9kckYckm1i+vB7kURLm7hD2ScKtVQmsSW++IEbyOuNS0oIEenv3GT7xAIZGOX ggQX/lJ0VWmWQKS79OFshXSdsQBIsO8T5XlIfMQRtVy0cVtOKlhsA0DnGU5/gGbBUU/V Sl08VGAI9QDRgV8KEgh9sUbJzjvAOu6YVO6tvrm43b8SdqxmfkyWf4RSUf6hEhzEtctS GUpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nWNYEkPGu4xeEk865eL9sMmuW2qvvMiYdO6LZIHyaa0=; b=WszX4xfTnOVNOVhLy7F33SjCnMqt92zwTEO24ewBR9HkurXQ3pI/wU9kIU0ajOG5Xl jRCB6e8i7XrYKW0hc29Shrzif28m5F5EUK3ewyD/a65RCvKvJf19MlnOQQufws11ByAw XOVPRvvGVf3CQ+clBy9/spOgEQPtMTU24KtkWGn8JxKI0s4ST+pK5hwri79G443whSrs sdnXkTyafpKHGSQb/8EbphTKGJX6DNGH4vS6GLbyNJ1s3izl3cbKEKqbKuVS4OLXpxn3 SnhjRRJ3tQHvxmMcPKuPpXYxxkYX5nwyA1WO0MFlgnurcoQkQ6/l8b9WE5IAJHChAf4K wKVQ== X-Gm-Message-State: ANoB5pkZozUSgbqEB9hYFg54c1SLfD4lXTsoZCrEzokeUQc24V35LRSm RaoFNjp6Y/eSbCtWHkO69Hb3Kww7oMiR X-Received: from yuanchu.svl.corp.google.com ([2620:15c:2d4:203:1311:60bc:9e2a:ab1]) (user=yuanchu job=sendgmr) by 2002:a81:7b06:0:b0:3d8:677e:29e with SMTP id w6-20020a817b06000000b003d8677e029emr38045398ywc.410.1671058302001; Wed, 14 Dec 2022 14:51:42 -0800 (PST) Date: Wed, 14 Dec 2022 14:51:21 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221214225123.2770216-1-yuanchu@google.com> Subject: [RFC PATCH 0/2] mm: multi-gen LRU: working set extensions From: Yuanchu Xie To: Johannes Weiner , Michal Hocko , Roman Gushchin , Yu Zhao Cc: Andrew Morton , Shakeel Butt , Muchun Song , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Yuanchu Xie Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 Introduce a way of monitoring the working set of a workload, per page type and per NUMA node, with granularity in minutes. It has page-level granularity and minimal memory overhead by building on the Multi-generational LRU framework, which already has most of the infrastructure and is just missing a useful interface. MGLRU organizes pages in generations, where an older generation contains colder pages, and aging promotes the recently used pages into the young generation and creates a new one. The working set size is how much memory an application needs to keep working, the amount of "hot" memory that's frequently used. The only missing pieces between MGLRU generations and working set estimation are a consistent aging cadence and an interface; we introduce the two additions. Periodic aging ====== MGLRU Aging is currently driven by reclaim, so the amount of time between generations is non-deterministic. With memcgs being aged regularly, MGLRU generations become time-based working set information. - memory.periodic_aging: a new root-level only file in cgroupfs Writing to memory.periodic_aging sets the aging interval and opts into periodic aging. - kold: a new kthread that ages memcgs based on the set aging interval. Page idle age stats ====== - memory.page_idle_age: we group pages into idle age ranges, and present the number of pages per node per pagetype in each range. This aggregates the time information from MGLRU generations hierarchically. Use case: proactive reclaimer ====== The proactive reclaimer sets the aging interval, and periodically reads the page idle age stats, forming a working set estimation, which it then calculates an amount to write to memory.reclaim. With the page idle age stats, a proactive reclaimer could calculate a precise amount of memory to reclaim without continuously probing and inducing reclaim. A proactive reclaimer that uses a similar interface is used in the Google data centers. Use case: workload introspection ====== A workload may use the working set estimates to adjust application behavior as needed, e.g. preemptively killing some of its workers to avoid its working set thrashing, or dropping caches to fit within a limit. It can also be valuable to application developers, who can benefit from an out-of-the-box overview of the application's usage behaviors. TODO List ====== - selftests - a userspace demonstrator combining periodic aging, page idle age stats, memory.reclaim, and/or PSI Open questions ====== - MGLRU aging mechanism has a flag called force_scan. With force_scan=false, invoking MGLRU aging when an lruvec has a maximum number of generations does not actually perform aging. However, with force_scan=true, MGLRU moves the pages in the oldest generation to the second oldest generation. The force_scan=true flag also disables some optimizations in MGLRU's page table walks. The current patch sets force_scan=true, so that periodic aging would work without a proactive reclaimer evicting the oldest generation. - The page idle age format uses a fixed set of time ranges in seconds. I have considered having it be based on the aging interval, or just compiling the raw timestamps. With the age ranges based on the aging interval, a memcg that's undergoing memcg reclaim might have its generations in the 10 seconds range, and a much longer aging interval would obscure this fact. The raw timestamps from MGLRU could lead to a very large file when aggregated hierarchically. Yuanchu Xie (2): mm: multi-gen LRU: periodic aging mm: multi-gen LRU: cgroup working set stats include/linux/kold.h | 44 ++++++++++ include/linux/mmzone.h | 4 +- mm/Makefile | 3 + mm/kold.c | 150 ++++++++++++++++++++++++++++++++ mm/memcontrol.c | 188 +++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 35 +++++++- 6 files changed, 422 insertions(+), 2 deletions(-) create mode 100644 include/linux/kold.h create mode 100644 mm/kold.c -- 2.39.0.314.g84b9a713c41-goog