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 C76FCC433F5 for ; Tue, 9 Nov 2021 19:01:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 70E65611AD for ; Tue, 9 Nov 2021 19:01:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 70E65611AD 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 128CD6B008C; Tue, 9 Nov 2021 14:01:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D89A6B0093; Tue, 9 Nov 2021 14:01:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F08A76B0095; Tue, 9 Nov 2021 14:01:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id DFD566B008C for ; Tue, 9 Nov 2021 14:01:19 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A590C1813BCF7 for ; Tue, 9 Nov 2021 19:01:19 +0000 (UTC) X-FDA: 78790309878.21.BD6F5AD Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf09.hostedemail.com (Postfix) with ESMTP id 66DC93001DB2 for ; Tue, 9 Nov 2021 19:01:16 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id o12so87158ybk.1 for ; Tue, 09 Nov 2021 11:01:16 -0800 (PST) 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=KoZB95vVH0v2a9gf7XfzuFZQxHUcQQC8LetoqIfIJrc=; b=i6pbPLy0D0M4njCdg6snPJMmBT4Att1VQu/ppVxjExF9iSad/k/90KsN9L5mNymTSS NIMvoF3R3jeKUqiUipteXgZ9xfPVwrgJlc42b8brMzPdZdFM1+YQSRIKURb1UK/Df9uT RthW4wkCKi1AXXkdCWkGrlodZPyHo1jxSOXTNhNM7r5ZeYXATfhnPlHVsh05Q68lqHQ4 LxUVkDTF4VkLUmIAzppyMvguzsik6K4pYJwM4lATc/1pJn7Q0JAS7qkTzsemCERLwUq0 XvvDCalxov3CTjrK01krF26eRphk4Gfi83GC5VfxjJ2Nzc0GLavlPWMCP9TfwdmXNUNV Ipsw== 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=KoZB95vVH0v2a9gf7XfzuFZQxHUcQQC8LetoqIfIJrc=; b=MgbJYNzvUn2t9Aa5GNWoo1HZzR1lVYeBAcmKWfXp809F+p6gEfxceP2JT416AIgZTr V2w+xsDqbcqX7iNxBcrFmr02cIqakmEq1S2jqQo/lyPOjfVZsjxYuUOudkW+/IBagsKI uCe2vHYHpgkj2licKcmwQfVx+EYT2wEXJ2Gq9jCufCmJlPdQ59GV/vM4757wQQVTYVaf rG8A/+1kD3bwJNBDiWdsj6MQU6Okwp2O8PvVlVgPl9jdoCLOoKavJlM/ZtS5Np8K/4+3 lpXJ+cglsr2EAonFuA7z9q2nal6BX1ahGLJLDBVDJYp+FwsSvTLhXgjyd07gZTYrasiz jANA== X-Gm-Message-State: AOAM530LZoOiuMSD8sGN87GN1P5MwE7TJyJbWJ8SfaEWlr/Y9zexVknZ ORDxo1z2iFUGNvGbbxdPwlDDYyVXsoMM1zSL61mT9Q== X-Google-Smtp-Source: ABdhPJwdc7hXS6J642vWkCDbrvXn+RiplHQk2rKWV5VvcmEBD7ypXiQI7Rbf7k86wgaSrzmhwiRPdB1ZI/CHd2MT1L0= X-Received: by 2002:a25:d4d5:: with SMTP id m204mr11979039ybf.418.1636484473977; Tue, 09 Nov 2021 11:01:13 -0800 (PST) MIME-Version: 1.0 References: <20211022014658.263508-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 9 Nov 2021 11:01:02 -0800 Message-ID: Subject: Re: [PATCH 1/1] mm: prevent a race between process_mrelease and exit_mmap To: Michal Hocko Cc: Andrew Morton , 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 , "Kirill A. Shutemov" , Andrea Arcangeli Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=i6pbPLy0; spf=pass (imf09.hostedemail.com: domain of surenb@google.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 66DC93001DB2 X-Stat-Signature: sz7uo9c93w5xqyjw7w5zrhybjzukthof X-HE-Tag: 1636484476-69184 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 Tue, Nov 2, 2021 at 8:14 AM Suren Baghdasaryan wrote: > > On Tue, Nov 2, 2021 at 12:58 AM Michal Hocko wrote: > > > > On Mon 01-11-21 08:44:58, Suren Baghdasaryan wrote: > > [...] > > > I'm with you on this one, that's why I wanted to measure the price we > > > would pay. Below are the test results: > > > > > > Test: https://lore.kernel.org/all/20170725142626.GJ26723@dhcp22.suse.cz/ > > > Compiled: gcc -O2 -static test.c -o test > > > Test machine: 128 core / 256 thread 2x AMD EPYC 7B12 64-Core Processor > > > (family 17h) > > > > > > baseline (Linus master, f31531e55495ca3746fb895ffdf73586be8259fa) > > > p50 (median) 87412 > > > p95 168210 > > > p99 190058 > > > average 97843.8 > > > stdev 29.85% > > > > > > unconditional mmap_write_lock in exit_mmap (last column is the change > > > from the baseline) > > > p50 (median) 88312 +1.03% > > > p95 170797 +1.54% > > > p99 191813 +0.92% > > > average 97659.5 -0.19% > > > stdev 32.41% > > > > > > unconditional mmap_write_lock in exit_mmap + Matthew's patch (last > > > column is the change from the baseline) > > > p50 (median) 88807 +1.60% > > > p95 167783 -0.25% > > > p99 187853 -1.16% > > > average 97491.4 -0.36% > > > stdev 30.61% > > > > > > stdev is quite high in all cases, so the test is very noisy. > > > The impact seems quite low IMHO. WDYT? > > > > Results being very noisy is what I recall as well. Thanks! > > I believe, despite the noise, the percentiles show that overall we do > not noticeably regress the exit path by taking mmap_lock > unconditionally. > If there are no objections, I would like to post a patchset which > implements unconditional locking in exit_mmap() and process_madvise() > calling __oom_reap_task_mm() under protection of read mmap_lock. > Thanks! Discussing how the patch I want to post works for maple trees that Matthew is working on, I've got a question: IIUC, according to Michal's post here: https://lore.kernel.org/all/20170725154514.GN26723@dhcp22.suse.cz, unmap_vmas() can race with other mmap_lock read holders (including oom_reap_task_mm()) with no issues. Maple tree patchset requires rcu read lock or the mmap semaphore be held (read or write side) when walking the tree, including inside unmap_vmas(). When asked, he told me that he is not sure why it's currently "safe" to walk the vma->vm_next list in unmap_vmas() while another thread is reaping the mm. Michal (or maybe someone else), could you please clarify why unmap_vmas() can safely race with oom_reap_task_mm()? Or maybe my understanding was wrong? Thanks, Suren. > > > -- > > Michal Hocko > > SUSE Labs