From patchwork Wed Dec 13 01:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 13490269 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 1FBABC4167B for ; Wed, 13 Dec 2023 01:38:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 585FA8D0010; Tue, 12 Dec 2023 20:38:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 536A28D0009; Tue, 12 Dec 2023 20:38:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D6AB8D0010; Tue, 12 Dec 2023 20:38:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2917F8D0009 for ; Tue, 12 Dec 2023 20:38:40 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CD223A2114 for ; Wed, 13 Dec 2023 01:38:39 +0000 (UTC) X-FDA: 81560085558.03.0604841 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf05.hostedemail.com (Postfix) with ESMTP id 2021610001D for ; Wed, 13 Dec 2023 01:38:37 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EFPv30Ln; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702431518; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=gVAw6lRJ7pahWlf8sMC/DMXTEVU+Aq26rrCAm60sOZA=; b=Z1VoLgfZirURh0GJ9b2upvGLO0yp6VtskSxIyNAK/rrHMDB+pI0dMhcTMfKmgdIs0CAPJd +8TOx0WCMNm2MdNDTkPp75kAbtVStpPev5watR02/2xzi2fBm2XL1JAQ6aTYpmARKpD3HP FE/zzSZujkKBYylwt6WA6CRwTaDPqTU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EFPv30Ln; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702431518; a=rsa-sha256; cv=none; b=TYq0qM1CGNba0zJCnikZGAkxn3iM2c8jHNknnaIVbg33fVc+e+xbf/QedeQWpAX0SvKhfD vihv4r2x5OPvwtTuy5rAdGtX9GaaBbGob2KrxXoIQZQPUiEXVmQCKonvoPKP8EjbMVRame lLAinrGhpNbEMdkhkOa/ZuC8Q20CciM= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d32c5ce32eso17912025ad.0 for ; Tue, 12 Dec 2023 17:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702431517; x=1703036317; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gVAw6lRJ7pahWlf8sMC/DMXTEVU+Aq26rrCAm60sOZA=; b=EFPv30LnCJEFaDqRMXv4YYVZsQkchimev612LxBnBdVMg3xsRgcO3DbNn542nljYDi Kj7NuMaHHAaREy9KMZL2ClW1ybPRfGUaDtMg4vD/NSakGgcwt0Kdysc0Ciu+easNhnAF e6mXXnUJ0vkyq42IiM4yKql26/nz5vZ8SEw1867slO77s8KoxRclEOdQQWehfgHH9v8b PXgEwqCfB7qJpbqt3UF5PUUn9Kwt7o1e4U/P0cRZ69+OZ5/s0RBLjxt2v4n2722cJSOj m1WiR44x3EeIkNdVeagQU6yn4hzsLGENvcBld/f6oKPjtVnL/a17INqN0veYiWm+yWsR uYFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702431517; x=1703036317; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gVAw6lRJ7pahWlf8sMC/DMXTEVU+Aq26rrCAm60sOZA=; b=U15rmIQ6ogka+yyENyJ9bAsjD/Gxwg5fhUrFh9CKcOnsVKaOqyXPD0XQIScjtHPeF7 Q1Dx4CBS26xtmEsBF2T5iUzEOSF9K1xKqOq9QMQjZXfeDE1rvr8GGAqQq3a4/NPTsF5F HtZqz8HItglLu8p5El+VFH6g8X+ubT5oNR+KytC4ZpZFGFnYgdXHmeUcWLhZFUhkyU5S JTwndlrGWOBWOGjRGHF4WUFkXps19vs4EqdngdMRTj/ByEea0x/zQgQ5LVJ6kkn7PUPR CQlJg9uu0JxSYxOgKKX2RYqvu8YPs3GnSZGtj865uyhRR9p9CdfgR1iidEMKtYK9sQ/E YePw== X-Gm-Message-State: AOJu0YzmyCiTjVzHZEKVEdQU1niVvMivcTW9P7GR0Cz5vlMudNGZgtlC 5QkydzXLEpP8BfEfpsWI9XE= X-Google-Smtp-Source: AGHT+IG+Utuvu8ZvE9vrymMXlr3GYp04H1W7WNZnphwE7A9ZGjxfEuhstXGM/YzQUUo4jJbO2uKA9g== X-Received: by 2002:a17:902:c081:b0:1cf:f868:5b8c with SMTP id j1-20020a170902c08100b001cff8685b8cmr7770470pld.8.1702431516563; Tue, 12 Dec 2023 17:38:36 -0800 (PST) Received: from localhost ([2620:10d:c090:500::7:1c76]) by smtp.gmail.com with ESMTPSA id b18-20020a170902d51200b001cf511aa772sm9254767plg.145.2023.12.12.17.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:38:34 -0800 (PST) From: Dan Schatzberg To: Johannes Weiner , Roman Gushchin , Yosry Ahmed , Huan Yang Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Tejun Heo , Zefan Li , Jonathan Corbet , Michal Hocko , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Chris Li , Kefeng Wang , Dan Schatzberg , Hugh Dickins , Yue Zhao Subject: [PATCH V4 0/1] Add swappiness argument to memory.reclaim Date: Tue, 12 Dec 2023 17:38:01 -0800 Message-Id: <20231213013807.897742-1-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2021610001D X-Stat-Signature: kzusrznhw44rp1k5dh44g49r5gddapug X-HE-Tag: 1702431517-608731 X-HE-Meta: U2FsdGVkX1/rJO9j1GlsE/iNpYMGfMwEmGBhU6+FRj5hFYKNTZaPFAN5WG5XMPd/OOlatYq2/ginfHI5swdCmNkADAVALiaxZqhBowe4h2hj0cQNV0tcecGYX4iRq0FTn58H08sEGgY0D8MIgPZO5fXoJHclNWhvPLVkScEJrRbgyR1iZFBCP62vukuTqm0qYNFFcf1Rv3Nu2JuJBT4xK7sKneS8Jc0QJ1OgIvIOn0HNGnDFbMX5bjeC9Xffr437pcYZc9P8FIGQ7L4MV5dLLNAEGZ4d2UsXIhQ2yypmsEM1B33o+IMMutocAO5an8nfbWywbSMER0acLftIHtpmSKJio47z95yV9M4a/2EYlctSSeEIDiiTXPiJMm/rqjeJI9Wr5JVqUipKB3gQRKCclJAW/MrqZbLYab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ZehxXvJ3W2ghHDlLsezAV5vimsP2ZSEYhIEyFoKDNr9vIO8GlMJleBQ4AdXwSqUTYyNzdJxQ2ETLdgi/kEvIFhDei8bfe5yKonJRMtmkQxlY+OL1QuVTKmGUZJqZwil0VxAYHddW3Jvu1Gs5QI143MG8kG5INQdcI4pUdYsTJBiUNvocqZ/2DzeodsTHN5FWNq97uN56NkkZ1++i2iIhM/3qZH+QNp5ImAheRA/ZenE4KTTfMvd3HiyNbgYB9VZy6lfEUv25AXg= 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 since V3: * Added #define for MIN_SWAPPINESS and MAX_SWAPPINESS * Added explicit calls to mem_cgroup_swappiness Changes since V2: * No functional change * Used int consistently rather than a pointer Changes since V1: * Added documentation This patch proposes augmenting the memory.reclaim interface with a swappiness= argument that overrides the swappiness value for that instance of proactive reclaim. Userspace proactive reclaimers use the memory.reclaim interface to trigger reclaim. The memory.reclaim interface does not allow for any way to effect the balance of file vs anon during proactive reclaim. The only approach is to adjust the vm.swappiness setting. However, there are a few reasons we look to control the balance of file vs anon during proactive reclaim, separately from reactive reclaim: * Swapout should be limited to manage SSD write endurance. In near-OOM situations we are fine with lots of swap-out to avoid OOMs. As these are typically rare events, they have relatively little impact on write endurance. However, proactive reclaim runs continuously and so its impact on SSD write endurance is more significant. Therefore it is desireable to control swap-out for proactive reclaim separately from reactive reclaim * Some userspace OOM killers like systemd-oomd[1] support OOM killing on swap exhaustion. This makes sense if the swap exhaustion is triggered due to reactive reclaim but less so if it is triggered due to proactive reclaim (e.g. one could see OOMs when free memory is ample but anon is just particularly cold). Therefore, it's desireable to have proactive reclaim reduce or stop swap-out before the threshold at which OOM killing occurs. In the case of Meta's Senpai proactive reclaimer, we adjust vm.swappiness before writes to memory.reclaim[2]. This has been in production for nearly two years and has addressed our needs to control proactive vs reactive reclaim behavior but is still not ideal for a number of reasons: * vm.swappiness is a global setting, adjusting it can race/interfere with other system administration that wishes to control vm.swappiness. In our case, we need to disable Senpai before adjusting vm.swappiness. * vm.swappiness is stateful - so a crash or restart of Senpai can leave a misconfigured setting. This requires some additional management to record the "desired" setting and ensure Senpai always adjusts to it. With this patch, we avoid these downsides of adjusting vm.swappiness globally. Previously, this exact interface addition was proposed by Yosry[3]. In response, Roman proposed instead an interface to specify precise file/anon/slab reclaim amounts[4]. More recently Huan also proposed this as well[5] and others similarly questioned if this was the proper interface. Previous proposals sought to use this to allow proactive reclaimers to effectively perform a custom reclaim algorithm by issuing proactive reclaim with different settings to control file vs anon reclaim (e.g. to only reclaim anon from some applications). Responses argued that adjusting swappiness is a poor interface for custom reclaim. In contrast, I argue in favor of a swappiness setting not as a way to implement custom reclaim algorithms but rather to bias the balance of anon vs file due to differences of proactive vs reactive reclaim. In this context, swappiness is the existing interface for controlling this balance and this patch simply allows for it to be configured differently for proactive vs reactive reclaim. Specifying explicit amounts of anon vs file pages to reclaim feels inappropriate for this prupose. Proactive reclaimers are un-aware of the relative age of file vs anon for a cgroup which makes it difficult to manage proactive reclaim of different memory pools. A proactive reclaimer would need some amount of anon reclaim attempts separate from the amount of file reclaim attempts which seems brittle given that it's difficult to observe the impact. [1]https://www.freedesktop.org/software/systemd/man/latest/systemd-oomd.service.html [2]https://github.com/facebookincubator/oomd/blob/main/src/oomd/plugins/Senpai.cpp#L585-L598 [3]https://lore.kernel.org/linux-mm/CAJD7tkbDpyoODveCsnaqBBMZEkDvshXJmNdbk51yKSNgD7aGdg@mail.gmail.com/ [4]https://lore.kernel.org/linux-mm/YoPHtHXzpK51F%2F1Z@carbon/ [5]https://lore.kernel.org/lkml/20231108065818.19932-1-link@vivo.com/ Dan Schatzberg (2): mm: add defines for min/max swappiness mm: add swapiness= arg to memory.reclaim Documentation/admin-guide/cgroup-v2.rst | 19 +++++--- include/linux/swap.h | 5 +- mm/memcontrol.c | 63 ++++++++++++++++++++----- mm/vmscan.c | 21 +++++---- 4 files changed, 80 insertions(+), 28 deletions(-)