Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796287569; b=W6cGCyaTfCHAe4QWKQczc33dKhftc1ZN3aUrYcb4Qdr9w9UEMHBHd0OvPcb8B6dlTy0Q hDswH2U/cqOBsqr+tFoToJUqiDdt4owPitflfvTMPmHbvkz0R0SXBy490OZ6qykpH52QL OqFrcrKSwW+V9oumZAGuRif4DFY4UrCJ1cIZ5KDNZXVhq7u//8LqGj1dzFakQT6hZYhqw sx21RUREQa1qPk3/Sil3L3W6xHokzbPinDoPYwANzWUdYGesT0N2D61BWSCijXHsAVMAo WO7lgB1EBqPaU9LO0eHGyheNfuJ6Pp80y37WQh4MwdXw1RMGdhvFFNskO2VbzSItJTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796287569; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=0mtsUqg/lE/8vMjbuwrlYVVD/NYd6OAqXMbbGmyrQJs=; b=y5kOnxsR7SJr3BWelVJ4Qbq0h89LtRKrxmf7CHen1Rn079bv0V29OfnNflNi/wqVOnpE dSdaxd5qTZFEEiDJA/htjUFfAX4+45l15wG4pE9Ls38blZqe27vGsMuKh146uvGmkcpGg 4V4vkjhAT3ujrMt7jmJiheEFWPjH75jeOWaMuwSz+IljnPY4FVA53vpT95XxV9Q3omjgv +IRYxvtG0qzQCB/RACdxzIGVezp/gL8d0xe+hftuoSBS0qIEtYSZtSO1AH7kZwuMWoi2N 1l0WjZUnKCmgaUiJuQX4OgP9iTG7IOh82yfJmGB93onco+BrCsJLu6v7kojEMz+fz3A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=Elhdyvo7; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBE6A606A322 for ; Thu, 3 Dec 2026 08:46:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DBE6A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=Elhdyvo7 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso122235355e9.3 for ; Thu, 03 Dec 2026 00:46:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1796287567; x=1796892367; darn=lists.linux.dev; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0mtsUqg/lE/8vMjbuwrlYVVD/NYd6OAqXMbbGmyrQJs=; b=Elhdyvo715Mhpt1L6NyX6FYZNRVdxTGBpfOa4V0ZCcO8uF8/SJ0Pkf8BFVrBenAbj9 H53mMnp3y4pDecCwGJKW37YmcmTbeonY2Ox6OfPTYyiwBFO7V01h8GZNny+9W5vGpPH6 YkouZl3r8xsDR7oWUzkJjytN5mZNfsibaHe2qCVDXCy15P977ti6jntDQ4JM73wbPcS0 c0/oUQ4Y8KpaR/E34R04JWJthivWRXMqQBChICoIqFZI1r++tQhRQ4KRoO1K3woajVyB Juu3U1rAhmBaPBmbfrtGI01hIH8HuRQq8PBUpvs1FirT6CA1XeSrgcXp5TthIox6e6+t zjPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796287567; x=1796892367; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0mtsUqg/lE/8vMjbuwrlYVVD/NYd6OAqXMbbGmyrQJs=; b=pgB40T9eP0OrapSdPHPXYard9e+3MBO1VFDakAypGj1Mf1Vh6CzlYXZMF1dsDPH/h3 ixgZP5bXPU3wHV/e9FAES1O7oSjhF1MkzZYDWY05GvdlZm0mhim4BH/D0txg4Ql+y49d dCWj6nqZXT+IT2Iw8mkxtoJjF7j3YADz7NVTp1+at2H/RUXLVMCHZoGHYQkIbthyG1wA 5/BHmGH6TwTCFfpCQdbx616nMQt0wZS4rNbs4eDD03IqTXn+aQaP+uO6sd5X/sX85Aai VaNCIF520INy6/2s5rj9qSqfqpjjQuNQSZTcI7aTDyJgOKSG+iRTf0uEJvGIaF2WvZEC 9ptA== X-Gm-Message-State: APuU4Z8a8j3jlo0eE3g37Q7UZ1Vng10b27ixz1ByYVZaXvghf7x2DTm7 CwxL2LNGf/esXYXIpy1OFEG0FUceAoxdFc5ywofz5kzA7/HY37vnTLKSZKTJdRKIOH0yA1+pVum uH69ynno= X-Gm-Gg: AZFdTZe3p1+kUdNDBPQiQnUvKhZi1qkl826FVU1uuJi1vtWe7OWR8tVIuOgr/o95aXn sV5qVDu8MgdK8k2BNqfTaSvW1vwBL+50ykG/6CIRYn/3cZJHH5GzKVj656rLS0+wlMzUYXe6YEw NNCYShp99OH6hoc0kW8DSohjPHeUi+k6muX4RFZ+7zKsa9LtIdv25GetZBKTUrM1AtC1xDUvmhn 9hsAiAh/DWrSYE9nJgRpZGUTVEy42H90vrC9HbKX2h8xAU39GZ2eQMJSs8tVUcruRE2iQZCzUxf wXW5vxrQWMVKhtmvH56UFVBe1+/m1q+Ixzvy/8q5gaMaKBFJunNf/N8AXTJ1Ek9zWBH8oazoXyl bH0mrOjd2t7yaOhxe7vkcZ+z68NGqmwLa70Lf+GJ2iFKeAG2dWx7Hgdbdu0rL5uqv39jyegPVp8 tllauCcAKkeT3laoXlc2GRaapAxw357UGknr8oV+sfaOQ8dvX8Q19KhJuUgLneEUslnvPF4vbLU 0ZINLRjGcgDoV/MEYeOECdAp5f8Kj00gkSuxWiivsW6gqoMSgZlk5YMelCsszq1qRxWP8ggsH3L 1IPjIbh+coOOxQM9zVJ9PmFWhFaoMEXuyFRdyAikYQ== X-Received: by 2002:a05:600c:3b99:b0:4a1:777b:8a12 with SMTP id 5b1f17b1804b1-4bb8880b984mr974895625e9.14.1796287567329; Thu, 03 Dec 2026 00:46:07 -0800 (PST) Received: from localhost (109-81-27-207.rct.o2.cz. [109.81.27.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb9067846esm878541505e9.4.2026.12.03.00.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 00:46:07 -0800 (PST) Date: Thu, 3 Dec 2026 09:46:05 +0100 From: Michal Hocko To: sashiko-reviews@lists.linux.dev Cc: David Hildenbrand , Andrew Morton , "Lorenzo Stoakes (ARM)" , David Rientjes , Ben Gardon , Johannes Weiner , linux-mm@kvack.org, Chris Mason Subject: Re: [PATCH v2] mm, oom: add rcu_barrier before hiding victim from the oom killer Message-ID: References: <20261202095450.296675-10-mhocko@kernel.org> <20261202212147.379270-1-mhocko@kernel.org> X-Mailing-List: sashiko-reviews@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed 02-12-26 22:08:16, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 2 potential > issues to consider: > - [Medium] mm: delaying MMF_OOM_SKIP in exit_mmap() breaks oom_reaper > synchronization > - [Medium] mm, oom: redundant rcu_barrier() in exit_mmap() and > oom_reap_task() > -- > > commit d8b9a20b6dcaba9ce0a826a457c923a1fe4ea9c1 > Author: Michal Hocko > > mm, oom: add rcu_barrier before hiding victim from the oom killer > > This commit calls rcu_barrier() before setting MMF_OOM_SKIP in > oom_reap_task() and exit_mmap(), and moves setting MMF_OOM_SKIP in > exit_mmap() after free_pgtables() under mm_is_oom_victim(mm). > > > diff --git a/mm/mmap.c b/mm/mmap.c > > index ec55ccbb88055..deec8f3d20d05 100644 > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -1318,19 +1318,11 @@ void exit_mmap(struct mm_struct *mm) > > /* Use ULONG_MAX here to ensure all VMAs in the mm are unmapped */ > > unmap_vmas(&tlb, &unmap); > > > > - /* > > - * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM > > - * killer will only skip this mm if it's already freed all it can. > > - */ > > + /* Free batched pages during unmap_vmas ASAP for oom victims */ > > if (mm_is_oom_victim(mm)) > > tlb_flush_mmu(&tlb); > > mmap_read_unlock(mm); > > > > - /* > > - * Set MMF_OOM_SKIP to hide this task from the oom killer/reaper > > - * because the memory has been already unmapped. > > - */ > > - mm_flags_set(MMF_OOM_SKIP, mm); > > mmap_write_lock(mm); > > unmap.mm_wr_locked = true; > > mt_clear_in_rcu(&mm->mm_mt); > > @@ -1338,6 +1330,15 @@ void exit_mmap(struct mm_struct *mm) > > free_pgtables(&tlb, &unmap); > > tlb_finish_mmu(&tlb); > > > > + /* > > + * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM > > + * killer will only skip this mm if it's already freed all it can. > > + */ > > + if (mm_is_oom_victim(mm)) { > > + rcu_barrier(); > > + mm_flags_set(MMF_OOM_SKIP, mm); > > + } > > [Severity: Medium] > Does delaying MMF_OOM_SKIP until after free_pgtables() and rcu_barrier(), > and gating it on mm_is_oom_victim(mm), break exit_mmap() synchronization > with oom_reap_task() and process_mrelease()? > > oom_reap_task_mm() and oom_reap_task() rely on exit_mmap() setting > MMF_OOM_SKIP before acquiring mmap_write_lock(mm): > > mm/oom_kill.c:oom_reap_task_mm() { > ... > /* > * MMF_OOM_SKIP is set by exit_mmap when the OOM reaper can't > * work on the mm anymore. The check for MMF_OOM_SKIP must run > * under mmap_lock for reading because it serializes against the > * mmap_write_lock();mmap_write_unlock() cycle in exit_mmap(). > */ > if (mm_flags_test(MMF_OOM_SKIP, mm)) { > trace_skip_task_reaping(tsk->pid); > goto out_unlock; > } > ... > } > > With MMF_OOM_SKIP moved after free_pgtables() and rcu_barrier(), > exit_mmap() holds mmap_write_lock(mm) across sleeping anon_vma, i_mmap > and RCU barrier waits while MMF_OOM_SKIP is still clear, even though > unmap_vmas() and tlb_flush_mmu() have already freed the victim's > anonymous pages. Correct > If oom_reap_task() runs during this phase, > mmap_read_trylock(mm) fails repeatedly and oom_reap_task() finds > MMF_OOM_SKIP unset after MAX_OOM_REAP_RETRIES, emitting false "unable to > reap" warnings, task dumps, and debug_show_all_locks() output. Right. This is likely unnecessary but I would consider it mostly harmless. debug_show_all_locks is nop without CONFIG_LOCKDEP which is the case for most production workloads. Dumping the victims stack is more noisy than necessary but I would rather wait for this being a real problem than developing a specific solution for that. > Leaving MMF_OOM_SKIP unset between mmap_read_unlock(mm) and > mmap_write_lock(mm) also lets oom_reap_task_mm() grab mmap_read_lock(mm) > in that window, walk already-unmapped VMAs while blocking exit_mmap() > from starting free_pgtables(), and set MMF_OOM_SKIP in oom_reap_task() > before page tables are freed. Yes. We cannot have both. oom_reaper is delayed to allow normal victim to finish properly before meddling with it. > In addition, gating mm_flags_set(MMF_OOM_SKIP, mm) on > mm_is_oom_victim(mm) means processes killed from userspace never set > MMF_OOM_SKIP in exit_mmap(), breaking the MMF_OOM_SKIP checks in > process_mrelease(). diff --git a/mm/mmap.c b/mm/mmap.c index 0b19c720473a..eeb39eaeb23a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1330,10 +1330,9 @@ void exit_mmap(struct mm_struct *mm) * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM * killer will only skip this mm if it's already freed all it can. */ - if (mm_is_oom_victim(mm)) { + if (mm_is_oom_victim(mm)) rcu_barrier(); - mm_flags_set(MMF_OOM_SKIP, mm); - } + mm_flags_set(MMF_OOM_SKIP, mm); /* * Walk the list again, actually closing and freeing it, with preemption > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > index 3fb70495f0826..6ff2650e1d58c 100644 > > --- a/mm/oom_kill.c > > +++ b/mm/oom_kill.c > > @@ -614,6 +614,13 @@ static void oom_reap_task(struct task_struct *tsk) > > done: > > tsk->oom_reaper_list = NULL; > > > > + /* > > + * Make sure that pre-exising call_rcu users will get a chance to > > + * free up memory. This might have been exiting task itself as well > > + * so call this before we hide the current victim from the oom killer. > > + */ > > + rcu_barrier(); > > + > > /* > > * Hide this mm from OOM killer because it has been either reaped or > > * somebody can't call mmap_write_unlock(mm). > > [Severity: Medium] > Can oom_reap_task() and exit_mmap() both run a redundant rcu_barrier() on > the same victim when MMF_OOM_SKIP is already set? They can. Unless I miss something I do not see that as necessarily wrong thing to do. On the oom_reaper side of things this could slow down operation unnecessarily but this is not a fast path and it should provide a way to ensure we do not allow oom killer to go after another victim while there is memory being freed through rcu. On the exit_mmap side we are flushing after the victims active contribution to the rcu freed data structures from the page table freeing. So I would say prefer a simpler solution for now. Let's see whether there is a general agreement with those decisions before I send v3. -- Michal Hocko SUSE Labs