From nobody Fri Oct 3 14:29:00 2025 Received: from mta22.hihonor.com (mta22.hihonor.com [81.70.192.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05DB3260590 for ; Fri, 29 Aug 2025 06:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.192.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756450570; cv=none; b=WznsY254cXFcWPM4fNwRacuIQSMW0p5dPxUfZ7bKMpVkwbdgV/n0E6REQe46hqjKNjcqFshQeRXefydAxdFFzdf3/63b5lYmo2Ac1Eb0BWD9bDgs2Vy5bjg73HKN2FZNq37mvmQrIlPyjVPRfboxmsN+H4xNZTS0m48po7HdO3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756450570; c=relaxed/simple; bh=KG/7twUkQWo224PrkroO9mfMaZC393EpvmJz7SsJLnk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DExQjeSHP59dQXigXU5qvVpHTZTtcF51tSIagO2i1TaqWAlsB3s0nbKV8yBB4dTMMQnzXym+cbm9VgNbXUhIXNnnBwbAwy+5L5CgpyBC8GyYl5xLvjphCbzk9sG7Y8gaDK6iOZ4KaGj3dbUcTyfwBLi5i0SjEySWPXzUQxfKrQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; dkim=pass (1024-bit key) header.d=honor.com header.i=@honor.com header.b=efQSuI55; arc=none smtp.client-ip=81.70.192.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=honor.com header.i=@honor.com header.b="efQSuI55" dkim-signature: v=1; a=rsa-sha256; d=honor.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=To:From; bh=8XiR1glQQMxhqQ2yDLpSdiuzwavHhKmoaPSOcnK0KdY=; b=efQSuI55EPjgLOtZF/+TWbBl7H2uPLBno5fBnBEbi0eDgbrTmxcsUnMTthMNoOuiSBljLKS92 OGmO1TBaHImgiEk8jygM5rUKBWLAHHOmR4ZWgRVkM8kePlPezdVw+RGN2A9jHHWcvpEe42orskY 8ICPSxcIwqcZfnNe8ukdS9Y= Received: from w013.hihonor.com (unknown [10.68.26.19]) by mta22.hihonor.com (SkyGuard) with ESMTPS id 4cCpv369CkzYlbJG; Fri, 29 Aug 2025 14:55:43 +0800 (CST) Received: from a018.hihonor.com (10.68.17.250) by w013.hihonor.com (10.68.26.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 29 Aug 2025 14:55:56 +0800 Received: from localhost.localdomain (10.144.20.219) by a018.hihonor.com (10.68.17.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 29 Aug 2025 14:55:54 +0800 From: zhongjinji To: CC: , , , , , , , , , , , , , Subject: [PATCH v6 1/2] mm/oom_kill: Do not delay oom reaper when the victim is frozen Date: Fri, 29 Aug 2025 14:55:49 +0800 Message-ID: <20250829065550.29571-2-zhongjinji@honor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250829065550.29571-1-zhongjinji@honor.com> References: <20250829065550.29571-1-zhongjinji@honor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: w010.hihonor.com (10.68.28.113) To a018.hihonor.com (10.68.17.250) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The oom reaper is a mechanism to guarantee a forward process during OOM situation when the oom victim cannot terminate on its own (e.g. being blocked in uninterruptible state or frozen by cgroup freezer). In order to give the victim some time to terminate properly the oom reaper is delayed in its invocation. This is particularly beneficial when the oom victim is holding robust futex resources as the anonymous memory tear down can break those. [1] On the other hand deliberately frozen tasks by the freezer cgroup will not wake up until they are thawed in the userspace and delay is effectively pointless. Therefore opt out from the delay for cgroup frozen oom victims. Reference: [1] https://lore.kernel.org/all/20220414144042.677008-1-npache@redhat.com/T= /#u Signed-off-by: zhongjinji Acked-by: Michal Hocko Reviewed-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes --- mm/oom_kill.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 25923cfec9c6..a5e9074896a1 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -700,7 +700,14 @@ static void queue_oom_reaper(struct task_struct *tsk) =20 get_task_struct(tsk); timer_setup(&tsk->oom_reaper_timer, wake_oom_reaper, 0); - tsk->oom_reaper_timer.expires =3D jiffies + OOM_REAPER_DELAY; + tsk->oom_reaper_timer.expires =3D jiffies; + + /* + * If the task is frozen by the cgroup freezer, the delay is unnecessary + * because it cannot exit until thawed. Skip the delay for frozen victims. + */ + if (!frozen(tsk)) + tsk->oom_reaper_timer.expires +=3D OOM_REAPER_DELAY; add_timer(&tsk->oom_reaper_timer); } =20 --=20 2.17.1 From nobody Fri Oct 3 14:29:00 2025 Received: from mta21.hihonor.com (mta21.hihonor.com [81.70.160.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A454D260569 for ; Fri, 29 Aug 2025 06:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.160.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756450566; cv=none; b=R5rb4kiN80ZDEI92n/zZNXaw4DDgdNGFA8ZRpCMWfFRiO/ND1aDobPQSUVLsj86R1YW/saXpOIweJTR5E/TUw9vVB1amOEVsZNiBdQINPGAftoIu0hV8+CUesX8eWno2Nixf5BYU/LuRU2lUlb31/tMZKLFVEZc4mf9YRzOT2Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756450566; c=relaxed/simple; bh=zaLRGrfm2rVJ5FM30v0HBC/REj93fkh++zzN1nEPBR8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=az1/PZSY8EwzwBxa9EyYxHA/T4864dDMwrFZV3f2tfI3X0ZKdX+mqseGg724wISBpJM+oczwSwmUAnWdDit3PtXp1g9gHzDb7mCVvIuGAgDeaGk2AbQpbqAfFCBzBQw5l92wXIGQN2nOx6nyUUVGhDNfbelDfCreDYPjKzaBVGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; arc=none smtp.client-ip=81.70.160.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Received: from w013.hihonor.com (unknown [10.68.26.19]) by mta21.hihonor.com (SkyGuard) with ESMTPS id 4cCptx6T7YzYnQcn; Fri, 29 Aug 2025 14:55:37 +0800 (CST) Received: from a018.hihonor.com (10.68.17.250) by w013.hihonor.com (10.68.26.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 29 Aug 2025 14:55:56 +0800 Received: from localhost.localdomain (10.144.20.219) by a018.hihonor.com (10.68.17.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 29 Aug 2025 14:55:55 +0800 From: zhongjinji To: CC: , , , , , , , , , , , , , Subject: [PATCH v6 2/2] mm/oom_kill: The OOM reaper traverses the VMA maple tree in reverse order Date: Fri, 29 Aug 2025 14:55:50 +0800 Message-ID: <20250829065550.29571-3-zhongjinji@honor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250829065550.29571-1-zhongjinji@honor.com> References: <20250829065550.29571-1-zhongjinji@honor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: w010.hihonor.com (10.68.28.113) To a018.hihonor.com (10.68.17.250) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a process is OOM killed without reaper delay, the oom reaper and the exit_mmap() thread likely run simultaneously. They traverse the vma's maple tree along the same path and may easily unmap the same vma, causing them to compete for the pte spinlock. When a process exits, exit_mmap() traverses the vma's maple tree from low to high addresses. To reduce the chance of unmapping the same vma simultaneously, the OOM reaper should traverse the vma's tree from high to low address. Reported-by: tianxiaobin Reported-by: fengbaopeng Signed-off-by: zhongjinji Acked-by: Michal Hocko Reviewed-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes --- mm/oom_kill.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index a5e9074896a1..01665a666bf1 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -516,7 +516,7 @@ static bool __oom_reap_task_mm(struct mm_struct *mm) { struct vm_area_struct *vma; bool ret =3D true; - VMA_ITERATOR(vmi, mm, 0); + MA_STATE(mas, &mm->mm_mt, ULONG_MAX, ULONG_MAX); =20 /* * Tell all users of get_user/copy_from_user etc... that the content @@ -526,7 +526,12 @@ static bool __oom_reap_task_mm(struct mm_struct *mm) */ set_bit(MMF_UNSTABLE, &mm->flags); =20 - for_each_vma(vmi, vma) { + /* + * When two tasks unmap the same vma at the same time, they may contend + * for the pte spinlock. To reduce the probability of unmapping the same = vma + * as exit_mmap, the OOM reaper traverses the vma maple tree in reverse o= rder. + */ + mas_for_each_rev(&mas, vma, 0) { if (vma->vm_flags & (VM_HUGETLB|VM_PFNMAP)) continue; =20 --=20 2.17.1