From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796246525; b=xXsLh+oJkty3qxIyAKI+E+NZaxxQyyFCJlULhc1tK5wrICtx7QJSBrDcrgDCNu/m7CLv TajMUJvSlVALG0YmqBDe2nKQtfyhrWJ4eH5bvCD9fKlNow3VXBGIoSYbEa3i2VuUgx8jg bdcphyFvSDKuH+CtHlAB1eUcQA/nTRGOoN38wWGEaU75NxbQvXdUvtneq8v2QEVylHB7p +tR0Hh4oHP4/EninGvgOdgDgi8ccxw6AHoIgQGn8yb1O9FnlIqhiLh6AeAMMZPVLWryZb Tr5djoj5pNArJXJzK3o2J3ShXqumeq8h3EpWfYrH23XbFIFNG4rMq1BZikhTXqmzLqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796246525; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Zrnf6GNBSM/deERw5ax94c8nLmA7Eq+UfINSGju+0Sk=; b=S++8yw3bQ+zZabUPGPLmDLKcH2wQSuvgL8IgugzkEpB4nBnYUaBOyfroLN5dWSP3IWiD 2w0Q2dk7GcVwMM39NzYzCzA7YMctwnPIDgSqLa4sCG3EKbvX+pPJfHevtN+lKbBeYE2xf L5nLrzw6LjLDsEGQSHzst9LamLc0rc2TaIGmD2X6pjpe7MguiZdQBybzq+HZ/Cu8sTie/ wbCwP2jm5/BiCiXt5hCuPL5mECs6xQktBHxo+loJfIpEkxdSJHuI+WWBBRhWpVpGDnlnQ JxFxIa+Klxb587iwCL9ODCaZiyt48xAiyJWRka8zFv+Firm5S8JxwS2QuGSnsyUecYg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 57C8B606A330 for ; Wed, 2 Dec 2026 21:22:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 57C8B606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bba5e17cbeso73565415e9.1 for ; Wed, 02 Dec 2026 13:22:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796246524; x=1796851324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Zrnf6GNBSM/deERw5ax94c8nLmA7Eq+UfINSGju+0Sk=; b=VaN6HEpHcuI4lFlcsNXgjVeJFj0w9xXnAMZroJ17mCDRGAlsEpqPVTJohi0ClJfQ2q cN1bzvMrbAeXgTTvL6an9qeDFHdjE0EG2lEDoCkuB6MgDRDnIlRaM0oXfGHggZAsbCId c0h2Ak1W+taSawNCDlBn198A4kjMNcND383buw7kWKPTR13vShJBVlXE1vv9WE9wrUug jlfD4CBHumXtiS0hiRKh0A2y3gzV7HacS4EdVwF2409xCCzlTGoNO6hkha/uI1PmXz5z MiLgA/hEyhGiV58ENp2AatUoLDJ1YpT04wU9gJj0gJ3ij71ZSOYco891uvbyLGUtGixl a64Q== X-Forwarded-Encrypted: i=1; AL+hErFwm2FloIsWZV0RDqxT1CKLI8Vj3BJJBL5y6gCXkg0te55+NJRyhC+bcLoE9ib2MyJkgBxkN9ndENZDWPU=@vger.kernel.org X-Gm-Message-State: APuU4Z8JSZs7rpU2LjIVmhdvNR3njV0+6tvjTatseLHHYSa3nCt2DlBq VLRyDf9mdh4HMH/x/2J9eXuPpo8jpKo8oMOsWYeQnJdPFaN38xtupFCB X-Gm-Gg: AZFdTZehBhtqqxH2wfRxQiPiPoIbx+EueFgqLUmbC88aMybrMEPiGM1kC7zLihDeQtN qsZOUGH4544qArMEf/9HPwZUDgrRbHbShH5zyPl6/4p7ZmAPmFXYvsPvP5OYN/cL6GPkU2OzndX yS6Yfc60Ywz/vHHvkTb80/UbPLNBzcs9J0lzsZIv6pB6iUK0H/K4/oCYFsQ9TGcKxYoKPv5BPPG UJNj7tlWmAiMbQIuIHDbHhsrPO2AY1of72t0p0+zdh30QX06jd0L+Bx7KMztGedKAMRO7I8UmGO SOzVIbQyqHYV0Qs4PVABWAfeLE0dPgtw2PLW5me243y25jeb0nx6D4Pqk+7TN8nrnOUhDP71Ko5 57qgHbS5JDoGiYUWUzRrP89qSlDGJ5jXYYmstdumfgKn45kifcPlJVcpkogDrG+2KjOFz+gZo0s lE4b+dDvduB7YfHADNUORMWPZAD8BkmohzfDiT8GbC7zW0pTVzSp45qYUAKFzTdM4Snfjz6pt8A /GsF3DUhizpAw+c0ZCIFkCL1onRyR/E0Y3L1qr+5EvykBkEUv1ktFLQX4xN8J4rN1uy2POmDePy qyzWgiPUj2wgwm2ww0JpJu+1NDPXiKhvP1A8wIjDebo= X-Received: by 2002:a05:600c:848d:b0:4bb:694e:496c with SMTP id 5b1f17b1804b1-4bb88810b39mr868159385e9.22.1796246523627; Wed, 02 Dec 2026 13:22:03 -0800 (PST) Received: from tiehlicka (109-81-21-11.rct.o2.cz. [109.81.21.11]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906d6a13sm697611305e9.3.2026.12.02.13.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:22:03 -0800 (PST) From: Michal Hocko To: David Hildenbrand , Andrew Morton , "Lorenzo Stoakes (ARM)" Cc: David Rientjes , Ben Gardon , Johannes Weiner , , LKML , Michal Hocko , Chris Mason Subject: [PATCH v2] mm, oom: add rcu_barrier before hiding victim from the oom killer Date: Wed, 2 Dec 2026 22:21:47 +0100 Message-ID: <20261202212147.379270-1-mhocko@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202095450.296675-10-mhocko@kernel.org> References: <20261202095450.296675-10-mhocko@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Michal Hocko OOM victim could have released quite a lot of memory through rcu_call path (e.g. page tables). Call rcu_barrier before setting MMF_OOM_SKIP on the victim to wait for those to execute before the oom killer is allowed to pick another victim. Also move MMF_OOM_SKIP in exit_mmap path after page tables are freed to capture as much memory as possible to be freed. This is safe from the forward progress POV because oom_reaper will run concurrently in case the exit path gets stuck. We are going to see less memory freed by the oom reaper because it cannot tear down page tables directly but that should be acceptable. Reported-by: Chris Mason Signed-off-by: Michal Hocko --- mm/mmap.c | 19 ++++++++++--------- mm/oom_kill.c | 7 +++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4cb18b217048..0b19c720473a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1314,19 +1314,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); @@ -1334,6 +1326,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); + } + /* * Walk the list again, actually closing and freeing it, with preemption * enabled, without holding any MM locks besides the unreachable diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 6ff1e93ec6e3..e0c2e3e647aa 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -628,6 +628,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). -- 2.56.1