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 8AE13C35FFA for ; Wed, 19 Mar 2025 12:53:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F5D5280003; Wed, 19 Mar 2025 08:53:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A794280001; Wed, 19 Mar 2025 08:53:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66DC8280003; Wed, 19 Mar 2025 08:53:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 499BC280001 for ; Wed, 19 Mar 2025 08:53:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D8027161E6E for ; Wed, 19 Mar 2025 12:53:34 +0000 (UTC) X-FDA: 83238291948.25.1635AA0 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by imf14.hostedemail.com (Postfix) with ESMTP id 02447100006 for ; Wed, 19 Mar 2025 12:53:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=du6vy2Md; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742388813; a=rsa-sha256; cv=none; b=XkKAdFpC+o+42Viy2tp2cYdf20tuYSc2hRb9ruJWlzRqbfxEIbPSM0YMrB+XerfluYUSjU U/d+uHnAs9KB+AphMIXj4aVT/yv9nb5twZNrJ5bbQPnw4UErx6/Q1ooEebJCUhP/fbUo/K NcQNpyYgfuQmUs8jF8hYZy59weRR03Q= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=du6vy2Md; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742388813; 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=gdbbRT580Qu8som9Q+94gaoUxidIl9ZdI8AmdFOecEw=; b=WaJ0HARLb99fU9oeDNpr/39fmJX4BOipO/TZufyIRCpOjAUofXgZjrVF3IlGN+DndosMO0 rvVeV8T1waQdN3SnVVPv6HGj59IDu9JMY1dXt2FaoeKZL2C1OOes+RE8bdY0qR1d4xFHWw 7DHoIfwo9YTJxCiLAlj9+fqx+tlozdg= Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5498d2a8b89so7205938e87.1 for ; Wed, 19 Mar 2025 05:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1742388810; x=1742993610; 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=gdbbRT580Qu8som9Q+94gaoUxidIl9ZdI8AmdFOecEw=; b=du6vy2MdWNR9cL3+hHcf4cOLiHn42VB3NeKLcp1ldHV9ThZjTcDL2em5uSSrpt99jR TRw6f3UAoUKAoumACa2V5H3Lapd2M4IVVfrAfxs8ohZ4Z9IsVTxDhRUG+ga2Hx1vkzcZ le4wkpqRFPCYKMnjcRrJRSz7wG2Y8bCZZBaG19ocGLR35V0i0Eteixf+N6gcJc37HoQ6 /5iZIWS8xuOmxJ3CbbIDcBt2udLoFUp5dC8u8XJveCBQmEgDQ0Ih+z2/MhruB7RB2GMJ oEvPlNKMFGg/qG+umd8Y+wuulp46yeA3KUdW5jGzi51jJH0WSO0RcKKw7GXY8RrK0RNZ IFTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742388810; x=1742993610; 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=gdbbRT580Qu8som9Q+94gaoUxidIl9ZdI8AmdFOecEw=; b=akQz3XytQ8xKofdpoL0GRRfUDRL4mdIas1e4smvQ9ded5IRz2TYCbF5Gwbu4r0yYTH 6UztElCDMObIRn8M9UCvphfyubRW5JJgLKgd210149DsAeFeEmCPh+x25eeKok2wKs7b QIzlJZfp8ja09LuLxzOAHZKYaYjAkzHNeVdVOcfF7pImPpEhpjJo3PWvWmakQgCIW69p ahhtOJZ4tsrRKCdDzdcZx1C9oUlHoyMU92ucLiTqJ+GZm6lx297jl7UZTmr/qcekYv0j lBOhuwmaoQrGMEH+hbIvUX9KWOs2KzlSUxdXO5KEsA46NOva+sxhcGkRJsvieXabf7pd LR0Q== X-Forwarded-Encrypted: i=1; AJvYcCWNONKCEBz1QNed5xtuJYyAxDRyzCRN4rwwTNlgenMAhkXHXHCQqrxkFaMBhdaMeU2xvZZbepwhrQ==@kvack.org X-Gm-Message-State: AOJu0YywckfIp+xJ8TZrF1m4LdNpzw+0LJPmCpjgBWvgC0Id9OoDBkXV 9HHzGWLIw+mIHTlPVnkiLZGzRGS7M+kApXbb4XyMFi8N/8A126lTVdghn4mTsVsPgl7LrtH0v/D 5MeMZ2rx4djEh5XRiRo7576L/Y2cBafUA/dzZYw== X-Gm-Gg: ASbGncsT8EZOvjOEcmUagtTI48tTU1x1Aki28Lg1dISf+QXfRw8DRlIQfP0tJsRop/Q KBWJtS5yh54+Y2LxWe3r8fSe0suV8E5tFGeeDpR3u8ic7E6ZR+4sabe5RmphC+EGt3i60k89Vmr n5ESyirEkBl9qOgLWLWsincfxuinBiFDLkSI35OwfF X-Google-Smtp-Source: AGHT+IEue5MPU3PrM7P5n1w/XUtEMRe9CztvHOb/x9ccIXDa/TEpEX6z/VLk/2ZMWMshfhUTw5KhlQFlX9J29bAdIZA= X-Received: by 2002:a05:6512:1090:b0:545:5a5:b69d with SMTP id 2adb3069b0e04-54acb1d5c3emr1019159e87.31.1742388809845; Wed, 19 Mar 2025 05:53:29 -0700 (PDT) MIME-Version: 1.0 References: <20250318135330.3358345-1-hezhongkun.hzk@bytedance.com> In-Reply-To: From: Zhongkun He Date: Wed, 19 Mar 2025 20:52:52 +0800 X-Gm-Features: AQ5f1JrCfe0A7QX7Ogw-Wxu_Uv7MELXV8NyoE_mruM1hLG8-Q0_vn2WF4cDoa64 Message-ID: Subject: Re: [External] Re: [PATCH] mm: add swappiness=max arg to memory.reclaim for only anon reclaim To: Yosry Ahmed Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yuzhao@google.com, mhocko@suse.com, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 02447100006 X-Rspamd-Server: rspam05 X-Stat-Signature: i4uiqcony664iggszdiifqdycs85juqf X-HE-Tag: 1742388811-539572 X-HE-Meta: U2FsdGVkX18YBwBbmOgQwsWmXjZmjt9nFPuC8iPuHMOxOrjOmWII6j9AZjkGa5jnmWG1dLhPnfb7X8gIoQaeiBD1Ey9ECjhz1yOWE5HQJd+3sWZf5MoXZTFAx3WBUSUC0u7yqZ1+XLW6D++Jz+AGqvsxKRBS7NZfYWD42aSKOoMnioRnsuYm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ack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Mar 19, 2025 at 1:29=E2=80=AFPM Yosry Ahmed = wrote: > > On Wed, Mar 19, 2025 at 10:34:54AM +0800, Zhongkun He wrote: > > On Tue, Mar 18, 2025 at 10:10=E2=80=AFPM Yosry Ahmed wrote: > > > > > > On Tue, Mar 18, 2025 at 09:53:30PM +0800, Zhongkun He wrote: > > > > With this patch 'commit <68cd9050d871> ("mm: add swappiness=3D arg = to > > > > memory.reclaim")', we can submit an additional swappiness=3D a= rgument > > > > to memory.reclaim. It is very useful because we can dynamically adj= ust > > > > the reclamation ratio based on the anonymous folios and file folios= of > > > > each cgroup. For example,when swappiness is set to 0, we only recla= im > > > > from file folios. > > > > > > > > However,we have also encountered a new issue: when swappiness is se= t to > > > > the MAX_SWAPPINESS, it may still only reclaim file folios. > > > > > > > > So, we hope to add a new arg 'swappiness=3Dmax' in memory.reclaim w= here > > > > proactive memory reclaim only reclaims from anonymous folios when > > > > swappiness is set to max. The swappiness semantics from a user > > > > perspective remain unchanged. > > > > > > > > For example, something like this: > > > > > > > > echo "2M swappiness=3Dmax" > /sys/fs/cgroup/memory.reclaim > > > > > > > > will perform reclaim on the rootcg with a swappiness setting of 'ma= x' (a > > > > new mode) regardless of the file folios. Users have a more comprehe= nsive > > > > view of the application's memory distribution because there are man= y > > > > metrics available. For example, if we find that a certain cgroup ha= s a > > > > large number of inactive anon folios, we can reclaim only those and= skip > > > > file folios, because with the zram/zswap, the IO tradeoff that > > > > cache_trim_mode or other file first logic is making doesn't hold - > > > > file refaults will cause IO, whereas anon decompression will not. > > > > > > > > With this patch, the swappiness argument of memory.reclaim has a ne= w > > > > mode 'max', means reclaiming just from anonymous folios both in tra= ditional > > > > LRU and MGLRU. > > > > > > Is MGLRU handled in this patch? > > > > Yes, The value of ONLY_ANON_RECLAIM_MODE is 201, and the MGLRU select t= he > > evictable type like this: > > > > #define evictable_min_seq(min_seq, swappiness) \ > > min((min_seq)[!(swappiness)], (min_seq)[(swappiness) <=3D MAX_SWAPP= INESS]) > > > > #define for_each_evictable_type(type, swappiness) \ > > for ((type) =3D !(swappiness); (type) <=3D ((swappiness) <=3D > > MAX_SWAPPINESS); (type)++) > > > > if the swappiness=3D0, the type is LRU_GEN_FILE(1); > > > > if the swappiness=3D201 (>MAX_SWAPPINESS), > > for ((type) =3D 0; (type) <=3D 0); (type)++) > > The type is always LRU_GEN_ANON(0). > > Zhongkun, I see that you already sent a new version. Please wait until > discussions on a patch are resolved before sending out newer versions, > and allow more time for reviews in general. Got it, thanks. > > I think this is too subtle, and it's easy to miss. Looking at the MGLRU > code it seems like there's a lot of swappiness <=3D MAX_SWAPPINESS checks= , > and I am not sure why these already exist given that swappiness should > never exceed MAX_SWAPPINESS before this change. > > Are there other parts of the MGLRU code that are already using > swappiness values > MAX_SWAPPINESS? IIUC, The MGLRU can already use the value of MAX_SWAPPINESS + 1 to reclaim only anonymous folios. Please have a look: lru_gen_seq_write()->run_cmd(): else if (swappiness > MAX_SWAPPINESS + 1) goto done; /*so MAX_SWAPPINESS + 1 is OK */ in inc_min_seq(): if (type ? swappiness > MAX_SWAPPINESS : !swappiness) goto done; //skip LRU_GEN_FILE when swappiness is //MAX_SWAPPINESS + 1 //Skip LRU_GEN_FILE when swappiness is MAX_SWAPPINESS + 1. #define for_each_evictable_type(type, swappiness) \ for ((type) =3D !(swappiness); (type) <=3D ((swappiness) <=3D MAX_SWAPPINESS); (type)++) So the /sys/kernel/debug/lru_gen can accept the value of swappiness + 1 for proactive reclamation, meaning it only reclaims anonymous pages. But the above statement is just my guess. It would be great if Yu could cla= rify. If my description is incorrect, please correct me. > > Yu, could you help us making things clearer here? I would like to avoid > relying on current implementation details that could easily be missed > when making changes. Ideally we'd explicitly check for > SWAPPINESS_ANON_ONLY. > Looking forward to Yu's reply. Thanks.