From patchwork Tue Jun 4 02:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanchu Xie X-Patchwork-Id: 13684567 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 F3119C25B75 for ; Tue, 4 Jun 2024 02:06:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70E186B0088; Mon, 3 Jun 2024 22:06:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 696416B0089; Mon, 3 Jun 2024 22:06:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50FE66B008A; Mon, 3 Jun 2024 22:06:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 302FA6B0088 for ; Mon, 3 Jun 2024 22:06:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9E84E1A0FC4 for ; Tue, 4 Jun 2024 02:06:09 +0000 (UTC) X-FDA: 82191566058.09.B1F5413 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf25.hostedemail.com (Postfix) with ESMTP id DB47BA0004 for ; Tue, 4 Jun 2024 02:06:07 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="d/9nAvf7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3jnZeZgcKCC8jfLYNSfRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3jnZeZgcKCC8jfLYNSfRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yuanchu.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717466767; 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: references:dkim-signature; bh=rjsptS2Yts9gQuV5Q8ZXK1TfjP+hvA4bC7qdXn/aM28=; b=flDGSfdyfRPDpkOKuT3wABeq0pM0nv87kIO9U5t/s1wjuDBJfXxQgW7nUnyg/e0ikLH+2F K8HE26BLvLdasr5tJH3GJ8BtU+oOx/xpuJIXfGQ4b16E3PSMcse3zWzJTL6CV3kyErvX2p 2Gex9vvO6S1BXtPmWOQobNehFmGtIgo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="d/9nAvf7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3jnZeZgcKCC8jfLYNSfRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3jnZeZgcKCC8jfLYNSfRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yuanchu.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717466767; a=rsa-sha256; cv=none; b=7B/FVMaGdsCmwdpxbFSJdp7lZm85qeWR5RD+jp1ND4ImIeZNgcSsSzkF5XHRgvDbw5LU2B v7v+K4A9ffW6FQRICj3zv4H90N861M/lL9hs3EFVucM5XL/NKIbuFF7/cRgjrvz2ABYGNv tTqbxX3RK9JXaoasHVrAkoCAvFN60rQ= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a084a0573so77919527b3.2 for ; Mon, 03 Jun 2024 19:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717466767; x=1718071567; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rjsptS2Yts9gQuV5Q8ZXK1TfjP+hvA4bC7qdXn/aM28=; b=d/9nAvf7mR6VIq2X+59f5hcM9xgrLmwCyb2868zmF1AIMrydDypoznqvahRNCkt9S9 5aC21ho6lRrUvZhpb2INstDy+fbGXbALyRlG2T4NStUv9SMdBw7BSOhME8fjMzARyEgv y2Y6yhSn4+Y2KVCk4LPoXv/XjzNAGqwJKSN2V3z11yMCBEYXvHyld2g+RYXc0rQnCZcm Plax+gVbavHH4I/lgttvGTN8SnK848pp/EXgAt5nVFxfZmxXj3d3/yuurKWid/UtVV0E zpFuP/cjsvMdTxDVnUwqHl9vg53bfJnK365vT3q+rFWwNmBz0s9A+L6WCqGC/LgFBj5w onFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717466767; x=1718071567; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rjsptS2Yts9gQuV5Q8ZXK1TfjP+hvA4bC7qdXn/aM28=; b=mdtoavCLiApe6YPRQKi4Kt8c4/sos99sMAVpWALYCEVtYzUafDp/7p1CRIIeMoniWA ax1iSnuF/8872O2ovtV2PdixEg4QNfES6D0Kw1QssIH7VbXVoe9zMfu2DUsN2CJYKnOb R9/eE9Pq5HkDh01uIs/9MyTTTNm58fdWKOw/lGLO9ULqlQm4o0w1RVnUtHr+ESK1KoYD 8c2DlQBFNawp169b9zoXkbqKgbw2lFVfBOAqU+Fg7xj+BEcGvxLra1h+IlUsvh1Omwu0 pP1OL0ynmWIiJkDdSxbrTt33oJsKOvvhhq8LwBVYFZktNgxNeQNrMI/+a8CA0f4q+jDf 0Igw== X-Forwarded-Encrypted: i=1; AJvYcCXg50UNEHLVJNGPjhdTG2pxY3FqKJehPUMwkROK9eHqV+SvKmO9dKjv94NBW+CP6sgSwqO6qggXr9hrl8OYyHT8PzU= X-Gm-Message-State: AOJu0YzD/wHPl4Pa6gErYn69FfwVInxfq4FXDOxlSEfYpT5AcdzWCUlj ibxffYwozNQfkyq2X0B+Ogibeppz47sNKMZ467zEmFQKyHsc3cFt9LRylae0SV0FAyXNQM3l2ry 2lMR85w== X-Google-Smtp-Source: AGHT+IG3g3AgqCOlx3jBB4ji1cGSVnGwhhLfCxnWASyuX4xJagCnN4kQSgFzxz93g37nWopgo31fHw42PQJS X-Received: from yuanchu-desktop.svl.corp.google.com ([2620:15c:2a3:200:367f:7387:3dd2:73f1]) (user=yuanchu job=sendgmr) by 2002:a05:690c:85:b0:61b:1dbf:e3f with SMTP id 00721157ae682-62c796486d0mr32737577b3.4.1717466766718; Mon, 03 Jun 2024 19:06:06 -0700 (PDT) Date: Mon, 3 Jun 2024 19:05:41 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240604020549.1017540-1-yuanchu@google.com> Subject: [PATCH v2 0/8] mm: workingset reporting From: Yuanchu Xie To: David Hildenbrand , "Aneesh Kumar K.V" , Khalid Aziz , Henry Huang , Yu Zhao , Dan Williams , Gregory Price , Huang Ying , Muhammad Usama Anjum Cc: Kalesh Singh , Wei Xu , David Rientjes , Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Shuah Khan , Yosry Ahmed , Matthew Wilcox , Sudarshan Rajagopalan , Kairui Song , "Michael S. Tsirkin" , Vasily Averin , Nhat Pham , Miaohe Lin , Qi Zheng , Abel Wu , "Vishal Moola (Oracle)" , Kefeng Wang , Yuanchu Xie , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org X-Rspamd-Queue-Id: DB47BA0004 X-Stat-Signature: 61tazowxa9gwefnuywgdq97nufsq4ign X-Rspam-User: X-Rspamd-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SYEYqqQhG0rKL21cvx3yds6jUVJjBv4eI03udpikRtGOIeHk2NlRmG1aCtXvTgbFGrXbC61UEgCc6LfewvTt9FCvsECoh2kNZg8SPVqr+EzsDQ28K6cUxjGMz/pmTE640XwSNpan8wLkf8tbyBcrqft5QO7ebvKwvE3EnZ8FZbbXJMHxC8NfXwVavOv/7LcCZ39v+k79bNjNlcsWguUXN1JJF3L7jkt6Zk3cqVQkfS4+cvXGCfYq8NJMVv9IG6BA2dZ9UKS4KEH4q4FgmYLJnETO/JomSeEZv1Y2KSUfARpgXwythpU9mX6TqxsYhbGP7nMWnAjRSKQyGQGlHAF1XyWgkIec092FjyqghCECPH60TUdgC+lieQI132IGELcgou9rhTRIvgI3P33vAHDT80mnJC2pfY2NkjaygPYujaB1O+a52eUYLqYfwKRBS8xjUZCfuCvm3he5y9nQU+N9xA6Get5WbqPo+CrPWYPFXZRvyE3DsMF+uup6rnKVBKC5X9jx11ICiCFAqfXzCZUhBbpfmmm010ZyDM8fWtRMYhv7fOz6VVDppXspgK0/HVaQWI1zMBU2QpcCOFcbVLdQWMHn/tVN4iUv5ozGlxYnsXYWt1JKnFDn/a7R22WeAxQrG4eHrkNAuoW59oouO5pqB7BVT+h1lzW96xLDl5UJj5KkAX0bgKKIaEGRxyVkhhlpmzSJSioXUIw9+5EDaQ2CBzmvO2qaj319HDuTjEjk14BYJvBCzy7VdgEDM0SKbXfCz0mCx8EW7VZHTVFWLgSz7Rtz7AMlRRJmslLY= 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: List-Subscribe: List-Unsubscribe: Changes from PATCH v1 -> v2: - Updated selftest to use ksft_test_result_code instead of switch-case (Muhammad Usama Anjum) - Included more use cases in the cover letter (Huang, Ying) - Added documentation for sysfs and memcg interfaces - Added an aging-specific struct lru_gen_mm_walk in struct pglist_data to avoid allocating for each lruvec. Changes from RFC v3 -> PATCH v1: - Updated selftest to use ksft_print_msg instead of fprintf(stderr, ...) (Muhammad Usama Anjum) - Included more detail in patch skipping pmd_young with force_scan (Huang, Ying) - Deferred reaccess histogram as a followup - Removed per-memcg page age interval configs for simplicity Changes from RFC v2 -> RFC v3: - Update to v6.8 - Added an aging kernel thread (gated behind config) - Added basic selftests for sysfs interface files - Track swapped out pages for reaccesses - Refactoring and cleanup - Dropped the virtio-balloon extension to make things manageable Changes from RFC v1 -> RFC v2: - Refactored the patchs into smaller pieces - Renamed interfaces and functions from wss to wsr (Working Set Reporting) - Fixed build errors when CONFIG_WSR is not set - Changed working_set_num_bins to u8 for virtio-balloon - Added support for per-NUMA node reporting for virtio-balloon [rfc v1] https://lore.kernel.org/linux-mm/20230509185419.1088297-1-yuanchu@google.com/ [rfc v2] https://lore.kernel.org/linux-mm/20230621180454.973862-1-yuanchu@google.com/ [rfc v3] https://lore.kernel.org/linux-mm/20240327213108.2384666-1-yuanchu@google.com/ This patch series provides workingset reporting of user pages in lruvecs, of which coldness can be tracked by accessed bits and fd references. However, the concept of workingset applies generically to all types of memory, which could be kernel slab caches, discardable userspace caches (databases), or CXL.mem. Therefore, data sources might come from slab shrinkers, device drivers, or the userspace. IMO, the kernel should provide a set of workingset interfaces that should be generic enough to accommodate the various use cases, and be extensible to potential future use cases. The current proposed interfaces are not sufficient in that regard, but I would like to start somewhere, solicit feedback, and iterate. Use cases ========== Job scheduling On overcommitted hosts, workingset information allows the job scheduler to right-size each job and land more jobs on the same host or NUMA node, and in the case of a job with increasing workingset, policy decisions can be made to migrate other jobs off the host/NUMA node, or oom-kill the misbehaving job. If the job shape is very different from the machine shape, knowing the workingset per-node can also help inform page allocation policies. Proactive reclaim Workingset information allows the a container manager to proactively reclaim memory while not impacting a job's performance. While PSI may provide a reactive measure of when a proactive reclaim has reclaimed too much, workingset reporting allows the policy to be more accurate and flexible. Ballooning (similar to proactive reclaim) While this patch series does not extend the virtio-balloon device, balloon policies benefit from workingset to more precisely determine the size of the memory balloon. On desktops/laptops/mobile devices where memory is scarce and overcommitted, the balloon sizing in multiple VMs running on the same device can be orchestrated with workingset reports from each one. Promotion/Demotion If different mechanisms are used for promition and demotion, workingset information can help connect the two and avoid pages being migrated back and forth. For example, given a promotion hot page threshold defined in reaccess distance of N seconds (promote pages accessed more often than every N seconds). The threshold N should be set so that ~80% (e.g.) of pages on the fast memory node passes the threshold. This calculation can be done with workingset reports. To be directly useful for promotion policies, the workingset report interfaces need to be extended to report hotness and gather hotness information from the devices[1]. [1] https://www.opencompute.org/documents/ocp-cms-hotness-tracking-requirements-white-paper-pdf-1 Sysfs and Cgroup Interfaces ========== The interfaces are detailed in the patches that introduce them. The main idea here is we break down the workingset per-node per-memcg into time intervals (ms), e.g. 1000 anon=137368 file=24530 20000 anon=34342 file=0 30000 anon=353232 file=333608 40000 anon=407198 file=206052 9223372036854775807 anon=4925624 file=892892 I realize this does not generalize well to hotness information, but I lack the intuition for an abstraction that presents hotness in a useful way. Based on a recent proposal for move_phys_pages[2], it seems like userspace tiering software would like to move specific physical pages, instead of informing the kernel "move x number of hot pages to y device". Please advise. [2] https://lore.kernel.org/lkml/20240319172609.332900-1-gregory.price@memverge.com/ Implementation ========== Currently, the reporting of user pages is based off of MGLRU, and therefore requires CONFIG_LRU_GEN=y. We would benefit from more MGLRU generations for a more fine-grained workingset report. I will make the generation count configurable in the next version. The workingset reporting mechanism is gated behind CONFIG_WORKINGSET_REPORT, and the aging thread is behind CONFIG_WORKINGSET_REPORT_AGING. Yuanchu Xie (8): mm: multi-gen LRU: ignore non-leaf pmd_young for force_scan=true mm: aggregate working set information into histograms mm: use refresh interval to rate-limit workingset report aggregation mm: report workingset during memory pressure driven scanning mm: extend working set reporting to memcgs mm: add kernel aging thread for workingset reporting selftest: test system-wide workingset reporting Docs/admin-guide/mm/workingset_report: document sysfs and memcg interfaces Documentation/admin-guide/mm/index.rst | 1 + .../admin-guide/mm/workingset_report.rst | 105 ++++ drivers/base/node.c | 6 + include/linux/memcontrol.h | 5 + include/linux/mmzone.h | 9 + include/linux/workingset_report.h | 97 +++ mm/Kconfig | 15 + mm/Makefile | 2 + mm/internal.h | 18 + mm/memcontrol.c | 184 +++++- mm/mm_init.c | 2 + mm/mmzone.c | 2 + mm/vmscan.c | 58 +- mm/workingset_report.c | 561 ++++++++++++++++++ mm/workingset_report_aging.c | 127 ++++ tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 3 + tools/testing/selftests/mm/run_vmtests.sh | 5 + .../testing/selftests/mm/workingset_report.c | 306 ++++++++++ .../testing/selftests/mm/workingset_report.h | 39 ++ .../selftests/mm/workingset_report_test.c | 329 ++++++++++ 21 files changed, 1869 insertions(+), 6 deletions(-) create mode 100644 Documentation/admin-guide/mm/workingset_report.rst create mode 100644 include/linux/workingset_report.h create mode 100644 mm/workingset_report.c create mode 100644 mm/workingset_report_aging.c create mode 100644 tools/testing/selftests/mm/workingset_report.c create mode 100644 tools/testing/selftests/mm/workingset_report.h create mode 100644 tools/testing/selftests/mm/workingset_report_test.c