From mboxrd@z Thu Jan 1 00:00:00 1970 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 90D86C4167B for ; Mon, 11 Dec 2023 14:04:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B8F76B00E9; Mon, 11 Dec 2023 09:04:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1428E6B00EA; Mon, 11 Dec 2023 09:04:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F248B6B00EB; Mon, 11 Dec 2023 09:04:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D9F5D6B00E9 for ; Mon, 11 Dec 2023 09:04:35 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 790F3C0887 for ; Mon, 11 Dec 2023 14:04:35 +0000 (UTC) X-FDA: 81554707710.12.B5E6462 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 6D4441C002A for ; Mon, 11 Dec 2023 14:04:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HaqJJaqT; spf=pass (imf18.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702303473; a=rsa-sha256; cv=none; b=OGux24WfV9HZoj9knozeoa5/QldlGvb00pIbX2H5d7/CiFGazjCQFWxhwa9fOee9V0aCh5 WtKuHuijGXSUPHRXJWl9hYtUrXHZ/g81NA/jmAeoHkjS86qHUYS/r8kOFF7Ib9JdavxZRa WZUjkRNCANHGM2lw9YTJpzAm4LsSr5o= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HaqJJaqT; spf=pass (imf18.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702303473; 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=2chFAW6nomfA6igwhAmawml0spzXTHvMGYmVScTgkfQ=; b=07VAGGW/d1LIg+M1diuUzWCAKnFSx/pS5NuvvEDPVQ3bKTjCPa8a6LXbaBQ6TpguflQyfT JmeKWTqST87ZWY92n6OQMmvyDxYENuzgtrM0EBHZ8AM16tlQ6OCYCuIKmC2DUGbKahA5T5 tRBDhVUWemroZw/j4+efZglircW2E9Y= Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-77f642b9a22so131244685a.0 for ; Mon, 11 Dec 2023 06:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702303472; x=1702908272; 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=2chFAW6nomfA6igwhAmawml0spzXTHvMGYmVScTgkfQ=; b=HaqJJaqTXvtAjEVgBiy9+qPp9FRYi6IM95AJEwZ+LKkpm4y14sKHqthHfSKMM7bQDR zaXS0xsc2Dll8voxcq5lA4uEri07HoBXBkmJb7LDfGb5bGtKsxLzQBMgw7b83y/GhRvh o5WMCJoNLoIRhmCE1O9ClkCE4IcYdab61AnOX41xW/LnbjkvyRW2DdzYNL4C1DsSpgH1 wxmSvYelqQRXZjWr9i+aR9hVSxdaan7KPIl7RwAPEBvcaMPmH5XSY7waEUWwCXuakhP+ o4FIPIcNGh7WAk0BopwJIuNSJZO+sMqbhPZjg0aVtRKVYpA5YGvNbh8kDRhvuMJiyGqS rLMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702303472; x=1702908272; 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=2chFAW6nomfA6igwhAmawml0spzXTHvMGYmVScTgkfQ=; b=iC4QaACYweT6p2/5JTWnX2/Iy3PNK28JnhwqpCFxOp/Z3jowRxLpabjk5frJoXSr0f IR2lLbF3Pk/CcmCeN+Eor2TRNY7zqfozp3gn35ht9z7FQetKKRA+c7n3XZXYW8nwqtsZ lBgAK/Mzaa7ZUwVqV9H2ZXDuAfSkt9rImukqzZgRSayPkyi7GewzEWbIQPKEtSmQu04B By34slut1IIBHKXneWi5yENZvw0KR4inFEKFmm4B/OPjLoeP+YJd0X/Ex1WYqbVZ60l3 uC8uFo/jSF42sINCC5R/p7Oh4fJBaowy0A33+IAAdrJ7FmGoJPM/P3i1JtPqGEadm5AQ Dk5A== X-Gm-Message-State: AOJu0YzhJIruKyocOPbP675KqLHgHoN2SRA0TW2Wxs1VB2muVOsw+gmG Fv5WlbWwfuBe5dTjCcoBWe0= X-Google-Smtp-Source: AGHT+IFgRujnHXjXhFSUn7kK/8s7CqS3KVm7yCtPcsrSSVcCgQGpBlc7NlQ4YODBMklLqCFxHk35kg== X-Received: by 2002:ae9:f50b:0:b0:77e:fba3:3e7f with SMTP id o11-20020ae9f50b000000b0077efba33e7fmr5842778qkg.72.1702303472173; Mon, 11 Dec 2023 06:04:32 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:45f0]) by smtp.gmail.com with ESMTPSA id bm33-20020a05620a19a100b0077eff6eece8sm2931655qkb.62.2023.12.11.06.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:04:31 -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 , Kefeng Wang , "Vishal Moola (Oracle)" , Mina Almasry , Yue Zhao , Hugh Dickins Subject: [PATCH V3 0/1] Add swappiness argument to memory.reclaim Date: Mon, 11 Dec 2023 06:04:14 -0800 Message-Id: <20231211140419.1298178-1-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6D4441C002A X-Stat-Signature: ebku3rh7xjifn1obgt6ehbf75i58uqa4 X-Rspam-User: X-HE-Tag: 1702303473-399216 X-HE-Meta: U2FsdGVkX19eM4wds57CC8zksZeMZu/0EKWvvAOuD9vfqtSwQRjhUDT9uxDlPpted4so7xVN7ESyIlGDTz9uln2Y7xHXE8OxTP/qnaLEJrcqEt3LWAS7r9/c4Wa8qT4pLmghY0uAO58EUF7gz5XWcUwiLzOyOynKSvyadArfoUMhu2/cCZ6wsfUhzKNXylNRB/6vyrbAM2vTSbbpvbZNd0YhD15ABSkJ8ZS9jrKudXCGMjXFJmdTKB8SiQ10TsQlBdfoSQPZfSxA1kGuCMx42tbgrw36uYS4Fu1McgwS8ZXXB7KB+JVkt+NDOh+GTk203APnC/xXn15QHK5jTs4fVwtnXZiOoPJNxKyb/jK4MXz+WqLOdnpCIqxYef3/v80mF/z1gVeydp/n/UW6vPFDAZgmlsbpNEKgDrHZ/bB0KwsBAzzQf8NppdalJCrBKdbgTQfpLWeCuu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WNbl9FrBdgfpXVnracmuNkyZW1rGNRpuFKHm9Hrdfhd1uE9VFI28T/zdc5EaG45NDlNpyWW3NtSW3fdI3EKwXmqseURGxWVtFn9b3MpFMDMiRFsLJ8CfOag3vxyDRnzuNr8kA4V20+WCZ9agJdeYgC//fX6qI58INr1h5n5s6wP6Y3xqreGTxC1DSVW5+/wD/dAZUhhFGMNdUwnorhO1UUSXxrE= 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 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 (1): mm: add swapiness= arg to memory.reclaim Documentation/admin-guide/cgroup-v2.rst | 15 ++++++- include/linux/swap.h | 3 +- mm/memcontrol.c | 55 ++++++++++++++++++++----- mm/vmscan.c | 13 +++++- 4 files changed, 70 insertions(+), 16 deletions(-) -- 2.34.1