From patchwork Fri Jul 13 14:26:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10523475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55A01602B3 for ; Fri, 13 Jul 2018 14:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4132C2922D for ; Fri, 13 Jul 2018 14:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 353952925E; Fri, 13 Jul 2018 14:26:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAB7829257 for ; Fri, 13 Jul 2018 14:26:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BCAD6B0003; Fri, 13 Jul 2018 10:26:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 71BA26B0006; Fri, 13 Jul 2018 10:26:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E2B66B0007; Fri, 13 Jul 2018 10:26:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 080CD6B0003 for ; Fri, 13 Jul 2018 10:26:16 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id b12-v6so12193702edi.12 for ; Fri, 13 Jul 2018 07:26:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=Uu2Z2bMN3WNkNuLWuNmVUtovcagLCpWG6xM94LxN9pk=; b=Ud/kGE/mqd4gP6vhGyU+PZA9z7RwkSLYd7/JmIN8G5fIQyNPWO8bvK6cKi8Dzt+C5h oOWd/1ebit+f+UTOTv9VOYbKmJbPbzmy7z4hkRyX17Vq52bl8z53h2Hnntq4wxJCeksy YA2Q0LAnWAOT4F+IepV158Nh+qc8fQL93ZxaCN7UMVNOeRy9v66ykJC2DxyHp5Ntifru M8AgJA4mceGrJsedDjmvtjVwj0U8xnGoGXRjS/zb7E8C50yFyeL+Tg4HHwvDwQ+QFb/l Ic/XlnfdM6ZPxWLw8sx/PBwG+WnMyij4fTeGi+vMdfjpyZ5/q6gORzi9kXRfUoZQYCBf PYGA== X-Original-Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: AOUpUlG1MU58ZqvvwkwTxsIV1pP5A4Niu+rKwPItREWyOVn1DywgGH4r 1WX+LJEw3rOq3s9UMgfdrjsjoii9qEhan/ofgB66FXw8ZsJucx+MP8+uejE/Q3fzCkSH+crRbgf ImIp8lnOizko1VLMjgBi0f2jw4dBcAW/iVr2F174QtUFGSKJn/MnnWZIVuj1kp2Q= X-Received: by 2002:a50:f4aa:: with SMTP id s39-v6mr7304667edm.262.1531491975526; Fri, 13 Jul 2018 07:26:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe+hZC+pLO37R2DdpdrsUGp5oabk1rLB3hDEFYAWwLD+xvyc0XJdftwvsuFJhrNGWk4bOxr X-Received: by 2002:a50:f4aa:: with SMTP id s39-v6mr7304579edm.262.1531491974204; Fri, 13 Jul 2018 07:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531491974; cv=none; d=google.com; s=arc-20160816; b=sZqN2RpRHQwXfzzRxDBEC8k63UAQ/3v19kp9oWnk1vGAsoB8ThDnQjDn474bTjV5+X a8gY2RbHftzF8vMpbYjhBejvCX/Nxc6hxFnaSUKfHvxLNgiqfJLSFSV5vAq38nYzx1cX LEpisDnsQgA/+4XAdALXFKNwpd1Nj7tdg76dJInAleEDK1aOQti6+3F914nByqx+GSON zkEkvbf6jdZfiTctzsPCk/WRFfA8ULf6dxyQtbgpmhQOP2CAyYmBmwABAHBVrT9hs3dE P5h6VXIJgnvYqfp2MvpDFBBlZ0qr7PMVoA4Q3LILhP9FSmDpIajm36z6VO9d2Anwa6k5 27KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:arc-authentication-results; bh=Uu2Z2bMN3WNkNuLWuNmVUtovcagLCpWG6xM94LxN9pk=; b=lK5Lh/zhv0ZD4c3zErbZrHZdfZ/rZDT8abwl80HfqnwfreXS2rcCSjA8NABkfR4Oo6 +L0DgZUrG3ONP8ZAbH1Xf0yhsb6oUodG60j1zdmylcHkEnhBnUd1JwfCLDj8yczoy97q cnUsaLw1ZvEnWd0Rxv8tkiD781upna07cwmBcTpGJTTqWxxpP3bt6UtPBQbVYa6J01Xq POM4K7E44w4ZfZtK1wqmhrhdOWBI9OBw4bI2v0fN32c5Oh4bEIFDvLMv5KHALc8afZNQ qp0e/JgVLDiJiNSMXsXxEhfMv0PHG07jHitRgz5ZYDGtN8+dPzfMaKaeRrE66BHlZ++a S1CQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id r16-v6si872759eds.213.2018.07.13.07.26.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 07:26:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning mhocko@kernel.org does not designate 195.135.220.15 as permitted sender) smtp.mailfrom=mhocko@kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 350E0AD9C; Fri, 13 Jul 2018 14:26:13 +0000 (UTC) Date: Fri, 13 Jul 2018 16:26:12 +0200 From: Michal Hocko To: David Rientjes Cc: Andrew Morton , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [patch -mm] mm, oom: remove oom_lock from exit_mmap Message-ID: <20180713142612.GD19960@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) 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: X-Virus-Scanned: ClamAV using ClamSMTP On Thu 12-07-18 14:34:00, David Rientjes wrote: [...] > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 0fe4087d5151..e6328cef090f 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -488,9 +488,11 @@ void __oom_reap_task_mm(struct mm_struct *mm) > * Tell all users of get_user/copy_from_user etc... that the content > * is no longer stable. No barriers really needed because unmapping > * should imply barriers already and the reader would hit a page fault > - * if it stumbled over a reaped memory. > + * if it stumbled over a reaped memory. If MMF_UNSTABLE is already set, > + * reaping as already occurred so nothing left to do. > */ > - set_bit(MMF_UNSTABLE, &mm->flags); > + if (test_and_set_bit(MMF_UNSTABLE, &mm->flags)) > + return; This could lead to pre mature oom victim selection oom_reaper exiting victim oom_reap_task exit_mmap __oom_reap_task_mm __oom_reap_task_mm test_and_set_bit(MMF_UNSTABLE) # wins the race test_and_set_bit(MMF_UNSTABLE) set_bit(MMF_OOM_SKIP) # new victim can be selected now. Besides that, why should we back off in the first place. We can race the two without any problems AFAICS. We already do have proper synchronization between the two due to mmap_sem and MMF_OOM_SKIP. diff --git a/mm/mmap.c b/mm/mmap.c index fc41c0543d7f..4642964f7741 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3073,9 +3073,7 @@ void exit_mmap(struct mm_struct *mm) * which clears VM_LOCKED, otherwise the oom reaper cannot * reliably test it. */ - mutex_lock(&oom_lock); __oom_reap_task_mm(mm); - mutex_unlock(&oom_lock); set_bit(MMF_OOM_SKIP, &mm->flags); down_write(&mm->mmap_sem); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 32e6f7becb40..f11108af122d 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -529,28 +529,9 @@ void __oom_reap_task_mm(struct mm_struct *mm) static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) { - bool ret = true; - - /* - * We have to make sure to not race with the victim exit path - * and cause premature new oom victim selection: - * oom_reap_task_mm exit_mm - * mmget_not_zero - * mmput - * atomic_dec_and_test - * exit_oom_victim - * [...] - * out_of_memory - * select_bad_process - * # no TIF_MEMDIE task selects new victim - * unmap_page_range # frees some memory - */ - mutex_lock(&oom_lock); - if (!down_read_trylock(&mm->mmap_sem)) { - ret = false; trace_skip_task_reaping(tsk->pid); - goto unlock_oom; + return false; } /* @@ -562,7 +543,7 @@ static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) if (mm_has_blockable_invalidate_notifiers(mm)) { up_read(&mm->mmap_sem); schedule_timeout_idle(HZ); - goto unlock_oom; + return true; } /* @@ -589,9 +570,7 @@ static bool oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm) up_read(&mm->mmap_sem); trace_finish_task_reaping(tsk->pid); -unlock_oom: - mutex_unlock(&oom_lock); - return ret; + return true; } #define MAX_OOM_REAP_RETRIES 10