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 2C439C3271E for ; Mon, 8 Jul 2024 12:41:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 945FC6B0099; Mon, 8 Jul 2024 08:41:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F57E6B009A; Mon, 8 Jul 2024 08:41:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 797386B009B; Mon, 8 Jul 2024 08:41:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 591346B0099 for ; Mon, 8 Jul 2024 08:41:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 15302A01F8 for ; Mon, 8 Jul 2024 12:41:36 +0000 (UTC) X-FDA: 82316546592.30.F623A07 Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) by imf26.hostedemail.com (Postfix) with ESMTP id 41829140013 for ; Mon, 8 Jul 2024 12:41:34 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.175 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720442470; a=rsa-sha256; cv=none; b=KQDcatLECGEi3f7RZPtf14SUo5WI6pdhWMp/lOiZFpT/g/bpuAosyF73oawKP+bkIAnp3b 5dWEBY8UwSZrjKwup7huG6zwdICaAxWHCi4gai5/CxShyM7rUKf+zaAZfAcI6N32EWnFQ3 8JhkB6DcQs7LbaZlTEjKT3vh72xiPSo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.175 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=1720442470; 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: in-reply-to:in-reply-to:references:references; bh=7aq8BrL89QpHro8jdNn8gsdKLZfMhUlzf1ikhsNBBo0=; b=Rei6vfGKgjTMlKlhufECy28s3QwCv6eY5jHyvVTEjyLeLOPbWVoy20iXe5aLBEZDXEhRmS z7HsjAMfewXM4LyjwNpUCZaP+TmGFIB7i7ANUQ9G5UiI8EL6L0tlqvKj6hUPCuto9R584t vyJxM2WZ6q86VnoahmTPUGOen9MkKvg= Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-4f2f24f6470so1260381e0c.1 for ; Mon, 08 Jul 2024 05:41:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720442493; x=1721047293; h=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=7aq8BrL89QpHro8jdNn8gsdKLZfMhUlzf1ikhsNBBo0=; b=c/DgYW+ODkDkvGhg4PTB7US41Tkcx0ZUCWJvc5ZwUcD2oqHTlF7ffGeh55mwAoUVP+ LCn27Da0JBDxX8UrC3aQRhxavnYsbMfFYf0waikxO1HttfV5wc8Sd9Z022ggCeyA6WIN YJn6iU3LsRe5Wf4077vWHVPVEd83G9k4xyTYtELgA6Xlb4tjUtmb8vlpGrNrVnnuwog/ DFHbmkYmdJ+IsoVfP3jDA/Wf7bYiHr4wXxtMIJPefU8lGBC7dh69KKPpx7eN0wNeCEOX W0bGjMze9uWORMuItVCSLUIbYKWQHutr/HOuLAcNpeaVf90WyVva+vAollpalfEctp6T U44g== X-Forwarded-Encrypted: i=1; AJvYcCWVP8MTIHFSTpq57/cuQlXNihpupp0SDimtLpRcPbq9Ufpd4V4IntLvYuMXLCoae8FGQ+c4p/8ch1SwUtxTuTScdpo= X-Gm-Message-State: AOJu0YwH72r61LJin5nbI5KdMnQhw2kGEY/BZiHxjTjgXRV+CJ0VbwM9 5y5OEMcS7vJGxfHMIM6+VjjE9iQO4RLPCBCaswoS6lqcxzdFUz25blZ6vaWQkcIXiUECfUnwiuf 9wYLnf0zf/ATEXD8TYe2fX18fhtQ= X-Google-Smtp-Source: AGHT+IESB2SRZW7CTTaqDSd+WNb4CFo48+ASHUNlUuv/cTGdOyv4UE1CcRYMD1wm6LgYVdplteb0xkSHTx+xFmngbGg= X-Received: by 2002:a05:6122:d22:b0:4f2:da8a:8b6a with SMTP id 71dfb90a1353d-4f2f4051a2bmr13338682e0c.12.1720442493227; Mon, 08 Jul 2024 05:41:33 -0700 (PDT) MIME-Version: 1.0 References: <20240708090413.888-1-justinjiang@vivo.com> <122bbe20-f2ab-4d44-97ac-76df8469d3fa@vivo.com> <4ca9836c-4f03-4792-9be8-f7db71a2b162@vivo.com> In-Reply-To: <4ca9836c-4f03-4792-9be8-f7db71a2b162@vivo.com> From: Barry Song Date: Tue, 9 Jul 2024 00:41:21 +1200 Message-ID: Subject: Re: [PATCH v5] mm: shrink skip folio mapped by an exiting process To: zhiguojiang Cc: Andrew Morton , linux-mm@kvack.org, LKML , opensource.kernel@vivo.com Content-Type: multipart/alternative; boundary="000000000000aa5964061cbbbb44" X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 41829140013 X-Stat-Signature: nfttd3mm3itfoowjoge95rqcjwe3ti8t X-Rspam-User: X-HE-Tag: 1720442494-426340 X-HE-Meta: U2FsdGVkX19y0Akq/yFtNbUcJHUSoJ6HL7XFZ8FRqOQJFSJfByNNqRxQmJbDbdJ7/AJWHP7iqlRPOdUMlAJyaGN5N8aDTUBZqn6Dzp/iTcR8NeJzb2+IhBIwpyfJ1M/TkjQTYb7l6A1g6PXb9PzvR4pOEooji91UW9m3tS1UnjaQwd38geHPApqqLBXyDyjX088O0Z52T+N4HAcpc6lpwkBHas5ul2639vvMxlj9OEWmFlEs+v7+sG7bcnpJUqdhHkmDDcAYnQDzNlckdfbe0zmzgTb1FkFuwExDe03KHmD95b/HGHZcEqQ0UG5A9yznhA/vuX8apqK2RYaAXjWW304opJkAGqu3waKIaGkiqORYEQjxawRJf/qnDDXHaRn86Q8HSPx6zQGdTGEo4Bjcl1Mk/viCU4TEOpdyeHsq1KmJlpo1X0JI7W6HvrAhEGraA+Pg7Hi+c3W54FcJmG/ruWj2fvhLbm/tvVPJdHHVKf6vl1cYfYYxF9EhQ2Y/Mdv3oFOU70qZa9UhW6gkJb1gLkI185qU8r1TeEsG80IqeF63LWeISgUsZ7OgxlSJGrjDPxi6fdqcrjIJ1MdY+OTx+cptaJ9noZtgDfIhXhWXAkmqsLUrCOc2343jLkGG0VXLwdG2JPtpuuzR6Qn0kyowmqR2Gd/jZtQw8D9KHHPwBVI6UD5qO1zM7kXEpF7bvkE8LNOGalNisttq9p+1h/iZ3ltDmCpY9AZY2YBocuP4nt5IcYTgOJB7jCIK8hkyDwYZHnZYBbW36cYxcjgMJzXA0HFUkOUFf7acf7mABZ224BIwZK7A6t3vl7ECIrt+DTYkyB9JWhX2aCazMRKX9LudX8G/M1+0nRxmkjstggBn00PmM3Lmw+oQEGr5WjGBYK7ZQG6NWlHX08d8nHQGv7s2dbgYEOyFVtcWWtHVLzpl0CQo/XA3XU8gKsJ4E2ldx0NEah6fh9Jqc4LYNuZd9bc ouPAgGt5 oYwNcCHlyvml9mwq9IVXCzAIufgTc8Uu1+i8AQ9j0EMkPOSJ315wsljkirvyKWkTUfRh64dIYQ+I0B29vELdOBWUxeT6blCKLZWQBKpX+uDJ6vIwnc4kcL5awLhfGc9uIn56Ko6zzSqqRQxDxqySpTX6kwmLoTrLMxoM0JvYAj7fTrgKYqfA2Ghhsj4NZEM7OI7xhxh2lH9nGjnmtRnljjjbjrXfsQBovN2WhNLsavSbl2x6hY2ZcSlGaEbNgi7LQPWagUQUrBNpWwO9Eu7s90Z7EZr5MfYwf5icEVOhsJMRokhUZQt4I1DVXlLB4kwAS0I/RFUsCHh2UNiL/sOaVqW0j0EC6HCEqGNJJHc6KxAfFJZ7cyujJ95Pqim504iCZ9ksUJKKrErFBUr+qAeVeBDKYhtYSw3lfdrDkcXkslTkRdbAAW3R17W62aA== 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: --000000000000aa5964061cbbbb44 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable zhiguojiang =E4=BA=8E 2024=E5=B9=B47=E6=9C=889=E6=97= =A5=E5=91=A8=E4=BA=8C 00:25=E5=86=99=E9=81=93=EF=BC=9A > > > =E5=9C=A8 2024/7/8 20:17, zhiguojiang =E5=86=99=E9=81=93: > > > > > > =E5=9C=A8 2024/7/8 19:02, Barry Song =E5=86=99=E9=81=93: > >> On Mon, Jul 8, 2024 at 9:04=E2=80=AFPM Zhiguo Jiang > >> wrote: > >>> The releasing process of the non-shared anonymous folio mapped > >>> solely by > >>> an exiting process may go through two flows: 1) the anonymous folio i= s > >>> firstly is swaped-out into swapspace and transformed into a swp_entry > >>> in shrink_folio_list; 2) then the swp_entry is released in the proces= s > >>> exiting flow. This will increase the cpu load of releasing a non-shar= ed > >>> anonymous folio mapped solely by an exiting process, because the foli= o > >>> go through swap-out and the releasing the swapspace and swp_entry. > >>> > >>> When system is low memory, it is more likely to occur, because more > >>> backend applidatuions will be killed. > >>> > >>> The modification is that shrink skips the non-shared anonymous folio > >>> solely mapped by an exting process and the folio is only released > >>> directly in the process exiting flow, which will save swap-out time > >>> and alleviate the load of the process exiting. > >>> > >>> Signed-off-by: Zhiguo Jiang > >>> --- > >>> > >>> Change log: > >>> v4->v5: > >>> 1.Modify to skip non-shared anonymous folio only. > >>> 2.Update comments for pra->referenced =3D -1. > >>> v3->v4: > >>> 1.Modify that the unshared folios mapped only in exiting task are ski= p. > >>> v2->v3: > >>> Nothing. > >>> v1->v2: > >>> 1.The VM_EXITING added in v1 patch is removed, because it will fail > >>> to compile in 32-bit system. > >>> > >>> mm/rmap.c | 13 +++++++++++++ > >>> mm/vmscan.c | 7 ++++++- > >>> 2 files changed, 19 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/mm/rmap.c b/mm/rmap.c > >>> index 26806b49a86f..5b5281d71dbb > >>> --- a/mm/rmap.c > >>> +++ b/mm/rmap.c > >>> @@ -843,6 +843,19 @@ static bool folio_referenced_one(struct folio > >>> *folio, > >>> int referenced =3D 0; > >>> unsigned long start =3D address, ptes =3D 0; > >>> > >>> + /* > >>> + * Skip the non-shared anonymous folio mapped solely by > >>> + * the single exiting process, and release it directly > >>> + * in the process exiting. > >>> + */ > >>> + if ((!atomic_read(&vma->vm_mm->mm_users) || > >>> + test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) && > >>> + folio_test_anon(folio) && > >>> folio_test_swapbacked(folio) && > >>> + !folio_likely_mapped_shared(folio)) { > >>> + pra->referenced =3D -1; > >>> + return false; > >>> + } > >>> + > >>> while (page_vma_mapped_walk(&pvmw)) { > >>> address =3D pvmw.address; > > Sure, I agree with your modification suggestions. This way, using PTL > > indeed sure > > that the folio is mapped by this process. > > Thanks > >> As David suggested, what about the below? > >> > >> @@ -883,6 +870,21 @@ static bool folio_referenced_one(struct folio > >> *folio, > >> continue; > >> } > >> > >> + /* > >> + * Skip the non-shared anonymous folio mapped solely b= y > >> + * the single exiting process, and release it directly > >> + * in the process exiting. > >> + */ > >> + if ((!atomic_read(&vma->vm_mm->mm_users) || > >> + test_bit(MMF_OOM_SKIP, > >> &vma->vm_mm->flags)) && > >> + folio_test_anon(folio) && > >> folio_test_swapbacked(folio) && > >> + !folio_likely_mapped_shared(folio)) { > >> + pra->referenced =3D -1; > >> + page_vma_mapped_walk_done(&pvmw); > >> + return false; > >> + } > >> + > >> if (pvmw.pte) { > >> if (lru_gen_enabled() && > >> pte_young(ptep_get(pvmw.pte))) { > >> > >> > >> By the way, I am not convinced that using test_bit(MMF_OOM_SKIP, > >> &vma->vm_mm->flags) is > >> correct (I think it is wrong). For example, global_init can > >> directly have it: > >> if (is_global_init(p)) { > >> can_oom_reap =3D false; > >> set_bit(MMF_OOM_SKIP, &mm->flags); > >> pr_info("oom killer %d (%s) has mm pinned by > >> %d (%s)\n", > >> task_pid_nr(victim), > >> victim->comm, > >> task_pid_nr(p), p->comm); > >> continue; > >> } > >> > >> And exit_mmap() automatically has MMF_OOM_SKIP. > >> > >> What is the purpose of this check? Is there a better way to determine > >> if a process is an > >> OOM target? What about check_stable_address_space() ? > > 1.Sorry, I overlook the situation with if (is_global_init(p)), > > MMF_OOM_SKIP is indeed not suitable. > > > > 2.check_stable_address_space() can indicate oom_reaper, but it seems > > unable to identify the situation where the process exits normally. > > What about task_is_dying()? static inline bool task_is_dying(void) { > > return tsk_is_oom_victim(current) || fatal_signal_pending(current) || > > (current->flags & PF_EXITING); } Thanks > We can migrate task_is_dying() from mm/memcontrol.c to include/linux/oom.= h > > static inline bool task_is_dying(void) > > { > > return tsk_is_oom_victim(current) || fatal_signal_pending(current) = || > > (current->flags & PF_EXITING); > > } > no. current is kswapd. > >> > >> > >>> diff --git a/mm/vmscan.c b/mm/vmscan.c > >>> index 0761f91b407f..bae7a8bf6b3d > >>> --- a/mm/vmscan.c > >>> +++ b/mm/vmscan.c > >>> @@ -863,7 +863,12 @@ static enum folio_references > >>> folio_check_references(struct folio *folio, > >>> if (vm_flags & VM_LOCKED) > >>> return FOLIOREF_ACTIVATE; > >>> > >>> - /* rmap lock contention: rotate */ > >>> + /* > >>> + * There are two cases to consider. > >>> + * 1) Rmap lock contention: rotate. > >>> + * 2) Skip the non-shared anonymous folio mapped solely by > >>> + * the single exiting process. > >>> + */ > >>> if (referenced_ptes =3D=3D -1) > >>> return FOLIOREF_KEEP; > >>> > >>> -- > >>> 2.39.0 > >>> > >> Thanks > >> Barry > > > > --000000000000aa5964061cbbbb44 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


zhiguojiang <justinjiang@vivo.com> =E4=BA=8E 2024=E5=B9=B47=E6=9C=889=E6=97=A5= =E5=91=A8=E4=BA=8C 00:25=E5=86=99=E9=81=93=EF=BC=9A


=E5=9C=A8 2024/7/8 20:17, zhiguojiang =E5=86=99=E9=81=93:
>
>
> =E5=9C=A8 2024/7/8 19:02, Barry Song =E5=86=99=E9=81=93:
>> On Mon, Jul 8, 2024 at 9:04=E2=80=AFPM Zhiguo Jiang <justinji= ang@vivo.com>
>> wrote:
>>> The releasing process of the non-shared anonymous folio mapped=
>>> solely by
>>> an exiting process may go through two flows: 1) the anonymous = folio is
>>> firstly is swaped-out into swapspace and transformed into a sw= p_entry
>>> in shrink_folio_list; 2) then the swp_entry is released in the= process
>>> exiting flow. This will increase the cpu load of releasing a n= on-shared
>>> anonymous folio mapped solely by an exiting process, because t= he folio
>>> go through swap-out and the releasing the swapspace and swp_en= try.
>>>
>>> When system is low memory, it is more likely to occur, because= more
>>> backend applidatuions will be killed.
>>>
>>> The modification is that shrink skips the non-shared anonymous= folio
>>> solely mapped by an exting process and the folio is only relea= sed
>>> directly in the process exiting flow, which will save swap-out= time
>>> and alleviate the load of the process exiting.
>>>
>>> Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>=
>>> ---
>>>
>>> Change log:
>>> v4->v5:
>>> 1.Modify to skip non-shared anonymous folio only.
>>> 2.Update comments for pra->referenced =3D -1.
>>> v3->v4:
>>> 1.Modify that the unshared folios mapped only in exiting task = are skip.
>>> v2->v3:
>>> Nothing.
>>> v1->v2:
>>> 1.The VM_EXITING added in v1 patch is removed, because it will= fail
>>> to compile in 32-bit system.
>>>
>>> =C2=A0 mm/rmap.c=C2=A0=C2=A0 | 13 +++++++++++++
>>> =C2=A0 mm/vmscan.c |=C2=A0 7 ++++++-
>>> =C2=A0 2 files changed, 19 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/mm/rmap.c b/mm/rmap.c
>>> index 26806b49a86f..5b5281d71dbb
>>> --- a/mm/rmap.c
>>> +++ b/mm/rmap.c
>>> @@ -843,6 +843,19 @@ static bool folio_referenced_one(struct f= olio
>>> *folio,
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int reference= d =3D 0;
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long= start =3D address, ptes =3D 0;
>>>
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /*
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * Skip the non-sha= red anonymous folio mapped solely by
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * the single exiti= ng process, and release it directly
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * in the process e= xiting.
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if ((!atomic_read(&v= ma->vm_mm->mm_users) ||
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 test_bit(MMF_OOM_SKIP, &vma->vm_mm->flag= s)) &&
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 folio_test_anon(folio) &&
>>> folio_test_swapbacked(folio) &&
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 !folio_likely_mapped_shared(folio)) {
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 pra->referenced =3D -1;
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 return false;
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
>>> +
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (page_v= ma_mapped_walk(&pvmw)) {
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 address =3D pvmw.address;
> Sure, I agree with your modification suggestions. This way, using PTL =
> indeed sure
> that the folio is mapped by this process.
> Thanks
>> As David suggested, what about the below?
>>
>> @@ -883,6 +870,21 @@ static bool folio_referenced_one(struct folio=
>> *folio,
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 continue;
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
>>
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 /*
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 * Skip the non-shared anonymous folio mapped so= lely by
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 * the single exiting process, and release it di= rectly
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 * in the process exiting.
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 */
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if ((!atomic_read(&vma->vm_mm->mm_users) ||=
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 test_bit(MMF_OOM_SKIP,
>> &vma->vm_mm->flags)) &&
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 folio_test_anon(folio) &&= ;
>> folio_test_swapbacked(folio) &&
>> + !folio_likely_mapped_shared(folio)) {
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pra-&= gt;referenced =3D -1;
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page_= vma_mapped_walk_done(&pvmw);
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 retur= n false;
>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 }
>> +
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (pvmw.pte) {
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 if (lru_gen_enabled() &&
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 pte_young(ptep_get(pvmw.pte))) {
>>
>>
>> By the way, I am not convinced that using test_bit(MMF_OOM_SKIP, >> &vma->vm_mm->flags) is
>> correct (I think it is wrong).=C2=A0=C2=A0 For example, global_ini= t can
>> directly have it:
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (is_global_init(p)) {
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 can_oom_reap =3D false;
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 set_bit(MMF_OOM_SKIP, &mm->flags);
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 pr_info("oom killer %d (%s) has mm pinned by
>> %d (%s)\n",
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 task_pid_nr(victim),
>> victim->comm,
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 task_pid_nr(p), p->comm);
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 continue;
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
>>
>> And exit_mmap() automatically has MMF_OOM_SKIP.
>>
>> What is the purpose of this check? Is there a better way to determ= ine
>> if a process is an
>> OOM target? What about check_stable_address_space() ?
> 1.Sorry, I overlook the situation with if (is_global_init(p)),
> MMF_OOM_SKIP is indeed not suitable.
>
> 2.check_stable_address_space() can indicate oom_reaper, but it seems <= br> > unable to identify the situation where the process exits normally. > What about task_is_dying()? static inline bool task_is_dying(void) { <= br> > return tsk_is_oom_victim(current) || fatal_signal_pending(current) || =
> (current->flags & PF_EXITING); } Thanks
We can migrate task_is_dying() from mm/memcontrol.c to include/linux/oom.h<= br> > static inline bool task_is_dying(void)
> {
> =C2=A0=C2=A0 =C2=A0return tsk_is_oom_victim(current) || fatal_signal_p= ending(current) ||
> =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0(current->flags & PF_EXIT= ING);
> }

no. current is kswapd.


>>
>>
>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>> index 0761f91b407f..bae7a8bf6b3d
>>> --- a/mm/vmscan.c
>>> +++ b/mm/vmscan.c
>>> @@ -863,7 +863,12 @@ static enum folio_references
>>> folio_check_references(struct folio *folio,
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (vm_flags = & VM_LOCKED)
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return FOLIOREF_ACTIVATE;
>>>
>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* rmap lock contention:= rotate */
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /*
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * There are two ca= ses to consider.
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * 1) Rmap lock con= tention: rotate.
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * 2) Skip the non-= shared anonymous folio mapped solely by
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *=C2=A0=C2=A0=C2= =A0 the single exiting process.
>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (reference= d_ptes =3D=3D -1)
>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return FOLIOREF_KEEP;
>>>
>>> --
>>> 2.39.0
>>>
>> Thanks
>> Barry
>

--000000000000aa5964061cbbbb44--