Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1097261rdb; Wed, 6 Dec 2023 08:29:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiVOmR6NEEIFV9il+tbThFz0Go4TIL42HPpKfb+TYzRxFy+2X4FU9Fh4hTz5bDuMiLjgiy X-Received: by 2002:a05:6a00:10c3:b0:6ce:93bf:b778 with SMTP id d3-20020a056a0010c300b006ce93bfb778mr920396pfu.44.1701880196798; Wed, 06 Dec 2023 08:29:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701880196; cv=none; d=google.com; s=arc-20160816; b=p1empYNWrIndbrRe79I86pZjapz3eQTXdyVYQucNbHsRHFGIZm5k5Z+Y/ZnuuVhjeE ryTQ8VSWfexOVn3WPqS4vQTnQebvUsIzCAtBYdqradlkJPNsNrFi6QDgB5q66wMhFlW5 TqECmYYXVviWITF1n1tSMsE+Xno8jNR63vqtr1iIxmMTnaonI1EaHwr/uu4DaI/wafxU t4ksNVWhNuq64hwZhAMQWkXaur++haIltXnOoF3017MmSPb5w7y1sPLsVYI3YPOBX1Kp Eao3o9C8gTfteVSjn438Tl3HexFPYEL9qw1sWtM7sJqKS1uy9ymc8OfaAPiOLnuKkM8+ bp0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wd9dmNFWVV3wZN+V4jSJjxu24qyO9wHRcayLWIoq474=; fh=o51nsChBdfT2WVVpSO4a1orzHPJzXK0uNLDEhmCqBmo=; b=UoILKrYg43CwfBNdX65E1mq0C5xfbz2nqEebYq+JVviURoqofw8rxlPB2bzyVkNiWI DC+NjHFhjzVFmmHJML+a2i8lxAgFLz1B0BTRYwhbesgO3dIF3/8OVMnyN7/eqorlUf7M 8CuvAaTbTW8gRct4JqFERlS+FX7/9dyAqLX0/CLPBmf2MzLRl2NFLeOItZvMJMSRxFPY 8HcTckZ7AdXik0+FH5J424FyWWCZ09wvFTI1ppSO/vOFJtLCvipakONplrPmSZ1tXPBm 5GnnfsEKTDcV72TxOR3gph/woyIoNO45uqYw8BhE7rB1+SnHwfB5B6seLrhgrhuLr8AP 0lHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ciSihS5X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bw24-20020a056a00409800b006ce46c5f293si170693pfb.384.2023.12.06.08.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:29:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ciSihS5X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0D8418343960; Wed, 6 Dec 2023 08:29:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378189AbjLFQ3T (ORCPT + 99 others); Wed, 6 Dec 2023 11:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378266AbjLFQ3R (ORCPT ); Wed, 6 Dec 2023 11:29:17 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E4E2D47; Wed, 6 Dec 2023 08:29:20 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-77f3183f012so33369085a.0; 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=vger.kernel.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=ciSihS5X1O8h4ci4GGguyECDBinXW/Kltvw4tF6hL5rhD22IZMjB5gclMaueuWlrkd H/tgLZ8SXZZ5ORAPj3sThrgTaYLsg9WVdzTMV37VeUlq+Ar6mdVmbb0OKCEtSE1e9c9w U1RCBARjuEJahKzPKTsKcfQHly3EIKb/WbeAzWj7EXNRvWADkFt/LeUsnP8eSUSJ6TXN uParrsAvtxdeygcvhhKkvXZrrDgNP/jcdt+V/ua2hmh97aygLL0vhieOprPU1Rmak2+y ApCfYxW7Mn7GYShkkBiFdLe895QSS5H2N3cP+hddoaPKkxjg1dOJ+RQvjl6uM/5MZwyH Tfjg== 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=H+bqR7nrZffoGgfrWyl1bAUE5R+wfPhomI6fgJs0U0SA+YDH5edmwCmlpsDmqCdnTb KqeEfKCseivRTu7YUC+qcMqUiSoZu+j+5gOJQnRxnubUqpZWgaAidaTix1Z2hBjjLTw8 CgHOKrJKCYF600SvrKxek4bGAqdwNMqXWLK8SAfI4BceQtGlZ5cw4x3KqygzkrUYz+cb ETiq4hSk+LUsDp+ulPWQPpi6NfaUeMD80UdBmVE9ABQn3WBQpN3c5UcRCSCJFG81I5t4 He+eeolSRfWMWnkRLCNzwdFmaT005cLVTkfq67ZAbod3Qc6MZTJ+3ON5Xpsj6TdrTEPA 94aA== X-Gm-Message-State: AOJu0YxM2zNWAMs/PasvkI8k/zuz3jh62w85/iv7Cx1WuPu5A6Xu5ey3 YL2tWZ5PN054GOdVhVQU418= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 08:29:44 -0800 (PST) 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