From patchwork Wed Dec 6 16:28:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 13482011 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 07599C4167B for ; Wed, 6 Dec 2023 16:29:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D2146B0092; Wed, 6 Dec 2023 11:29:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A9596B0093; Wed, 6 Dec 2023 11:29:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 570A06B0095; Wed, 6 Dec 2023 11:29:22 -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 491056B0092 for ; Wed, 6 Dec 2023 11:29:22 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 10612A01B7 for ; Wed, 6 Dec 2023 16:29:22 +0000 (UTC) X-FDA: 81536928564.09.FA2B7A3 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf26.hostedemail.com (Postfix) with ESMTP id 5482A140019 for ; Wed, 6 Dec 2023 16:29:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PBIbXlP4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.180 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=1701880160; 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=wd9dmNFWVV3wZN+V4jSJjxu24qyO9wHRcayLWIoq474=; b=NEzckWYQrE3dClOp0XsVB16mT1CkVq5sNa8IfOQLXoDXx2N6Zgdy6MFzPPpKG1n/3Zw8WF ++AfQgq1nV5wkxdsXrzU6LlwxJJzWt408Djx8EcvX4NhV9y91l/LSP8cnqNakPKyVsuerB +VXSDXDV3px2JUvlLstIu6IkAmi8NyM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PBIbXlP4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701880160; a=rsa-sha256; cv=none; b=8poQkJKr3tVP7O9UXJ2Y1im/HSz4/x7/Fw7fhH757zANoetfgjkaoRvbNUZXOZCFCAF/DJ qGTaM+mfcd/9n4Sp3x5kGKhuzust1quL8Zb9fR06/of3/ciO453RJ8tXXhtUikyT25llBR G6jiAVrtnP2+TLEav5OshX+YT5Bgyeo= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-77f04969d2eso259950585a.1 for ; Wed, 06 Dec 2023 08:29:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701880159; x=1702484959; 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=wd9dmNFWVV3wZN+V4jSJjxu24qyO9wHRcayLWIoq474=; b=PBIbXlP4FCpQkrFfKMQI2NvVN6wO524bNnJq1qF0vSIdKpqnbgc4YDlFow7OvGDYjG /09VrzVaVlQsVP+Da+S9d7f2kIdezG0EMdrU/FzCrgSPdcwxyC+4gzs5EB7Q3qoL7YE/ TvwDk5xuMCCKxuwXifp8ew0icAPV9+tTz/nm3qomtyeX0DKt+XTOl8nawFunoJ/xdYUS 0DQG/UWMD80MeaLXmq/qRBWWmtTizUwWXJxR3FAUeBwfnqlLVNoYlOFq7z0g92A0KiXQ R0WRdHAJRJKsVTDcYTqBKxYVsQnTbiAb49bQp1uLYaPYRLE1PBkDLLBifCMwxW3IrJcK Xk0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880159; x=1702484959; 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=wd9dmNFWVV3wZN+V4jSJjxu24qyO9wHRcayLWIoq474=; b=pKp9es0g6qBbzWDNOQKm/GjiL2AyjMN3LnCkBtmBBKixzDX+gu22Wuc6oNE4dHuiLy zJQGDFmY4XPuOIvi2ZGggZNIZ4iFJGn84JVRYaacP7zi43stVNVIPsPgQf/sn6+0JYE8 Z8f7a7oa2jxUu+F5PvsYHC/gRknsOrCUS3wVmH4kCF5hmhpNc27NH0N9WIEw7NOFOUTa BCIzbiN5OSNHLBu+b1+3KBb8TD2B/2hV0fJlWYvfZR187D85GK1+FQIb4eOTQLK+kcIN IhbtuNa0Un5h3xYSpGWeXKifFaOMxBntd/NbV3pjk+3rK/oVLKsNIiqCfBtaBqVMLxv2 Yg5Q== X-Gm-Message-State: AOJu0YxBHuDoxa0Xo0JLB78rv4ul+TBGaYrPzpHfvddEnfAvO00jnUDl oBn6ugpbAA988LIcwGa+mpk= X-Google-Smtp-Source: AGHT+IHhiuALx2hZ1zKntduTCjGsG1MfwXfwX9syFNhffyevENPJR9W/FQbEfj2xzCDrmW4Gb0rfuA== X-Received: by 2002:a05:620a:3b07:b0:77f:37e7:bd6e with SMTP id tl7-20020a05620a3b0700b0077f37e7bd6emr396533qkn.121.1701880159169; Wed, 06 Dec 2023 08:29:19 -0800 (PST) Received: from localhost ([2620:10d:c091:500::6:c65f]) by smtp.gmail.com with ESMTPSA id uw5-20020a05620a4d8500b007749dc7881dsm69759qkn.48.2023.12.06.08.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:29:18 -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)" , Yue Zhao , Hugh Dickins Subject: [PATCH V2 0/1] Add swappiness argument to memory.reclaim Date: Wed, 6 Dec 2023 08:28:55 -0800 Message-Id: <20231206162900.1571025-1-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 5482A140019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 48ts5npib6xk48egnhb87ixta6p8brd1 X-HE-Tag: 1701880160-84884 X-HE-Meta: U2FsdGVkX1/atCyMlNWSe7T2j1mXZJzu7MFQBE3yUuLD5ATK303zYVUQW7xJ2sO1RfH3oOR+i6QsFobPB0fPDYtpN9mSB7bkRjES/MBWi+M5LYT37zQnOzT0TRR8xmoG5fk5mq2k8w3ruC+fot5rKYwpDR0ST4Jaa2C/TA7Pbqh2ILqzBVAcSeeRfaYKGS1v4D18iVRu9c1P0YvyU+8TpBnLOsWa94/XCVh8J126/xneN/dz0pH3KT5o9ZrgRguGODE1PmFNUZJ3KkDaW7dx6xAxCcNTRimVOplc5OyfWybz2JRIkCI4Yeud7wwWKjw5PX+qiGbxYFa9nyEzCtKKCgUO+iZbzfYE4zUcXSIjrjFd+qaDd01Lmc8Lwez70ivpmf1uBnN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WBmwRdugOf+bvgeUPlVNHVEMfK7cjc/bcNtPvEyGkBCMOVVT5WZ+fTWB+i/4k2uDF3npV5CeZ5CcKMnMOafvlXi48Bt4GbysK7UIAXpdujZgFX7OZoWDXSGoWl0q6xldrboeO5bDXzyTRGnNKMI0B3zkLCy8lN0SIjxSobYoEEWEDOQ+w0L+/zLCwXeNygrzeZzmRTOo0jK5I75n9KXQYWYyw1egci1lmP84Rsmk0Z4RN/PSA1b8pKFFrumblQ/XDTdUhW5MfhJKrUmkamQyvrSw5qWvh6H+4ABfb2ij930Ovj5EcasC9ZSI= 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 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(-)