From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7832606A322 for ; Thu, 3 Dec 2026 08:46:12 +0000 (UTC) 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=VfNfaD9X Received: by kanga.kvack.org (Postfix) id B4F076B00EF; Thu, 3 Dec 2026 03:46:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B26436B05B4; Thu, 3 Dec 2026 03:46:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3C846B05B8; Thu, 3 Dec 2026 03:46:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6D27A6B05B4 for ; Thu, 3 Dec 2026 03:46:11 -0500 (EST) Received: from smtpin17.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F1F23405D5 for ; Thu, 3 Dec 2026 08:46:10 +0000 (UTC) X-FDA: 85502039700.17.AD1F27D Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf29.hostedemail.com (Postfix) with ESMTP id D812412000A for ; Thu, 3 Dec 2026 08:46:08 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=VfNfaD9X; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf29.hostedemail.com: domain of mhocko@suse.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796287569; b=AdEqS28Wt3Zm7MOR7pTNFzPMuS6j+V3TGXkpSPZ3/mqdCostffmAYttm2fSycQxGizVJch asvB2ztnegbhJhepCUKEcdIvtAbGZF3+lCwVOO3b8EVHkAACFFquzy2UJYOLXQB6OPemGl b8MocFwbxAJuHY2Q2YIhXv5QEa7eKiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796287569; 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:dkim-signature; bh=0mtsUqg/lE/8vMjbuwrlYVVD/NYd6OAqXMbbGmyrQJs=; b=Tc4An0WmulXgQtAA5YikFVtTSiZQZiUPix/uiY5Y7LXo3AGZPE6H7toNySXjsk72qSO+g9 iedFji1uKRCBxhsxhXdp5OODbYP7hiH8+5r8r1KF0psDqbmHsHmJu0aHhTr6ZB7YeNP4K8 vV6fSIThdmXcon1G+WR+ONitbaWXsMk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=VfNfaD9X; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf29.hostedemail.com: domain of mhocko@suse.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=mhocko@suse.com Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-492690dd5daso10866655f8f.1 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=kvack.org; 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=VfNfaD9XhJFuqEKospz0Ujf6ZIkvozu8RV/uW3HomwUe19bBEbmquxzrfbJSgJNohm Mh410kPpPVcN8gy0LJ7rbQSolRlgDTOKHjqVcaEEiIj6MTw7OwfEwRh/FJCh+vfcPFT5 GotiW97axs7YFfnDQKLtwq8tvbLsEDyoLaNujxsy7Q4FBEdPWWafsHx82dHqbdpzwvdb Jjqx6CL6Y2WG5PmBeeoA1lKhP2IGzLwoEdEOlS9pB2F1KmD7VSQRFG61xYh4FYjTvvR4 BpD7sq6716jy1Hocq55QWjfT7JNQlX40ZRJ57AKbr95d1xoY/Og4A7N8VI8GL5pg2Rf0 1qpA== 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=FYK3G2SnONGfEAdLfvnolsJCo1rUfGeGR8ifdOCHO/Em5UPE0XFhzFuRjwRJCOg/uu I/H7/CApjIVaKB9vPEfcgmfCwByx5+W55gIygO3e7En+bJILn0R7Q7BxUOEvosH6aL+6 KsflVKhvaUoxokkcf8rilSL+4gbethEiRs95Tv5zkSZzacadG28ta0aREgWqw7OOzbRI bixQHgWQUoLc6+JeHUAIUn8ILEY+cRqjE98eGQvh4MCFOiYGMSDIrhLwx1IwfWuXDI0u Gyjo86zMS8pMqXQ+HydnDPBesz8vLR2cEmke2yBGvAWGwNUUDM6/v9fmHhGvl1mlbk26 hvJQ== X-Forwarded-Encrypted: i=1; AL+hErEhOZpn2PCm1dX2BC6K84Pfob2kmMaRbqkVC71MIEy6xqsjZS6shMvaBXEO8MPnuoOne91OtvjUpQ==@kvack.org X-Gm-Message-State: APuU4Z9/9/HcHyhNBBF+RlONzAp0ipH/eiH7DNpb+KEgikOTq/o8OjWP r1kHTfCdDAFJjZ0lE7gn7MPkuooLrBluJROtMMJ98B2QmzZh+PnkIzM92XmELxEzQaACofncstp d+gFsQT0= X-Gm-Gg: AZFdTZclBYVHGfJUQCUgUWSBekpmve79QHJeu8Kinmkmodsenaw92Asg97cN6PBNHCv Qyz1ODiUlSqOM00I63n4yaKlu3Gx+CHI7NzDfORuPrHydnnllULzZ3JurA7hqmoq2I/eGefxvTg djbxbWq0AN8PC9UaTj7neLt4SGWrN2eZsibBU5qEzzCAbgC6438cX1B6IINKjUO1IUmo7e4xql7 o8VlZAVzxBpemwQdXBX76/2fe7ISLhK8CWTbIX+sQrNZjnDaNK9V+qZcZwWTEFSJIOPYdJGixNH Oy29Hvkxqzy/ixDOt0rxf1c4ymnmzLXjT/QSlc50+8KSRdmYh6QoAEnXGTbfrGK2vh3MiPjkE0j E6e6ZsQDdNrwnz+gqZYf1n6yfrw3ax28yX+2Kz4H4sCeFAakFlCBzZAfRmseHlMA2f7SQvl/i51 JIbofo9p7AuhmVFlL+ZhB9ye6+DJRv48hTHnfb/oZUjEbAZHOKrNGps+Ib5Ir+qfKozyK9aGKKX IAZFjj1Lr1iJkjLSylBI1YAFwyTPhqOOtzyF+tEkHMfwMPUvC+q6zeqMS9Z1imU7wyN03mNQouf wv5zAZ1E9KwUrOsPyyiQ6GY/jir1juahPN6DOgq6nA== 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: D812412000A X-Stat-Signature: 7cuchg7ptsyri8xnugjfg66aobf66gqj X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Server: rspam02 X-HE-Tag: 1796287568-212849 X-HE-Meta: U2FsdGVkX1+PX9z6AStuusBqvgQXqFWmOeahbFYTZSrIvPF1HrMdS/sk6ofk7JTVgmy4+6UiNtCOUEVa63CRXweFy3qHn2YPSZ9dI05XOZqPuNmpdJG4JlNoEBlzWgw6bP0LxnaQvgr2gOz7IRwG/FBGTDz8h+DMPBKEUG36f3gy/YX2RYjp2HtiPj13F3Ox//Ivsn/Xd1KhpuTbPOSIalm+kEbQu62tdhK144Q5BHFj/jvb4m6rDvrIzabPj4X87BSXZtrcrurXHlDEuoiN0RO+RlP8iUJwmJTlLrliRBBwQQSaziU3qU0PO+gvA+N16qXNZHrNRmf+1AHs6EaO3de6NV7itNGyYL8EehW3fJidQLrYqAzIRx2HrgXEBLM+gH2QN1lHz7tHbbJbtK+ULw7k8hMVBZUQ6gWdmoXjO4FOJamhXfL0dqKA6qa3VPXF7KrIib/kWYZv5PvO7pCyMa5iNfXkQ+ZKbfX0yQd1Jw16YLgsfwPlE0j8M2+6bOsBW9UPcY5HZ48fQjdhRH7qxBzLqPP/MdgCFtE5/rB11ekhZbvQtE/1o306lklctNYE/1k1/FeY8PfPYA6ak/8BYVUV+AW+CNQH2HFowRso7bUHMJnI+ExyOWpb2fJAxutG/J1vo5I2LV0YkeeO8BsjZLVgHSbx/ifo90cvx2nsFbBVQR+jlWhLDbaQCpNpTphTHeWw9nJr0CKgpJXNDKMxIl0gZIaFV1vj+mxZuipywUgR711lsek5uud7E7IL3714D7ASTrjWE28AASFSGVVBfxrnF8LjBY9Jx3kyzSSw4GnxgtVIaS2mxGW9P2/2vfeqFg3oWo+2vAu2Vw+83W15GTv7ZdYetEHpx4vp9U3sE2+lryOk3YkvIxsZwHPU4Kfy8irz5g09yAnx7UuV+80K5hhozhI+zExblvh6imfXoMIDpK5NLTjcE9IFtR2KD+nMhv0GRunto9GSIpdJJdp 3FIdg8Vn mnp5ntOF/gPnJRrA2/AJ1zxO/C9hHV4u0/k/K+l0HevD1NURXYt05kDATQE6qrqxXOC9u0PJbW3jShC+DTlEsPTfod/BI3NrSHC9D6jZAz6pEAXBhf9+sVRFyPYhWt2xCJ9GwCR8SiixfbHuWTccmyZZwK2lWWpN8bmBxQkrR/sTiiMTtRJGYYdqtIMPjEwIUYHlv466JXuVdsF+9hjKREHAOv4GtVv5YH7t5ZBDlucHEli3dEJUHeA1zOHtEQjY6ZsL6s1fNjvHHm5KXLYrCHJd6fMr05GFDI/M1ajrE5skgxadJixfzxGNYgM0M48xtZEEcV0TXwc/Z+SKNJ6ggT0N56uUyWeztVI666anc7s9b+k2yarIXKAEDQ8snjX5LAqmZUSz13pWiWZQzP7wAYxvtINWfeZ8QCuwobinYv9Efi3Dr+k6QejVRlutpUelWkXeGDLCn87PCmRaQmOx9V17hm+rD4gA8vjx/gbG4qmCQpBPhdyUjIGuuEhPfSoVw77w0Jp2bJ0WkTUOTXXadsywNYch8gNgKYhRqHgHMWuvG1xna0zl+eOYhThWY/YwXuzHHzhxyz9PVmjhsQYDgBlqA1kWS2kKaj9uNENxy97S73KQUCLdRCPt7UxH2a8S/pG4v1vdUJxrTbp8VINzccuG2eJcT9k/PqSLBJV7b4bmb8cmSZ0ZMsZ0cLvaKH9mX6ntENUtj7yjMvnw= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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