From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63F5CC433FE for ; Fri, 22 Oct 2021 05:23:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD7A260FF2 for ; Fri, 22 Oct 2021 05:23:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD7A260FF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 24C96940008; Fri, 22 Oct 2021 01:23:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FB69900002; Fri, 22 Oct 2021 01:23:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EA47940008; Fri, 22 Oct 2021 01:23:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 01897900002 for ; Fri, 22 Oct 2021 01:23:21 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B2CD73208B for ; Fri, 22 Oct 2021 05:23:21 +0000 (UTC) X-FDA: 78722930202.34.63C0309 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by imf25.hostedemail.com (Postfix) with ESMTP id A8D42B000181 for ; Fri, 22 Oct 2021 05:23:16 +0000 (UTC) Received: by mail-yb1-f173.google.com with SMTP id 67so4342376yba.6 for ; Thu, 21 Oct 2021 22:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/K7g7u2ztiiMpfLD3ufFGiu7hRc5OC0Hi+SvzjKN4Uk=; b=ly0FbEE9Cx2o0m+sLygjae/WePo6aZBdJEycwr+AxFGMCElMOUSKMnm3dNn6yydnFD IeCJVcOc0fhI8EOODak6bDjP5jmdEdrwK9klZmCv393MLULV2izorxk+R2zF2uUMOSTI 6YHAOGEZWpBJ9UmRlHOot/gSWeRJezJYsWzq/3+5475yi8MeNEd4eKZgk1u2VnuCmxT+ bR7iVcEuthyMWB1WNLejEWG+ylqhYCQUMq61fWB6+Tjz9iTbNOzbcTRjjMaGHPnqRnZY TEbIS3zdaAYvypoQ0D+jKp9Fgb6/OrurOSihIUF7xWw5s/3kX+Ywf9jM36iNmm+c8zxg JJJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/K7g7u2ztiiMpfLD3ufFGiu7hRc5OC0Hi+SvzjKN4Uk=; b=eMtM4x0m5pn1/l/scA4SG4w0D4IiRETU2DQQZvQsvJZm6Tf0rN1o8PL8bTidZU8ZAu 0b0oRbnUmWfM54rziau29HQicfqEW4Ukbqe7BExK6nOpg1LhdugecaPu+U74cgKPxPW3 Eq5EwweFYMSujL9wkVq+uwmiyPFgjzuTMT6KZfmI2pJMkbsAFfAsrQjbHsiv4HtmAwTm MpryFDwbTijyadTPUoxyyQ0YfIvHw5f0ZWB7o65JWN3L95xW5ylBuKtu6x+QmkE4KXpf j/RxSpocCsKnyK9sQy00U+m/+lUqXzY9Imy2xYdPYnztWkBBTY1OJCMXzRSLQOAwAQi0 DudQ== X-Gm-Message-State: AOAM530cb5mPYclF7eKqZg8ry99McQz/D+uECqkq3S8h9t0cVc+ZUSX4 p720HjmwAtrAzRlPT+RX4gpuq9lg9kxiVclc2ueryA== X-Google-Smtp-Source: ABdhPJyxZCUyr4sMHK+JfeiRtzhmYvXjKxyFRS/5VnhxOej5AiUTE/+OV68+Q8FkKKW+Dxu+8ENslNiFqTzqpBJ17+w= X-Received: by 2002:a25:d1d3:: with SMTP id i202mr11392808ybg.487.1634880200329; Thu, 21 Oct 2021 22:23:20 -0700 (PDT) MIME-Version: 1.0 References: <20211022014658.263508-1-surenb@google.com> <20211021192454.72ada9b3d59460cc3c037d2c@linux-foundation.org> In-Reply-To: <20211021192454.72ada9b3d59460cc3c037d2c@linux-foundation.org> From: Suren Baghdasaryan Date: Thu, 21 Oct 2021 22:23:09 -0700 Message-ID: Subject: Re: [PATCH 1/1] mm: prevent a race between process_mrelease and exit_mmap To: Andrew Morton Cc: Michal Hocko , Michal Hocko , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Minchan Kim , Christian Brauner , Christoph Hellwig , Oleg Nesterov , David Hildenbrand , Jann Horn , Shakeel Butt , Andy Lutomirski , Christian Brauner , Florian Weimer , Jan Engelhardt , Linux API , linux-mm , LKML , kernel-team Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A8D42B000181 X-Stat-Signature: 5to319fxa488dzg68xj6uhawmr8ezpf8 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ly0FbEE9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of surenb@google.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=surenb@google.com X-HE-Tag: 1634880196-834786 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Oct 21, 2021 at 7:25 PM Andrew Morton wrote: > > On Thu, 21 Oct 2021 18:46:58 -0700 Suren Baghdasaryan wrote: > > > Race between process_mrelease and exit_mmap, where free_pgtables is > > called while __oom_reap_task_mm is in progress, leads to kernel crash > > during pte_offset_map_lock call. oom-reaper avoids this race by setting > > MMF_OOM_VICTIM flag and causing exit_mmap to take and release > > mmap_write_lock, blocking it until oom-reaper releases mmap_read_lock. > > Reusing MMF_OOM_VICTIM for process_mrelease would be the simplest way to > > fix this race, however that would be considered a hack. Fix this race > > by elevating mm->mm_users and preventing exit_mmap from executing until > > process_mrelease is finished. Patch slightly refactors the code to adapt > > for a possible mmget_not_zero failure. > > This fix has considerable negative impact on process_mrelease performance > > and will likely need later optimization. > > Has the impact been quantified? A ball-park figure for a large process (6GB) it takes 4x times longer for process_mrelease to exit. > > And where's the added cost happening? The changes all look quite > lightweight? I think it's caused by the fact that exit_mmap and all other cleanup routines happening on the last mmput are postponed until process_mrelease finishes __oom_reap_task_mm and drops mm->mm_users. I suspect all that cleanup is happening at the end of process_mrelease now and that might be contributing to the regression. I didn't have time yet to fully understand all the reasons for that regression but wanted to fix the crash first. Will proceed with more investigation and hopefully with a quick fix for the lost performance. > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >