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 75CC9C433FE for ; Tue, 9 Nov 2021 19:01:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45BB661184 for ; Tue, 9 Nov 2021 19:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242949AbhKITEH (ORCPT ); Tue, 9 Nov 2021 14:04:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242923AbhKITEB (ORCPT ); Tue, 9 Nov 2021 14:04:01 -0500 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F00B9C061764 for ; Tue, 9 Nov 2021 11:01:14 -0800 (PST) Received: by mail-yb1-xb2b.google.com with SMTP id e136so42325ybc.4 for ; Tue, 09 Nov 2021 11:01:14 -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=Tj9qCGc+e2Eaos/5zme+6iQjc5njOEjNZkCKJYwsl5Fzm2mwMOKzuQrHbAyJwGcH1/ CG2U01fKV1+mKjD2Q4CPQW1vboyaft7MyBog4gXrqeULAwyWRt1+EkUX/oGmN0iJQT2A kY5S79vEyxJF12H6a12mJsB9QE0C9eybYNDV++Dj32WxnFJKBpoM/Rd7x3aVIYB6BF+s kjr99otR4Xf6RpnlfZTTpBLWxtXMtrNpEqo1bFQfaKNUMD7ei13pB6p4QFRGSmlcOUVN iUL7Tu3CX1VahE850+UYiqzD4457cIDrRri/teDHVmMUD8y7fJyvCsVyCRTKiFJCMoqt AW+w== X-Gm-Message-State: AOAM531uaZNrVzKqLz2UDiKnuALBbwXd0ZxdLrrTXyd6SJFui58d5wJ0 wj/f1hfNXVT70iWE/zqgIwFuhD6WtIZ6ede8t5UzKw== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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