From patchwork Wed Dec 20 15:26:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 13500244 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 9A1B2C3DA6E for ; Wed, 20 Dec 2023 15:27:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D6836B0075; Wed, 20 Dec 2023 10:27:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05F766B0082; Wed, 20 Dec 2023 10:27:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E42CD6B0088; Wed, 20 Dec 2023 10:27:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CC3806B0075 for ; Wed, 20 Dec 2023 10:27:06 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9671F1A0BF6 for ; Wed, 20 Dec 2023 15:27:06 +0000 (UTC) X-FDA: 81587574852.29.5DB203F Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf12.hostedemail.com (Postfix) with ESMTP id 9FBB740008 for ; Wed, 20 Dec 2023 15:27:04 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gFmGsDg5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.171 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=1703086024; 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=0YmsiHiH2OTheWqPLRpv7rEgYFPWCHei0D2bGMni+hY=; b=iSRvZoIQdhXm9HkEnrl77aLTKmUVylpYparx7lNKP353X6C/zYKEPife58aQEuBKnfYdvw n05wPn39g0LE7/K3JYs4ZLEUCuRlUQGqF09tnXk1nA5cknH/SSFvzTgBfytdQxLoGvcQit i3+vIWV2pTqvhcxL8uXDplqQnJELzIs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gFmGsDg5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703086024; a=rsa-sha256; cv=none; b=CTimbVBcSJAuVF4+OceHhD/Q+nVdrbW1SWneKEjtXQ82h7P/Q7Mzem3drGfgagDvNZ4X/g XqafdAxlB9qoHQs9/QHKToBqyr+5r77NAFnu+egCJkqekCXoFbnc3UDJgQM4LGbH6nXeQZ 3rMVdCFUnx9SnpwVv77NROj3AOybYiE= Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-78113481f91so42895285a.3 for ; Wed, 20 Dec 2023 07:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703086023; x=1703690823; 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=0YmsiHiH2OTheWqPLRpv7rEgYFPWCHei0D2bGMni+hY=; b=gFmGsDg5Z0yu9U86Mr8INyLmpqiQaKyDUbxA+5dITdrJhfQslfYKDWYCQKpCqHw8ed SL6/Yt57I0R1n/Wx6yG5q/ee0LMGMZQDYvzM6E1Ycxb8ajlA2fDerzF+drGVub4Xp6RL AebW8KefqWONiSF1hvNPzZvUK8WIb3hSJVVgesexmbxynZIFZ5flQs2I+h9KjxaZVkr9 MD/NeLcwTuQ58T8uE6WTV+2ft4Yf3EusfkxSLFrWCi4+XbHcdEb2B4/V4QTWsh4+0MRR o21BzFu2T3YsfeXwR+oZvLxgbzEhqAUyhYTenzJVxgWaL96uSfVdVFznLj9kCGM134Th e/Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703086023; x=1703690823; 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=0YmsiHiH2OTheWqPLRpv7rEgYFPWCHei0D2bGMni+hY=; b=epZsuY9wgh5NUGX9A3yLgzHl5P+03JbpVoeLVNXMdU8Gv1aUxEnAMQNfxIbVWtFSbA NJqAFn33E2VIfxqf2oQnCgnlzjffX/Qa8DUEfvU7tojLQHyqG5YBUjiWx3RHqbXA0u20 RdJKcRedlPYeB5IEYfojR5R4TElSbutvVKXCWEmyrfcJdxgr4IKZq8sVkRDlL93OQwpO B1hJro0GdrnWIamr6HYVyr6qAN8amXv5t1BjQI9VNW/d83uxnjr9NqXfJwxCE4Nvy11j 1uuqHuY71e2u6wMK2mr+evHV8VxLBCnhfzx+oGP7JQ2rxPhzhJi2t9t+swkGsMARU9XK DWrA== X-Gm-Message-State: AOJu0Yy4wc4/Vv0/CV2KBLeB3RPS1SL1yM0E6LVXwbt/Ff6a4TCJV/Ud eox1UZXnqFr0zd7w4lTJzO4= X-Google-Smtp-Source: AGHT+IGNYVbytci62dp3FLra4LtlMZv7Z/KCegkh3b9fmkgZpKu25Qtk/Jt7Hk6pQ7MU580U5fb8uw== X-Received: by 2002:a05:6214:b64:b0:67f:7630:2371 with SMTP id ey4-20020a0562140b6400b0067f76302371mr811828qvb.13.1703086023548; Wed, 20 Dec 2023 07:27:03 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:1124]) by smtp.gmail.com with ESMTPSA id ev6-20020a0562140a8600b0067f370c7b04sm3397637qvb.68.2023.12.20.07.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 07:27:03 -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 , Kefeng Wang , Nhat Pham , "Vishal Moola (Oracle)" , Yue Zhao Subject: [PATCH v5 0/2] Add swappiness argument to memory.reclaim Date: Wed, 20 Dec 2023 07:26:49 -0800 Message-Id: <20231220152653.3273778-1-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9FBB740008 X-Stat-Signature: odqwzk78s9izqjyxgy6gy13bsf946zf4 X-HE-Tag: 1703086024-770372 X-HE-Meta: U2FsdGVkX195/f3W6+rKhsLP4amm5DL+PkotbmRGWHBVrovrgV08gIfIhyV1UJuXVLO+ySojl5x9ti5MLVP4lUnY4/bT2b6r2lWIGDivp3szxUXEERZwXXPb8lGp0Fk7TxG3CwBgH1wjlUngHcv2zHukeyPG1iH0o3RCWZGuopcuB2DgsAD3Ub61jNA8WLXBNyR62flWHFfPd8k5WAWPpVYjLS9/9zk1HXFiojufXZ5l9wVRjTN+t1dZTYLEjHki7WopHH/XM1quPlPMYXPIT5MUMqOUmVWa9CFTx/AgzQQbin8mwCSaiTprPdexSEmJzR2anBI++jczyXIe4ZmymXMJC8Spsni7sXX339PN1fjGvN9VqBtl6pHVbr4HckQsf504Pc0wDTiL6ft0K4Kt+8H0IMpf1/JOFeOswa+7UTEAjoRQ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F9HpVlNCV8rLT9H+Nr7daJcbJA58rQUKN7ulp5ez+GWjh4VVt9J3MUNdz4k5kYqv1WJEaYqef/XeejOJvm9re20pmlme5VzQ5SWplvTyay8IFVJ//+h1wy7v/Qm287SNYOooNWHsOXWUscXeSTVFiVEYKQPOeHYwp4gVNFTbKCHcg81WQYynkCSLb14Nxjlugz+JPE1J7kyfXQDDICqi2E6tC7C8AQNb9m3I+fGyXaVHVn38SC2QQk6DPEc7cZfRA= 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 V4: * Fixed some initialization bugs by reverting back to a pointer for swappiness * Added some more caveats to the behavior of swappiness in documentation 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 | 18 +++++--- include/linux/swap.h | 5 ++- mm/memcontrol.c | 58 ++++++++++++++++++++----- mm/vmscan.c | 27 ++++++++---- 4 files changed, 79 insertions(+), 29 deletions(-)