Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp396757rdb; Thu, 30 Nov 2023 07:38:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyMreuoEtIaDOcPf21OK/TfIQygjvo6+DnjHzwUPaxNWKDwsr2SrDXM252abDEqtHOP8BQ X-Received: by 2002:a17:90b:4b88:b0:285:c1e1:66b with SMTP id lr8-20020a17090b4b8800b00285c1e1066bmr14039657pjb.37.1701358715946; Thu, 30 Nov 2023 07:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701358715; cv=none; d=google.com; s=arc-20160816; b=YsreQXz0sV8zIGScuF0ITBHzJLLprpzXfwX56UjFKBFnvQSTioPZUgSRcDREQeVnO1 2rprGrYo5v7jQ+OP5K3AiRDC7YeI/3dKHeWnnN2MbaKsrULI9ffJBiUawLz436WCGd8q 5LMh4HVsS0fMN/bHSmdyMaWsExbnoO81oybpBS2r2rDbvW3i9Bt/Mb5DkNxkhSK2dCWf z6Gsap0gx7lJWu3geGzHwzz8sbCnbI8Hu7OimGA7fvWVYYNOfsVU1d4QHgIIQYiOMyCz fTgYAUz6V0AjLEFC9I+UcUXFIyQ/App2NiezHZEJx+2OCa1QFm04+w+3ikyS63o63Cg5 SxVg== 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=iHt5GWpmh8+9rwkGRbQdmAOL6TBISUyjYNzzHw7DKOw=; fh=sYw+Ou9qCjUqPBko/gEIRt2am38jlclmmZ26nZMFAxA=; b=kwRa12Q4c5TIkE90a0ujAmiAhROLkkapWKaidAokxTNphIAM6UwYUZzpQM2bBUWK1M X45kxn5vklz5VRkAFzOaNE43v+zn9oUm9LwyLDQWOTs54z2wB0q0jdexkFQ7gV5V2E83 Zb26l/w6eNAau3Puci3FuXLwS1HfQBYg/QeXO8V/nf1ELzVSuhpvBs5QezVlryuTuRgG bqwgkt1wF7F18kR0vepV77E85RxLxBcI/7CIoLpOAXdDUedtdOF9FEAsQBS01KSHu/P3 nq+3D4WvYqHhp6WezJtR0qukPuGvgscmjgqbiTG9pRfJC/qMwOiUbswtzgBG++DAlWw4 4bYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dOuj9+RS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id n89-20020a17090a5ae200b00286453388bcsi854013pji.60.2023.11.30.07.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 07:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dOuj9+RS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 7C3CF802EE4C; Thu, 30 Nov 2023 07:38:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346356AbjK3PiK (ORCPT + 99 others); Thu, 30 Nov 2023 10:38:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346351AbjK3PiI (ORCPT ); Thu, 30 Nov 2023 10:38:08 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146B710DF; Thu, 30 Nov 2023 07:38:15 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-77d708e4916so48385285a.3; Thu, 30 Nov 2023 07:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701358694; x=1701963494; 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=iHt5GWpmh8+9rwkGRbQdmAOL6TBISUyjYNzzHw7DKOw=; b=dOuj9+RSpq9WraSpu5bJ234WW3s6vfaOPQKzEMhTDaH71NXQXVwJ13UDh5qSW9wNwZ KVkS3R9JmsdIVGyuMkcH0i4NanhNjhBSfkZQS/7vYKsmHZ71IXsKSHuh3XKSaZHFdbNL MLxTJYwvRCf5CWF8OvvxZdBKDG2015kAcj7Sf0lK1vv/RULLUKg62vV3UOmfiPDlax/l UDl6KESb4pSzxsx0XAiFLwVGTNHzHgmoa2IB5sq3T1p+Uq8xPsgIP7RvZ5xagsIdsZ0D lurj30nPCJjW8s1YnzpE8VvdHZewJ7Gqi96zdWCPD+3W2lGmGd4QToCyLUW41OWBwpwz nVbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701358694; x=1701963494; 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=iHt5GWpmh8+9rwkGRbQdmAOL6TBISUyjYNzzHw7DKOw=; b=qYZ28o2gDXbaJ796rhD9Bl9fpr4sGad+swi8bl3ztUxhJpSYuXA8uUBKq+6gVO2peS qDXdQ7oJoBUerdL+L93wj0eDna//YjXTqjW/2ZrGeYs9kMq1TU+qZfBJkV6XH9g7/uzP SUgYJ9bAImJrmlaPwtVnM95tP5dWmcBxNIkWfvnqjYSlQVJRHRbHuf6xcgNIhGEhMla+ VXBeKPg8fR7qVK8GlczSNWMXnOJX8418MRQv9NioQid1S8dP/jPpHshtjGlXTz1rVh3u WSbbJIcSI1r5bUNj5bzWWZ8wIINFd/vqYEW2Hr37yZUTj1XzyHxicGpVDN9tmyhyq1uG sL8w== X-Gm-Message-State: AOJu0YyJ96bTy2Z1kmPo2kA4foXTUDxkTMCPc5T6nE/QMInR4UeoZ6WH g2ulwuHpmrpBFPsv/WbnxPg= X-Received: by 2002:a05:620a:3913:b0:77d:8659:ee65 with SMTP id qr19-20020a05620a391300b0077d8659ee65mr25383275qkn.67.1701358693897; Thu, 30 Nov 2023 07:38:13 -0800 (PST) Received: from localhost ([2620:10d:c091:500::4:edc5]) by smtp.gmail.com with ESMTPSA id bi32-20020a05620a31a000b0077d9f83e691sm593708qkb.35.2023.11.30.07.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 07:38:13 -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, Michal Hocko , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Kefeng Wang , Peter Xu , "Vishal Moola (Oracle)" , Yue Zhao , Hugh Dickins Subject: [PATCH 0/1] Add swappiness argument to memory.reclaim Date: Thu, 30 Nov 2023 07:36:53 -0800 Message-Id: <20231130153658.527556-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 07:38:30 -0800 (PST) (Sorry for the resend - forgot to cc the mailing lists) 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 include/linux/swap.h | 3 ++- mm/memcontrol.c | 55 +++++++++++++++++++++++++++++++++++--------- mm/vmscan.c | 13 +++++++++-- 3 files changed, 57 insertions(+), 14 deletions(-) -- 2.34.1