Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4200834rdb; Mon, 11 Dec 2023 11:42:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwhYen1uF0//z0EcXr7bYkf03rJuZ1lcNUbU4imVLEg4462n52DaM2ZgVoiDI9rl8MGzcB X-Received: by 2002:a05:6358:786:b0:16f:2478:a87 with SMTP id n6-20020a056358078600b0016f24780a87mr3467189rwj.0.1702323736661; Mon, 11 Dec 2023 11:42:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702323736; cv=none; d=google.com; s=arc-20160816; b=wfOGi7j0RJ0onJKXPmYOiNSWXMUwIB2EahJ70ZGvQEeYSiIgv9/RT6urVe9aqb/qlP 6oZs1+UgPe61M3A+bZRAfPFJLH0b48qRfJn/0q+pSTAOKZLnC4zemlpXq7ZropkO0N/1 1XQOx5TP2gHPleGcokyhjGWHhlfmEDxNJa1SFAA8tRQxtsDsNx5K9usilr3GM3TsiMGT UnhaXZJ9sV8jyrGWU3FQLLjGp1TSTu9i5hrfKraEWFoa6mL9NvklGXXVDQX5sj2ABAXH uZDPPPapywsYa7ipdQMrlJYwWfPS/1zJsyuQJ94u4O0f2FzH2h3ypzj6rIFe3H8lLl1s rWWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=A1xlkoknCKe+rRAZq4chj+QZuYrtbZ8hKNLIJXx7jh4=; fh=fHa/STNSUqaGbHc3m6YYrg5Xqrpxn3DpRBaZSmLer6I=; b=je7iPASpyWAXB1jk5dXkVmawAOMzsCxgqK9l/MAXsBteB+gvjfxfHE6spXqTi67Ykt 1PgU86OIfOYQy66kyypd3sGfF12jBHSktBKrf7ht+vttbeXFJtbS+AGojeJHYXqxgffj p64V+1bZDvJ75+r9hhdG/7bWhZP8SHSFvX26H76Blh8oJPEBlm/QpcFNF2IDhdyDPEXR qY2Tc9Vd/mRg8UxiGJo6UXqFFj2hgrkiPPareIjpAHPUfkCrC++YjIlZjnNosPD+oiTO H7+BxgNEKTFh8ngII8K+nGjps8eV3OsQZy8wNFPfNXXYvLr+gwELDPHkjxcLVhmtXsSM HQ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BzpwBPEq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q6-20020a635c06000000b005b86b35778fsi6383145pgb.180.2023.12.11.11.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 11:42:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BzpwBPEq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D677C80545B0; Mon, 11 Dec 2023 11:42:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344839AbjLKTmA (ORCPT + 99 others); Mon, 11 Dec 2023 14:42:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjLKTl7 (ORCPT ); Mon, 11 Dec 2023 14:41:59 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F353CE for ; Mon, 11 Dec 2023 11:42:05 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-54c77e0835bso7019777a12.2 for ; Mon, 11 Dec 2023 11:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702323723; x=1702928523; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=A1xlkoknCKe+rRAZq4chj+QZuYrtbZ8hKNLIJXx7jh4=; b=BzpwBPEqvUBjsQVHoOz/q1a76DmJJO7Kx/yAZ7og8hkf3sMxqcViv6MP4kyz84fcmT tahr1lgEtEBSA+/a6eRZKTSCdBdJ21KUaVJS1TOyy+1nprZut7KmPzCLSA+/kkVyRy3C Srnop5iVHzwVMSweBcfUw6DTmNNE3ePjAqFhIqc9m2n5OFMkf1NSsKU2vrkh93T8gRKp 0xpKgKgKwGP5umqVeZjsqWWb+7m4pbu6ErHcE2c58pSTIWswotBK5eec6oyunabbHmIw lLUgLFH/Jcsrj9PVLf5KeXppPATDSLUsQvlxXg1dR8zq5gPXdT+nNiQb1KvXV4AQDMz4 Xv/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702323723; x=1702928523; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A1xlkoknCKe+rRAZq4chj+QZuYrtbZ8hKNLIJXx7jh4=; b=V6ipoNPmd0rxDeFCi9bz77lW1+rx4GyBhfbI/NUW2rZas/SyQoTxzjJAybSSV9mBrE 0URTaCeRyFnOpmTdyGrNbNLJYqI97UnyxH7ivzTbYOs+NcMp+2nPXeBaWk3ezkHCDAt5 jY+rJ3gOMxLG0P6w+JXlEfG+lZ7KvwaPFbB4keDJ2ykMX5Bt1mdPb3eRo4n63hFibbC6 f8rDyQZIeRa7Mrsn6qFcjNYx2uY5vEeTM5eXENLKDF+11xJ01ii5nBJcYuGbvCJomtpr QZasn0ia4/a6SxZS70KfSP6hOQV5V1JTD1bXBkdEmW015NSrltEQ3gLb8MprXqnNYcdB DbOg== X-Gm-Message-State: AOJu0Ywla+aEejOP4x3ateW/GWVUfKaMxTV4Z+gaVE5qKswMIexgHsIg x+B9xzyrJo4iX1urWlLwv4ff9LjcXF3eg3i/1MwTDw== X-Received: by 2002:a17:906:33cc:b0:a19:a19b:78ae with SMTP id w12-20020a17090633cc00b00a19a19b78aemr2279264eja.113.1702323723348; Mon, 11 Dec 2023 11:42:03 -0800 (PST) MIME-Version: 1.0 References: <20231211140419.1298178-1-schatzberg.dan@gmail.com> <20231211140419.1298178-2-schatzberg.dan@gmail.com> In-Reply-To: <20231211140419.1298178-2-schatzberg.dan@gmail.com> From: Yosry Ahmed Date: Mon, 11 Dec 2023 11:41:24 -0800 Message-ID: Subject: Re: [PATCH V3 1/1] mm: add swapiness= arg to memory.reclaim To: Dan Schatzberg Cc: Johannes Weiner , Roman Gushchin , Huan Yang , 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 , Chris Li , Kefeng Wang , "Vishal Moola (Oracle)" , Yue Zhao , Hugh Dickins Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 11:42:14 -0800 (PST) On Mon, Dec 11, 2023 at 6:04=E2=80=AFAM Dan Schatzberg wrote: > > Allow proactive reclaimers to submit an additional swappiness=3D > argument to memory.reclaim. This overrides the global or per-memcg > swappiness setting for that reclaim attempt. > > For example: > > echo "2M swappiness=3D0" > /sys/fs/cgroup/memory.reclaim > > will perform reclaim on the rootcg with a swappiness setting of 0 (no > swap) regardless of the vm.swappiness sysctl setting. > > Signed-off-by: Dan Schatzberg > --- > 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(-) > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admi= n-guide/cgroup-v2.rst > index 3f85254f3cef..fc2b379dbd0f 100644 > --- a/Documentation/admin-guide/cgroup-v2.rst > +++ b/Documentation/admin-guide/cgroup-v2.rst > @@ -1282,8 +1282,8 @@ PAGE_SIZE multiple when read back. > This is a simple interface to trigger memory reclaim in the > target cgroup. > > - This file accepts a single key, the number of bytes to reclaim. > - No nested keys are currently supported. > + This file accepts a string which containers thhe number of bytes contains* the* I think this statement was only important because no keys were supported, so I think we can remove it completely and rely on documenting the supported keys below like other interfaces, see my next comment. > + to reclaim. > > Example:: > > @@ -1304,6 +1304,17 @@ PAGE_SIZE multiple when read back. > This means that the networking layer will not adapt based on > reclaim induced by memory.reclaim. > > + This file also allows the user to specify the swappiness value > + to be used for the reclaim. For example: > + > + echo "1G swappiness=3D60" > memory.reclaim > + > + The above instructs the kernel to perform the reclaim with > + a swappiness value of 60. Note that this has the same semantics > + as the vm.swappiness sysctl - it sets the relative IO cost of > + reclaiming anon vs file memory but does not allow for reclaiming > + specific amounts of anon or file memory. > + Can we instead follow the same format used by other nested-keyed files (e.g. io.max)? This usually involves a table of supported keys and such. > memory.peak > A read-only single value file which exists on non-root > cgroups. [..] > @@ -6902,12 +6913,33 @@ static ssize_t memory_reclaim(struct kernfs_open_= file *of, char *buf, > unsigned int nr_retries =3D MAX_RECLAIM_RETRIES; > unsigned long nr_to_reclaim, nr_reclaimed =3D 0; > unsigned int reclaim_options; > - int err; > + char *old_buf, *start; > + substring_t args[MAX_OPT_ARGS]; > + int swappiness =3D -1; > > buf =3D strstrip(buf); > - err =3D page_counter_memparse(buf, "", &nr_to_reclaim); > - if (err) > - return err; > + > + old_buf =3D buf; > + nr_to_reclaim =3D memparse(buf, &buf) / PAGE_SIZE; > + if (buf =3D=3D old_buf) > + return -EINVAL; > + > + buf =3D strstrip(buf); > + > + while ((start =3D strsep(&buf, " ")) !=3D NULL) { > + if (!strlen(start)) > + continue; > + switch (match_token(start, if_tokens, args)) { > + case MEMORY_RECLAIM_SWAPPINESS: > + if (match_int(&args[0], &swappiness)) > + return -EINVAL; > + if (swappiness < 0 || swappiness > 200) I am not a fan of extending the hardcoded 0 and 200 values, and now the new -1 value. Maybe it's time to create constants for the min and max swappiness values instead of hardcoding them everywhere? This can be a separate preparatory patch. Then, -1 (or any invalid value) can also be added as a constant with a useful name, instead of passing -1 to all other callers. This should make the code a little bit more readable and easier to extend.