Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4935149rdb; Tue, 12 Dec 2023 13:44:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaGZnHgv17xbD9T+sbLU9dUHrnegeDCWg1JX8sPxGr9L0B8IqgR2ml6tKfAYWlIp98tIpm X-Received: by 2002:a05:6a00:189e:b0:6cb:901a:9303 with SMTP id x30-20020a056a00189e00b006cb901a9303mr4029364pfh.13.1702417449584; Tue, 12 Dec 2023 13:44:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702417449; cv=none; d=google.com; s=arc-20160816; b=Xsd96SgqJPpl8W8BT4fv2KIoDRm+KjRZttknMBY3ECUWUd3MfOKWW6Y4okrkswV6oU NlAX7/1fwYU6l0MLrKidjavafD/5e5W96FqFQYuOvVJV3qqqhjw1rRlTsXgdWEQ4Pl4O syXFl7Mv7WNIQpmkcLShauzPm6p7KtVzZ019/gidbyswgi1W9GVbElLkyQ7OfgzT3EAA 6qpnfpfFPaThd63SLgxVuy5Sz6A/ZaN01b6TIjhr0e3961mvBXLI0e0/VssNmGcxqKVo q9EwDIxlLzCwq7k09F5vXZLW6CxwfVxUmQ3qePaZ1B0tZU1BR4y0toC62daYJfmoZFnC 0IGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NYFGcvpC2a9QSpzB8tRAV/ZTOG8iYLcCMIlAxh09bmk=; fh=Zexva7RB/8Fg1e/TGVSHZvQOCrNXZncEyuhlbBXSTpY=; b=mxIE9QyOPEXxLgjsfNB4XWnHCSsHzTjEns46kaoBN3JEL145N+XfJ+bnJ/Oh8CmnrJ +qHeZMPQtfGbvhB/P3hocR68cS3T4nZYW8JkTsBC2Wc3lLsJiNOWlJnndNTyZhRr4Waf kBwNrhs00cEj/QpVyhgMt/J2KSzxiwp6Mr3NkZfqBsmU3RFQxlhhz2LYUPMpmK4fOF5/ WInDtZC6D4yFxHxhGDFUwDDE5TfhoV7Yys3RFVhQFaF60kEAp1235OcwuU5mwaphisWt /85dBdLwda8zdwiBQTuOBX+qMswJBZxhFNXiO/215/4AdeWY6OZrGaYgYkYlg0jV7mjb rZFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SFTB2Hcd; 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 l68-20020a632547000000b005be00714949si8489978pgl.222.2023.12.12.13.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:44:09 -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=SFTB2Hcd; 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 BA18980ACCD7; Tue, 12 Dec 2023 13:44:05 -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 S1377427AbjLLVnr (ORCPT + 99 others); Tue, 12 Dec 2023 16:43:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377185AbjLLVnp (ORCPT ); Tue, 12 Dec 2023 16:43:45 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C3AAAB; Tue, 12 Dec 2023 13:43:52 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso3278143a12.3; Tue, 12 Dec 2023 13:43:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702417432; x=1703022232; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=NYFGcvpC2a9QSpzB8tRAV/ZTOG8iYLcCMIlAxh09bmk=; b=SFTB2Hcd4DX6QFV5OwJngSJA4yTgce33EDXqcUzDogJ3DLCI8yQXQcB3axppwVl4g5 ELf1KTY6wtm1W17rSOOwVU4S3XY40c2UC7uV/bDGWFE2WyS+EkS76kOWMvjPlGaerJTt rjSSlKN+8HfZ8aa5GyiQ3jI+ws59OroILyJumJw2UBXZgP4NObJmRCVqWfiJpsB8ourT 5YZWJiU4ZC1g5DUZBd9zGBs+Yq3nXyaKJQdXxVKJPYgvAWq1gFqV56rSI/OZlc00iuTv 5ghqfzwZnbOqQ830Pwd92jh8NOpaGEPTA/GeTjblmPLImpwVgA1VCGaT3JJlFwr1hs/8 ZDig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702417432; x=1703022232; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NYFGcvpC2a9QSpzB8tRAV/ZTOG8iYLcCMIlAxh09bmk=; b=Xq1NgLcrlU+nfk/ujEZ6Hz2Ihqz/PCynpSDT0DCqZeoFO6Zbv2cOOyuceOiS4tscQV hhJ5Y7VORGgLDJzoO762baZ4PpTQ8gQ1aCwvfan7d06EyZiX0iIwZcJyPChs08RlS2Z0 TKIG0sO/hNHgvs0Zve2dg/A1/l+4PSx7pf7TqB/F6p6Tychga/KCGuMZcOE9dJsy9kWa dTIObE7nD0d4AtL4VBsfgihOl3Gj3DzGU2WkE0Bnjn3Zdh+iCjnAUDJCoyB1pdzap62o hSbxNdMR0Y95QlokkX1vsTxMcJoQjCgTwwLxkPq44cLY2/nh0h++j2PkDJMKRi/pqOfE SZ3Q== X-Gm-Message-State: AOJu0Yw2cYXAPrURtWiuPOPS/6ObYtoK7ACwrXRTT3QTqennkSMmcmpW 4/IQwrAvy4b41Hr/Ju8tt7c= X-Received: by 2002:a17:902:ab45:b0:1d3:46f6:8046 with SMTP id ij5-20020a170902ab4500b001d346f68046mr743839plb.27.1702417431594; Tue, 12 Dec 2023 13:43:51 -0800 (PST) Received: from dschatzberg-fedora-PF3DHTBV ([2620:10d:c090:500::5:671e]) by smtp.gmail.com with ESMTPSA id i11-20020a17090332cb00b001d0ab572458sm9024911plr.121.2023.12.12.13.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:43:51 -0800 (PST) Date: Tue, 12 Dec 2023 16:43:48 -0500 From: Dan Schatzberg To: Chris Li Cc: Johannes Weiner , Roman Gushchin , Yosry Ahmed , 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 , Kefeng Wang , "Vishal Moola (Oracle)" , Yue Zhao , Hugh Dickins Subject: Re: [PATCH V3 1/1] mm: add swapiness= arg to memory.reclaim Message-ID: References: <20231211140419.1298178-1-schatzberg.dan@gmail.com> <20231211140419.1298178-2-schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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]); Tue, 12 Dec 2023 13:44:05 -0800 (PST) On Mon, Dec 11, 2023 at 05:06:54PM -0800, Chris Li wrote: > Hi Dan, > > Thank you for the patch. > > On Mon, Dec 11, 2023 at 6:04 AM Dan Schatzberg wrote: > > > > Allow proactive reclaimers to submit an additional swappiness= > > argument to memory.reclaim. This overrides the global or per-memcg > > swappiness setting for that reclaim attempt. > > I am curious what prompted you to develop this patch. I understand > what this patch does, just want to know more of your background story > why this is needed. I wrote about this in some detail in the cover letter (0/1). Take a look and let me know if the rationale is still unclear. > Instead of passing -1, maybe we can use mem_cgroup_swappiness(memcg); > Yeah this makes sense, I'll go ahead and make that change and eliminate the -1. > > nr_reclaims--; > > continue; > > } > > @@ -6895,6 +6896,16 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, > > return nbytes; > > } > > > > +enum { > > + MEMORY_RECLAIM_SWAPPINESS = 0, > > + MEMORY_RECLAIM_NULL, > > +}; > > + > > +static const match_table_t if_tokens = { > > What this is called "if_tokens"? I am trying to figure out what "if" refers to. I used the same logic as in "mm: Add nodes= arg to memory.reclaim". I can just call it tokens. > > > + { MEMORY_RECLAIM_SWAPPINESS, "swappiness=%d"}, > > + { MEMORY_RECLAIM_NULL, NULL }, > > +}; > > + > > Do we foresee a lot of tunable for the try to free page? I see. You > want to use match_token() to do the keyword parsing. See below > > > static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, > > size_t nbytes, loff_t off) > > { > > @@ -6902,12 +6913,33 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, > > unsigned int nr_retries = MAX_RECLAIM_RETRIES; > > unsigned long nr_to_reclaim, nr_reclaimed = 0; > > unsigned int reclaim_options; > > - int err; > > + char *old_buf, *start; > > + substring_t args[MAX_OPT_ARGS]; > > + int swappiness = -1; > > > > buf = strstrip(buf); > > - err = page_counter_memparse(buf, "", &nr_to_reclaim); > > - if (err) > > - return err; > > + > > + old_buf = buf; > > + nr_to_reclaim = memparse(buf, &buf) / PAGE_SIZE; > > + if (buf == old_buf) > > + return -EINVAL; > > + > > + buf = strstrip(buf); > > + > > + while ((start = strsep(&buf, " ")) != 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) > > Agree with Yosry on the 200 magic value. > > I am also wondering if there is an easier way to just parse one > keyword. Will using strcmp("swappiness=") be a bad idea? I haven't > tried it myself though. As above, "mm: Add nodes= arg to memory.reclaim" was previously in the mm tree doing it this way, so I duplicated it. I think given that there have been lots of discussions about extending this interface, this match table has some potential future value and I don't see a major downside to using it in favor of strcmp.