From mboxrd@z Thu Jan 1 00:00:00 1970 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 0934DC4167B for ; Fri, 1 Dec 2023 02:18:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B4F18D0062; Thu, 30 Nov 2023 21:18:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83DF28D0001; Thu, 30 Nov 2023 21:18:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DE6F8D0062; Thu, 30 Nov 2023 21:18:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 58E718D0001 for ; Thu, 30 Nov 2023 21:18:05 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2C012801BE for ; Fri, 1 Dec 2023 02:18:05 +0000 (UTC) X-FDA: 81516639330.17.902B495 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf19.hostedemail.com (Postfix) with ESMTP id 5077F1A0014 for ; Fri, 1 Dec 2023 02:18:03 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=M9zEaQjJ; spf=pass (imf19.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701397083; a=rsa-sha256; cv=none; b=JkCbWRnMH5u6mi7YxaT6+j8CqQhg807BxnQE72JHjJ35/qqckkvTNuMXPvODVHsdwOEGqa FDJzfQVNU6zxmeh9bTw5KSpKXJN5+GG3/ryEwHdcecgIBRcSi1FCipJ3YUb+LXpqgw2I/A eXtqrfYtBlht8MvhO0A0RqzMicHRpAc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=M9zEaQjJ; spf=pass (imf19.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701397083; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ExvEziVgMV2rppcyafzoU2tyP+vlRakA54EORAGR2IM=; b=emGrb7jpHi/+WWEfXP0W3mBbiyNx/dli79EDM/uPp4OzC5G9dl8Gx0tgOVkfW4qBIjbjcZ N+vm8dsQwXX2FnIHu9c+9z9G6dKxuvnyxWnWTk8SC9Vj6THmUpJX7QC7dREV7Xqge0oO3X 0YaQWz/bNGnwrqqwZZEcwhZiaLpJivY= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a02ba1f500fso238215566b.0 for ; Thu, 30 Nov 2023 18:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701397082; x=1702001882; darn=kvack.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=ExvEziVgMV2rppcyafzoU2tyP+vlRakA54EORAGR2IM=; b=M9zEaQjJF4Us5/MluKX0Engg8DyYmlUAU7SHUCQuibnpkjB7OyvHjSX66HNEcqc8Sh vTlYAGMEVcExEUhDtQRcznHt132BOOvYf5DLqv5EoxQycjB9HzpbyN8HJx52hgrXz4r0 mxyXrtU14wTQ5qLLRpLuV5G9oco15Pb38Ky4jEt41q8YTv+ByYkfDA1z0d5PvCy3k7Je 6UluN9ETefawqQYj32jPTY58PR6e7TTsiybFCLKjah9nyWRQCKHQ8KyroVbQab4WnT2G wWjqLkhLSPtQTgOIENBX7Nzs//4t52T9TKGF11nQm/vvKCBFaANH9XU2bLLNlpw6Rz4L WPMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701397082; x=1702001882; 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=ExvEziVgMV2rppcyafzoU2tyP+vlRakA54EORAGR2IM=; b=uTvcXFJVfSXeJA1TYrdLJL30nWEIq52T9RXxH1KTC0GacMHXr088VL21SpCF3EWdfd JAca78tG5rMFei6/dghFjysZPqEYZonNExPHjfONdbdskiVDztZfTyAozHnV6rq8Pj8D Sqg1g4B0gdzaFll4WGxHh/L3g7Kvc6yQyCab6HBsJe6XhnQ9SEy6vAyBIz9gDSQtt4bj EoL9jHS/FWD/7iwRXLhoHieoNszfxihWWO9Ve2tfKqm4/K38i8aorFsJSTYN2qrzIFXY qFY8SWMvLTm7LZgMMsAFU3umz/Ij0cEaFaYAeDDpYrxf49LcDoyE02VnUowqMnnne2cD SxWg== X-Gm-Message-State: AOJu0YxMW4vSEL0xFBH0WYyyYw381OEbCGcrayEVUVZd2Q0m3x/xhlmu UTz8CzQJZUq0tS3aKSMoz7rOzWhKYGx5wM/QgiQMng== X-Google-Smtp-Source: AGHT+IGTvaa/G5kr3Vm3SQHjd3wAZFjGUu8xzf+Rhh/1cOzNo0lKDy+8NE4TvaiB5fL/FDEb/khG4vZO0cZUCW/9LRk= X-Received: by 2002:a17:906:3984:b0:a04:3571:e165 with SMTP id h4-20020a170906398400b00a043571e165mr299359eje.52.1701397081741; Thu, 30 Nov 2023 18:18:01 -0800 (PST) MIME-Version: 1.0 References: <20231130153658.527556-1-schatzberg.dan@gmail.com> <20231130153658.527556-2-schatzberg.dan@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Thu, 30 Nov 2023 18:17:25 -0800 Message-ID: Subject: Re: [PATCH 1/1] mm: add swapiness= arg to memory.reclaim To: Huan Yang <11133793@vivo.com> Cc: Dan Schatzberg , Johannes Weiner , Roman Gushchin , Huan Yang , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5077F1A0014 X-Stat-Signature: cooop4jnaec6hcfdadjnko6fstxju4eo X-Rspam-User: X-HE-Tag: 1701397083-742105 X-HE-Meta: U2FsdGVkX1967FaSRUNQDzxW7a4ALkjVR6vBmHiIGR8INImSa1BCTEHQhlmqrPWU17X5dORkAUzoBtbUf17F2+PRw6/AKMB/NeVHoWVhVqgEWkKIotJJk85H6LuwUzeRK7esujVfV/2pGRrjGSGWvPZpv4Ks6e5AvwgojecsVk3PbEb9BIrYvvrXaAS4MLKaDLtysywbQDS2dP7heaDO4aY3AETM43T/G3R95iavAGN2ySpiW/FYuiKnUnAxm9/1eT44kDZeEAxLxtt5sd4em+Zp8et0KvOhjHKdKXskkR73qRHllbhH+o3fHzXSJr/BtgfYcsga+s/PX1e5LZzfTUuFY9yAO0nKTpnsSc6V36XN4jnCBHCYT11swEBWSmwPDZnPm4jnTrDq2i3WAjwoimb+v8ir9Yxy1Sc43RVGM68SdzvHhknwcFe4Um4bNlHNVoC0/Wzu1BHi30QhLCQyLFAKu3RE3zy21UlYoWS/oVNzklHYs0C9eoh+v8hBG3WAphwj3hAJJXbkzT5627ejzcmzWNQLUffvmY+jiskjiDI4VL902/a2CUBMj1NrqurLeYDUv9GAviWRShjIBPmBuWt7No23T38R1QbNtYLOfTmG54TOb6/nE9KP/pvHGefzxcQNvR/XFYPPDMfpEva+j0CKWo63qSiqQoREcmrj8deYV2PURWXd9xv/ZmmSE6lop2W+oy5NIwFdfxDH/+nKabIG2zQkVTboQ23o7gCu8GAhhe+VbDIjLXg0dta/Jrj44ZzRllxHFM9139teqizOG0sHn5dkTXtu/4wI/F0w0bQeVorlpa+btP7Gp1SGXtCvaFsAyOH0jA1E2w52assg1wc6m+BnTWOYxzUEz9PJuQzoyYUgEIrVWIQRIMPzWCul29IB76uYwLdEi2b/N40Oj3dDrL48k3hQ/kMHt+APz9A1E4VekInU0mMoaY0Hnpl5gY02OkJ0J55E+zZEL62 IrYvgljE XlYj2eTUeLjacqph8xdxp+2jRA2rY63E2RxgL2IBNtIdj/1Nis/jnlCF9lJahZWfEcOb3DJ/YqaUr1Me/ZZL4wuFOsjy9XaAznp7RfWyx9g0jM8DjvlKw69vfm1lekTvIen6+g8KNM5MevGCB6Hx5ThlQQqu4SEkFAl2OQAVj8zZhjgbApQnPG7CHlebXIf4C9AXyZRy2rLpTQZKBQGqbWh5U5jJ6Yq/juLVbjUltqVeylOlbIzEH0a1RH3KmbvOPR2i1+6I17OYIVacejymfO9jJ7hpYnj7ugeGrjIL+K1HXztNAcaK00xMeed3IZWhU5aoEkBcE3vVf6eZAqREXA2C52WAgZ2owTcRf0+dMCMxQ4Zw= 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: On Thu, Nov 30, 2023 at 6:14=E2=80=AFPM Huan Yang <11133793@vivo.com> wrote= : > > > =E5=9C=A8 2023/12/1 10:05, Yosry Ahmed =E5=86=99=E9=81=93: > >> @@ -2327,7 +2330,8 @@ static void get_scan_count(struct lruvec *lruvec= , struct scan_control *sc, > >> struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); > >> struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); > >> unsigned long anon_cost, file_cost, total_cost; > >> - int swappiness =3D mem_cgroup_swappiness(memcg); > >> + int swappiness =3D sc->swappiness ? > >> + *sc->swappiness : mem_cgroup_swappiness(memcg); > >> > >> Should we use "unlikely" here to indicate that sc->swappiness is an un= expected behavior? > >> Due to current use case only apply in proactive reclaim. > > On a system that is not under memory pressure, the rate of proactive > > reclaim could be higher than reactive reclaim. We should only use > > likely/unlikely when it's obvious a scenario will happen most of the > > time. I don't believe that's the case here. > Not all vendors will use proactive interfaces, and reactive reclaim are > a normal > system behavior. In this regard, I think it is appropriate to add > "unlikely". The general guidance is not to use likely/unlikely when it's not certain, which I believe is the case here. I think the CPU will make better decisions on its own than if we give it hints that's wrong in some situations. Others please correct me if I am wrong. > > > >> u64 fraction[ANON_AND_FILE]; > >> u64 denominator =3D 0; /* gcc */ > >> enum scan_balance scan_balance; > >> @@ -2608,6 +2612,9 @@ static int get_swappiness(struct lruvec *lruvec,= struct scan_control *sc) > >> mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH) > >> return 0; > >> > >> + if (sc->swappiness) > >> + return *sc->swappiness; > >> > >> Also there. > >> > >> + > >> return mem_cgroup_swappiness(memcg); > >> } > >> > >> @@ -6433,7 +6440,8 @@ unsigned long mem_cgroup_shrink_node(struct mem_= cgroup *memcg, > >> unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, > >> unsigned long nr_pages, > >> gfp_t gfp_mask, > >> - unsigned int reclaim_option= s) > >> + unsigned int reclaim_option= s, > >> + int *swappiness) > >> { > >> unsigned long nr_reclaimed; > >> unsigned int noreclaim_flag; > >> @@ -6448,6 +6456,7 @@ unsigned long try_to_free_mem_cgroup_pages(struc= t mem_cgroup *memcg, > >> .may_unmap =3D 1, > >> .may_swap =3D !!(reclaim_options & MEMCG_RECLAIM_MAY_= SWAP), > >> .proactive =3D !!(reclaim_options & MEMCG_RECLAIM_PRO= ACTIVE), > >> + .swappiness =3D swappiness, > >> }; > >> /* > >> * Traverse the ZONELIST_FALLBACK zonelist of the current nod= e to put > >> -- > >> 2.34.1 > >> > >> My previous patch attempted to ensure fully deterministic semantics un= der extreme swappiness. > >> For example, when swappiness is set to 200, only anonymous pages will = be reclaimed. > >> Due to code in MGLRU isolate_folios will try scan anon if no scanned, = will try other type.(We do not want > >> it to attempt this behavior.) > >> How do you think about extreme swappiness scenarios? > > I think having different semantics between swappiness passed to > > proactive reclaim and global swappiness can be confusing. If it's > > needed to have a swappiness value that says "anon only no matter > > what", perhaps we should introduce such a new value and make it > > supported by both global and proactive reclaim swappiness? We could > > support writing "max" or something similar instead of a special value > > to mean that. > > Yes, use other hint more suitable for this scenario. > > However, from this patch, it seems that this feature is not supported. > Do you have a demand for this scenario? We do anonymous-only proactive reclaim in some setups, so it would be nice to have. I am not sure if it's absolutely needed vs. just using swappiness=3D200 and living with the possibility of reclaiming some file pages.