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 DA887C369C7 for ; Wed, 16 Apr 2025 21:55:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49F57280144; Wed, 16 Apr 2025 17:55:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44F08280143; Wed, 16 Apr 2025 17:55:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3167E280144; Wed, 16 Apr 2025 17:55:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 10C55280143 for ; Wed, 16 Apr 2025 17:55:12 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D92DE120C02 for ; Wed, 16 Apr 2025 21:55:11 +0000 (UTC) X-FDA: 83341263222.24.02EF591 Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) by imf27.hostedemail.com (Postfix) with ESMTP id F2DA940003 for ; Wed, 16 Apr 2025 21:55:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pxl6M2hA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.42 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744840510; a=rsa-sha256; cv=none; b=y862RdVFT98QLUYdJ4qB7og6WeaOM9XSo55I6xvZGGGkszwwqcWvGueywqiWkXULN9nEso 2vyxICbyQTEaFlqmNRWbLJ29eUWsl6zlWdACYnK3EV/uJXGvLNpO70oXqogjSVU9R8ZtH2 rIxTN7Tv3uC7m88Au3ljn57H7bk0hQ0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pxl6M2hA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.42 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744840510; 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=1gPIruv8+DPJVykMvHBCcurRjzdOaLaF+ig/nmZ+rgk=; b=hjppgW54ymUx4FNshEcPVHk/ZngrgGWrj8UTWKzk0SDX6nSFfNoY2pjgpSHz/usIY36+WU rGAp7D+tYwx5WUxwc/Xp4gxCJ1u3qxfpTy/p6meq4+c7uZHgxZD5N02hogQ1IA9FY0Jmv+ wV3jMI7z1D+05SbFCJyW3BqBZHMynFU= Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-86b9d1f729eso64280241.3 for ; Wed, 16 Apr 2025 14:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744840509; x=1745445309; 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=1gPIruv8+DPJVykMvHBCcurRjzdOaLaF+ig/nmZ+rgk=; b=Pxl6M2hADLcA7I0P1jUj5uQFYz876ASWzgpg50Wb3zM+QhhJmB0DUJF5gpnakSHBkB 5ALNxHUDjjUZFGvKDDuQdhsPea6uP3dvSZtEUbzWzztifN5CEjTCyDbiYiDlf8J0qBCC SERdc0FN+y8HpYXpv/RM6hCjQMk2AJD4/4mLEwGVHnxXucfFHblLi2r2GwvWew4IIbF1 nI63Vo3Tu3samzawIfzY2zU1D1k65mf1Vusk7W6TDXeabQJ9c8Vmlot8bH5WSKIGD9JG 77spnkkcEUsKug1bDnuiYl3RrIhylgLb6UZMNExX4z6lfAr78HOvxotRWqkZIrIm6krS 2HMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744840509; x=1745445309; 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=1gPIruv8+DPJVykMvHBCcurRjzdOaLaF+ig/nmZ+rgk=; b=iSU/z1+03x2DFsKzWxbiVGXVNnx9xSkMNzxJWeHyLY8k6MRyvXhUSLVjl/QLNKKh44 WcH66u+JQiShyeAg+ijZ/BjSrUje2eSPn47AZbjzg/MyYn4S3HU7Ufu7i8LUmDfyg1dL eyRC/2I2if7yqmOX+yCdZZBfUD/WD4MseHfH8HEpfBn+WzqHX8Xxa5WYgqmmoINr2e6A fM7tn63kpNU50mBtqYj1Ung3h5kadfVMkD1A/XCZvBL4jTaulu2gE1jyn1mBfYguKNJD pbGPem9JySdw8lgEMGi/G/9Iu3qckH37tGmtjNyeopkoxVwIsi4gKnU/iYITqDKWzgCW QZXA== X-Forwarded-Encrypted: i=1; AJvYcCVRIkYUjEd63xS0Y33hdICzCpQnnNq59zC5ojBFf1vNbgbKusvFpeW4jEbeZkVWcJCIlZPTcdcvUg==@kvack.org X-Gm-Message-State: AOJu0YzmXnycCgpoA0FM2+lfHouk3yFky2Rayp7bjAMcY6x2sR1dfXDV nAzWWkUunydXj8wRPDIGuZBJxIp2aUuvhHgBzDsMyXBVYysAPuR914c6JmcSaUoXRK+3TY19pxh UYVInhH+abCXBHCo+989187BKwTI= X-Gm-Gg: ASbGncu6G5kXSF6mSKl6oqU6sEkhfXcJ8GiOSkJAGfU9PK8PPuhcdkXMe0R0FJ9k4qk L2meGHYtvbVRz7k7Rz5PxYpacX3GNz6R7wAGjI9mNZObyEvkWYl63dCr1jBiY5avgFbc1sIh7N9 O6NC92eAVHCze+id7a46yNeomGXZx1tonF X-Google-Smtp-Source: AGHT+IHkhF3xA4kAK/73tbGfvqZ44vjh+5kEBCPCGUNimklPYdFojptj/e2Keh6E46G5fdSlA7LLY3y9cJGfpCumpq8= X-Received: by 2002:a05:6102:5616:b0:4cb:5e41:5bf3 with SMTP id ada2fe7eead31-4cb5e415c8fmr2014388137.20.1744840508906; Wed, 16 Apr 2025 14:55:08 -0700 (PDT) MIME-Version: 1.0 References: <20250412085852.48524-1-21cnbao@gmail.com> <34c54df6-9a7c-475d-9b91-0f8acb118231@redhat.com> <6259cc1d-93a8-4293-9009-a6119166f023@redhat.com> <20250416141531.GD741145@cmpxchg.org> <239cfe47-9826-402b-8008-de707faa160e@redhat.com> <20250416181835.GA779666@cmpxchg.org> In-Reply-To: <20250416181835.GA779666@cmpxchg.org> From: Barry Song <21cnbao@gmail.com> Date: Thu, 17 Apr 2025 05:54:57 +0800 X-Gm-Features: ATxdqUFYN_CYfqcQtP8IpKf_FzoMqyFGwslI7cr67PZkLqgnF4wMCUnOUFTB2Xc Message-ID: Subject: Re: [RFC PATCH] mm: don't promote exclusive file folios of dying processes To: Johannes Weiner Cc: David Hildenbrand , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Baolin Wang , Matthew Wilcox , Oscar Salvador , Ryan Roberts , Zi Yan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: F2DA940003 X-Stat-Signature: ddcqgcuembodudj8exgmtgeapq97tdni X-Rspam-User: X-HE-Tag: 1744840509-497304 X-HE-Meta: U2FsdGVkX1/Q3MBrgO43ENTsROiztV5NdcvAlKe5uP6WcjgtECpyCLzW9PEY3OS8KWqiso960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Dor57Ny82TaGkl/nQr5S5LxRJSP/1bDreyiFVz7DrZe5T400LZm5PyQAXO3SYrSxrv7sZfK/YGoJvOjeolCEDpy7k0f5AmjKYu5oIecfrVAPlHFjMqT/Q3dO5g6646nQv3yuVh0XBuD8UMC6t+ypTtpbpgwdNQtB8AtQX96wQMLLdQIoP1YteoUK1g4vnAFgq9CVf38mpSDIvVa+/0YOqRos01L+lfRB0IvhgYYnxCzsTwCJBgabKrJeOupwoNTYTos= X-Bogosity: Ham, tests=bogofilter, spamicity=0.006476, 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, Apr 17, 2025 at 2:18=E2=80=AFAM Johannes Weiner wrote: > > On Wed, Apr 16, 2025 at 05:59:12PM +0200, David Hildenbrand wrote: > > On 16.04.25 16:15, Johannes Weiner wrote: > > > On Wed, Apr 16, 2025 at 11:40:31AM +0200, David Hildenbrand wrote: > > >> On 16.04.25 11:38, Barry Song wrote: > > >>> On Wed, Apr 16, 2025 at 5:32=E2=80=AFPM David Hildenbrand wrote: > > >>>> > > >>>> On 16.04.25 11:24, Barry Song wrote: > > >>>>> On Wed, Apr 16, 2025 at 4:32=E2=80=AFPM David Hildenbrand wrote: > > >>>>>> > > >>>>>> On 12.04.25 10:58, Barry Song wrote: > > >>>>>>> From: Barry Song > > >>>>>>> > > >>>>>>> Promoting exclusive file folios of a dying process is unnecessa= ry and > > >>>>>>> harmful. For example, while Firefox is killed and LibreOffice i= s > > >>>>>>> launched, activating Firefox's young file-backed folios makes i= t > > >>>>>>> harder to reclaim memory that LibreOffice doesn't use at all. > > >>>>>> > > >>>>>> Do we know when it is reasonable to promote any folios of a dyin= g process? > > >>>>>> > > >>>>> > > >>>>> I don't know. It seems not reasonable at all. if one service cras= hes due to > > >>>>> SW bug, systemd will restart it immediately. this might be the ca= se promoting > > >>>>> folios might be good. but it is really a bug of the service, not = a normal case. > > >>>>> > > >>>>>> Assume you restart Firefox, would it really matter to promote th= em when > > >>>>>> unmapping? New Firefox would fault-in / touch the ones it really= needs > > >>>>>> immediately afterwards? > > >>>>> > > >>>>> Usually users kill firefox to start other applications (users int= end > > >>>>> to free memory > > >>>>> for new applications). For Android, an app might be killed becaus= e it has been > > >>>>> staying in the background inactively for a while. > > >>>> > > >>>>> On the other hand, even if users restart firefox immediately, the= ir folios are > > >>>>> probably still in LRU to hit. > > >>>> > > >>>> Right, that's what I'm thinking. > > >>>> > > >>>> So I wonder if we could just say "the whole process is going down;= even > > >>>> if we had some recency information, that could only affect some ot= her > > >>>> process, where we would have to guess if it really matters". > > >>>> > > >>>> If the data is important, one would assume that another process wo= uld > > >>>> soon access it either way, and as you say, likely it will still be= on > > >>>> the LRU to hit. > > >>> > > >>> I'll include this additional information in the v2 version of the p= atch since > > >>> you think it would be helpful. > > >>> > > >>> Regarding the exclusive flag - I'm wondering whether we actually ne= ed to > > >>> distinguish between exclusive and shared folios in this case. The c= urrent > > >>> patch uses the exclusive flag mainly to reduce controversy, but eve= n for > > >>> shared folios: does the recency from a dying process matter? The > > >>> recency information only reflects the dying process's usage pattern= , which > > >>> will soon be irrelevant. > > >> > > >> Exactly my thoughts. So if we can simplify -- ignore it completely -= - > > >> that would certainly be nice. > > > > > > This doesn't sound right to me. > > > > > > Remembering the accesses of an exiting task is very much the point of > > > this. Consider executables and shared libraries repeatedly referenced > > > by short-lived jobs, like shell scripts, compiles etc. > > > > For these always-mmaped / never read/write files I tend to agree. > > > > But, is it really a good indication whether a folio is exclusive to thi= s > > process or not? > > > > I mean, if a bash scripts executes the same executable repeatedly, but > > never multiple copies at the same time, we would also not tracking the > > access with this patch. > > > > Similarly with an app that mmaps() a large data set (DB, VM, ML, ..) > > exclusively. Re-starting the app would not track recency with this patc= h. > > > > But I guess there is no right or wrong ... > > Right, I'm more broadly objecting to the patch and its premise, but > thought the exclusive filtering would at least mitigate its downsides > somewhat. You raise good points that it's not as clear cut. > > IMO this is too subtle and unpredictable for everybody else. The > kernel can't see the future, but access locality and recent use is a > proven predictor. We generally don't discard access information, > unless the user asks us to, and that's what the madvise calls are for. David pointed out some exceptions - the recency of dying processes might still be useful to new processes, particularly in cases like: while true; do app; done Here, 'app' is repeatedly restarted but always maintains a single running instance. I agree this seems correct. However, we can also find many cases where a dying process means its folios instantly become cold. For example: - If someone enjoys watching his/her TV (not shared with family) and then passes away, the TV's folios become instantly cold. - Even if the TV is shared with family but only that person actively used it, the folios still become cold. If other users access this TV too, shouldn't their PTEs reflect that it's still young? I agree that "access locality and recent use" is generally a good heuristic= , but it must have some correlation (strong or weak) with the process lifecyc= le. Implementing 'madv_cold' on a dying process seems impractical as dying means 'cold' for many cases. Also, It is really not doable to execute madv_cold on a dying process. Thanks Barry