From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796205304; b=oCplBt0KTn5te/i1b2kkCdOxlRP5ciSwpXAaE7gL83tCuc0pkpPwGSiFYrt0WvMOrfmz 9wI6Vmb3SL/L+N9QRAOpauAWQJonW9GsZuGyEkTVsImYGGniTeV0rZ+Gt0EWtTZoe5sF3 7AS0xLIj3Q8uPW45k18IFg8JPAh+PUK/6zliYXSsBdloqe6zreBTNO/bHNHkqaWD0q+Rn 1QeD4M/o1xwYsma3I71HgVeIxf0fxkYi+L9krcFFb0j705nc5rjCGMYA680HaZzeCfevP Uq+nAXCsoUc1dUBIS12Uk9AbfyWjkCxeOnNuf4pTYVb0eAUPzz0WjZNBryDnDHpSjBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796205304; 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=aO/xVQmVRfTGeyNcbeAXuWcDLP0cUqga2KQq8EpcAKQ=; b=ATNLBuieRqi0g4+qdAd6x/G457T6uGIzuVcA0YiK0nokG/ZEun59GHeTgBNYeP3r+OMD iLWt1+KUmJWYP43NUPNwGH/AyaZyzzRH7elYinx2NDiZeSsh4CvDgo3uENlNi7SfIWAmZ Xvgnan3OqKVvWMWLIuB2nzw8IjRlcfeYHO3cOyJeQNgIgIU3/dL1ArdcN3NBalDMyy99J F2tVM64qRfI5zO9SEM+5xOX2a4Q2gG1l+BbXuK34numweh4MHo97H+OAbay/l1Ccax6A9 GlXCYRJmFhoAl9/aI8iLTUGStOavLiZs9F+FfLGcsUfRp/awSWIjWLsdoG6Qn3IBZdQ== 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.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 4BBAA606A680 for ; Wed, 2 Dec 2026 09:55:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BBAA606A680 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-f42.google.com with SMTP id 5b1f17b1804b1-4bb6ba3b244so131933645e9.3 for ; Wed, 02 Dec 2026 01:55:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796205303; x=1796810103; 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=aO/xVQmVRfTGeyNcbeAXuWcDLP0cUqga2KQq8EpcAKQ=; b=cSXQ4Wd7csSIlg7w/NSuWid8CpnlpjzD1JGx8kIbyW7mrkYslTBqFXpH6NRyfuGNRE c9aFyfkdGMxnYlKsF0eKw2LaxxIK6Bq93SHslOgR40d3IjeB8fy1c8L6eLJJ8Pd+8nCm n6KIJoTtDu+QgoVB3wChTFaZYzAvYRktvc6yP1/lqvwlt+MKXDbR8oFesXnwp5yIQP9E B9slh2I8T9kztXup3Y1KLuz5GzzIeGdtulHeOM+gpCg6264T3BqRx21+xDVHezA+zjX4 JwJOcYMc12cYW+D6yocPIwqAInd5cGcOz826wUDApwk0hGOhpMGVXDS+ihGZZTzPfLnL GXeQ== X-Forwarded-Encrypted: i=1; AL+hErG2TBumz29VPdgh9EOLl16qtZqMw0SbgjZRrTR2A4x3VRxANsLUf8q5ELVw7k8Lu6PrN3A5MewUoD3Dzak=@vger.kernel.org X-Gm-Message-State: APuU4Z/O/yw70zmKCnXnHQRZOid6XQqZA4lhrewmiOa/4HtE+A/zvpkR tOFAnZ8zdFX1g2RBq0+85cyVaVZc0g8nS/9EY1LE6RGWiVttV3O12tMW X-Gm-Gg: AZFdTZcpi8WwcjPj9flpE0DzORFJNpAFQPlAtXz+1PsZhSfs8WeIRXA8LlO1m+8JiFj +5uTyO4N2Gsx5YQGPz9dcLpYuthl5PIrSlBhKG+ugh7wPEiaBm8HK/3Z5bflou5PQsGVG4VSwOk wyvus0+LiMEag34QLRsgzqiF6CRKvhSY/FxKCBmcuC4DTzetk7xoKoDVsuLi94qypUt/obyewpN kFANVQ6ZkoSjhi8y/6pjWWIma/GCanB/Vsyvtn6b+UK+rLptLZpmTAT3evXva+Kr3DOCDyd+fy/ 0mM6+AMRM3tV2T4rLV4RCl92tbng+lDEiEfMKDBCH7W0pcAjs94kLVF9l9duihcdZwHLZst6gBF w7IgE+tbPl6Iv9TI716f1Ysz2v6rpsm/TQIX+HDCm3YmQtcuQA7iYPt4BE3d+o5+ihDKK7mbQx1 SzFU+Frou6VFTKEPi9/sQ5lkmfi/Y0q0GueiocKE/M2oSoqCnvNeB2ClWAIBF75I5NKCKvW+xie QbGXriLXZCyDihNAvLw07NvPHHAWrFp2LiZn6alyqo4jp5TQl68/ZYheLfUtWou2FWezVqKlW6A y/joGT3ZFD8N441Ob/lHHyKcJxszSmCElU4oDtU= X-Received: by 2002:a05:600c:6383:b0:4bb:c483:ec9c with SMTP id 5b1f17b1804b1-4bbc483eda4mr186841805e9.1.1796205302642; Wed, 02 Dec 2026 01:55:02 -0800 (PST) Received: from tiehlicka (nat2.prg.suse.com. [195.250.132.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853b216esm1148433885e9.12.2026.12.02.01.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:55:02 -0800 (PST) From: Michal Hocko To: David Hildenbrand Cc: David Rientjes , Ben Gardon , Johannes Weiner , mhocko@suse.com, Andrew Morton , , LKML , Chris Mason Subject: [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Date: Wed, 2 Dec 2026 10:54:02 +0100 Message-ID: <20261202095450.296675-10-mhocko@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202095450.296675-1-mhocko@kernel.org> References: <20261202095450.296675-1-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 | 21 +++++++++------------ mm/oom_kill.c | 7 +++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4cb18b217048..87b081f85370 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1313,20 +1313,8 @@ void exit_mmap(struct mm_struct *mm) /* update_hiwater_rss(mm) here? but nobody should be looking */ /* 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. - */ - 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 +1322,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