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 7A8D1C3271E for ; Mon, 8 Jul 2024 03:54:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5FEC6B0089; Sun, 7 Jul 2024 23:54:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0EDC6B008A; Sun, 7 Jul 2024 23:54:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAF8C6B008C; Sun, 7 Jul 2024 23:54:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9CFA06B0089 for ; Sun, 7 Jul 2024 23:54:22 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 112A5141058 for ; Mon, 8 Jul 2024 03:54:22 +0000 (UTC) X-FDA: 82315217964.20.7A28727 Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 5B7692000E for ; Mon, 8 Jul 2024 03:54:20 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720410837; 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; bh=A9yWBcvtrBN9A0bVR1CPLdm0pzTAqGp6O50VAnnxws8=; b=7m8m+y7ukwv4fpDScowkWGbcu0DFcg0ONCibCWhp0Hg9yD6EsxfYbxAvX3uqzGrdNabMOp hvxjJPinC/2ABRyOj51bplHAGQYAMyi0V2aqIE12KCViUEfsfaLiWScf8mEBF4YN3V4Dt/ tP9wUppuxPRuq+le0JtY7TnLbawiPSU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720410837; a=rsa-sha256; cv=none; b=yY7/1Ls0MtHuv6yHLSv00MIkMTFcuWowFRBJaGwTtv/k6h9MTk0ZpU83H4qIYMqzs36+x3 Qps4R/1TK5P5YE1BlZUi59vFeYZbY9RvgUpXpkIIrkYG6yj4INoeSf0SYhGCkBOcQT5/9J eqVDLm78KlyI6VqVNzlFdRrAhlcfczU= Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-4f301629cfaso633084e0c.3 for ; Sun, 07 Jul 2024 20:54:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720410859; x=1721015659; 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=A9yWBcvtrBN9A0bVR1CPLdm0pzTAqGp6O50VAnnxws8=; b=eqvI+PvQ2kzP29eqgpApuBFQd+eAqkl+sdUKuwprMWdNVqwkt8kv4HSuOrGJZQJ+Ff 6Ylv+abBLQNUa4jIjZHKP30XwAERWEVko42utzc7TGfbl25sFchp4f4VkHZ5WLKRoNZ1 5sXm5VhkOvDQO1J7B3PeGrKDFmqfppSYImgpdmEVLADeByHfCZNFTyxvT2D9W9KKHE1+ HqxqiEiz6Dyl6Lq6ITDUF/4p0qE0o704/ozVmsPZsXsNesGWdA14DLaHd6DVnUKl5jkC q8fWBAdplEdYq3o8tNjucDpGQ+Jo1jV6W2q+wJJP3hfqaz7YVSppb+HUbD6mc+ygKzVS f3gA== X-Forwarded-Encrypted: i=1; AJvYcCU3ePM6vv7DlHioHL38V3qlixJ7bEx6M9rlEUb+xCAk1FraIaLzp6wFF10zCHd8N/JXugSUCKMx2Ar5nHcvxKU7zZM= X-Gm-Message-State: AOJu0Yx5d2JaI9tJEhyQ0kWoOz8PwkjIT6gFVPMMfQuVPumnxkaNy7Kj DECVmFNTVWntwTj///1l6CJuh87hWa5teNbnd7ERyMg/UHSpsw7AMZl/yOHxLztzCXiYOGNwcrj u/6kRuJiZVBwYszKXyC+k4lFzpMA= X-Google-Smtp-Source: AGHT+IFxeWLfsOeL1l5WXfdLDl5BzX7i/gji+dB2rmBjloeQTwZGNNgUupfoYxsObbFscvI1xOnbiGQeRJ52fFSJwcE= X-Received: by 2002:a05:6122:1693:b0:4f2:fc5c:b89 with SMTP id 71dfb90a1353d-4f2fc5c0e14mr6120606e0c.15.1720410857835; Sun, 07 Jul 2024 20:54:17 -0700 (PDT) MIME-Version: 1.0 References: <20240221114904.1849-1-justinjiang@vivo.com> <7964fa25-0ba6-43b5-b215-4e381a355a08@vivo.com> In-Reply-To: <7964fa25-0ba6-43b5-b215-4e381a355a08@vivo.com> From: Barry Song Date: Mon, 8 Jul 2024 15:54:06 +1200 Message-ID: Subject: Re: [PATCH] mm: shrink skip folio mapped by an exiting task To: zhiguojiang Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, opensource.kernel@vivo.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 9km75acjf7r9jt3heau8d7j5xfmxexqe X-Rspam-User: X-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7mbHP+SqqkKyoQKQHhwmUxAlX1u+jbzVoRFEBDUMgfQUqWDq2i10jeoYGgLaES6EeaIhpF/0PE9vLBj/Jn9R9ZGXaVr3MkNgysItvV+Zw35Sj2ogGRS/Lt+nld2oyIh+xyA3KKegndxWgVGYbgXKy8ECGYEGbuowljxyPX9o8ddh5j+owS8iJiHYQJ81E5g0EjkcpEm4P9ufQ6L0WZm1FHDpcwHbIRxOtXS1+09rcFKIm1aKF8YZp3K9B4dJWoRt1aEMduj0Y/yCvTi/DhmMdKUkdGNU10rJrGwuYmNo8P3fAZHx8Kr8F8qlvQQcjcI41CdvwV0gu36Xwew88CPqRoDkD0snMQ3B/ydFts6EulMQf7nRvf9wFmHgzRUA+wE+u8kGviiIXZ+4rDmtF8mIxUtIRpzP7cb5HFihFjALGdVvBs/8wZKtoW9/HQbus8MEjmbFRKUvm2T7uwezxz/XNggTaQHYITLRPN0uSZ6pazdfWsp0BDQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 Mon, Jul 8, 2024 at 3:40=E2=80=AFPM zhiguojiang w= rote: > > > > =E5=9C=A8 2024/6/30 17:35, Barry Song =E5=86=99=E9=81=93: > > [Some people who received this message don't often get email from baohu= a@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSende= rIdentification ] > > > > On Thu, Feb 22, 2024 at 12:49=E2=80=AFAM Zhiguo Jiang wrote: > > This is clearly version 3, as you previously sent version 2, correct? > Hi Barry, > > Yes, patchs are as follows: > v3: > https://lore.kernel.org/linux-mm/20240221114904.1849-1-justinjiang@vivo.c= om/ > v2: > https://lore.kernel.org/linux-mm/20240202012251.1aa5afbfdf2f8b3a862bced3@= linux-foundation.org/ > v1: > https://lore.kernel.org/linux-mm/20240124124308.461-1-justinjiang@vivo.co= m/ > > > >> If an anon folio reclaimed by shrink_inactive_list is mapped by an > >> exiting task, this anon folio will be firstly swaped-out into > >> swapspace in shrink flow and then this swap folio is freed in task > >> exit flow. But if this folio mapped by an exiting task can skip > >> shrink and be freed directly in task exiting flow, which will save > >> swap-out time and alleviate the load of the tasks exiting process. > >> The file folio is also similar. > >> > > Could you please describe the specific impact on users, including user > > experience and power consumption? How serious is this problem? > 1.At present, I do not have a suitable method to accurately measure the > optimization benefit datas of this modifications, but I believe it > theoretically > has some benefits. > 2.Launching large memory app (for example, starting the camera) in multip= le > backend scenes may result in the high cpu load of exiting processes. > > > >> And when system is low memory, it more likely to occur, because more > >> backend applidatuions will be killed. > > Applications? > Yes. > > > >> This patch can alleviate the load of the tasks exiting process. > > I'm not completely convinced this patch is correct, but it appears to b= e > > heading in the right direction. Therefore, I expect to see new versions > > rather than it being dead. > > > >> Signed-off-by: Zhiguo Jiang > >> --- > >> mm/rmap.c | 7 +++++++ > >> 1 file changed, 7 insertions(+) > >> mode change 100644 =3D> 100755 mm/rmap.c > > You changed the file mode to 755, which is incorrect. > > > >> diff --git a/mm/rmap.c b/mm/rmap.c > >> index 3746a5531018..146e5f4ec069 > >> --- a/mm/rmap.c > >> +++ b/mm/rmap.c > >> @@ -840,6 +840,13 @@ static bool folio_referenced_one(struct folio *fo= lio, > >> int referenced =3D 0; > >> unsigned long start =3D address, ptes =3D 0; > >> > >> + /* Skip this folio if it's mapped by an exiting task */ > >> + if (unlikely(!atomic_read(&vma->vm_mm->mm_users)) || > >> + unlikely(test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags))) = { > >> + pra->referenced =3D -1; > > Why use -1? Is this meant to simulate lock contention to keep the folio= without > > activating it? > > > > /* rmap lock contention: rotate */ > > if (referenced_ptes =3D=3D -1) > > return FOLIOREF_KEEP; > > > > Please do have some comments to explain why. > > > > I'm not convinced this change is appropriate for shared folios. It seem= s > > more suitable for exclusive folios used solely by the exiting process. > 1.The skiped folios are FOLIOREF_KEEP and added into inactive lru, beacas= e > the folios will be freed soon in the exiting process flow. This requires an explicit comment in the code. The expression referenced_ptes =3D=3D -1 implies "rmap lock contention: rotate", but it appears that this is not the case here. You should either update the original comment to reflect the current logic or use a different value. > 2.Yes, the shared folios can not be simply skipped. I have made relevant > modifications in patch v4 and please help to further review. > https://lore.kernel.org/linux-mm/20240708031517.856-1-justinjiang@vivo.co= m/ > > Thanks > Zhiguo > > > > > >> + return false; > >> + } > >> + > >> while (page_vma_mapped_walk(&pvmw)) { > >> address =3D pvmw.address; > >> > >> -- > >> 2.39.0 > >> > > Thanks > > Barry >