Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2206993imm; Mon, 16 Jul 2018 04:16:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekdQx7tiMu0UgPHAg+wGcvx4jPWcI3nTH/bEy3ebefTcVNNL5NYOeIttY0nTm3nWBirybH X-Received: by 2002:a63:647:: with SMTP id 68-v6mr15228254pgg.205.1531739767575; Mon, 16 Jul 2018 04:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531739767; cv=none; d=google.com; s=arc-20160816; b=znNL++tkZekN4a790qr6sabGFHRloFPu87RluOc7083B8mGG1XJes9ZVFBPO+eVB6C SV9zLjg7n/YWHnAHXvbM2ImqirYm1p505mF9j35czUj4uA9B7GpsDPxiXSdlKPmRRuZo IqLCLJotG4N3Q58+L7noFG1V04W8H4s1ZEtWXNxczOHCqvoCk+k96iJhVMNAO6jTZa3y M7NzwLT9TXfulxr6CPwKK9F3nLdxFtAyK+OA8SN1W44CmcbEg51zTgeFr63JYjE+alr4 wdiuvG+3HC9CjxgS+8NXw4d2pQjlb+IzTCX/cM3VH1wU7lOsGlWY6equqbJm28sFD8h1 aYHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=sQp14Y+OvtE+v9qZkFyeTWSLCf2ioLFYkXM2JvozCDk=; b=qjibfhcRyA2RdLEFsMXaKrtxtb3W4GS50Wz17/3pQql6Ns46DG83fc0/I2qnPgIQXB OwF0Qpnjc1c2fkl6MvABv2UsBpPATJfa4ztPYFLJaI/TYBUJ2yMJjjxYgXP1CwW8TEPG skhQnZYSbKXZi00dLxljvz3o4oG3vjJhD4StPqPoz1GTtsvZiZfOIFMYEoCBP7VQBCSv PLdLG/NK5oPDZqpHqhlKSLJmyMrDOi4/QtKyGwDdufJwm6yJhDMTHzKx9KYeFP8ymv+J zbErpZbHsgfzxNoKSY7mlhuqzc0Il3NHGS+OpTzmWYSOduxGXPtE96xbHVCuGS8I7Bm6 FC/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14-v6si17005036pgg.345.2018.07.16.04.15.52; Mon, 16 Jul 2018 04:16:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729612AbeGPLmG (ORCPT + 99 others); Mon, 16 Jul 2018 07:42:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:50372 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726602AbeGPLmG (ORCPT ); Mon, 16 Jul 2018 07:42:06 -0400 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 2A4B1ACF2; Mon, 16 Jul 2018 11:15:09 +0000 (UTC) Date: Mon, 16 Jul 2018 13:15:08 +0200 From: Michal Hocko To: Tetsuo Handa Cc: David Rientjes , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [patch -mm] mm, oom: remove oom_lock from exit_mmap Message-ID: <20180716111508.GL17280@dhcp22.suse.cz> References: <20180713142612.GD19960@dhcp22.suse.cz> <44d26c25-6e09-49de-5e90-3c16115eb337@i-love.sakura.ne.jp> <20180716061317.GA17280@dhcp22.suse.cz> <916d7e1d-66ea-00d9-c943-ef3d2e082584@i-love.sakura.ne.jp> <20180716074410.GB17280@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 16-07-18 19:38:21, Tetsuo Handa wrote: > On 2018/07/16 16:44, Michal Hocko wrote: > >> If setting MMF_OOM_SKIP is guarded by oom_lock, we can enforce > >> last second allocation attempt like below. > >> > >> CPU 0 CPU 1 > >> > >> mutex_trylock(&oom_lock) in __alloc_pages_may_oom() succeeds. > >> get_page_from_freelist() fails. > >> Enters out_of_memory(). > >> > >> __oom_reap_task_mm() reclaims some memory. > >> mutex_lock(&oom_lock); > >> > >> select_bad_process() does not select new victim because MMF_OOM_SKIP is not yet set. > >> Leaves out_of_memory(). > >> mutex_unlock(&oom_lock) in __alloc_pages_may_oom() is called. > >> > >> Sets MMF_OOM_SKIP. > >> mutex_unlock(&oom_lock); > >> > >> get_page_from_freelist() likely succeeds before reaching __alloc_pages_may_oom() again. > >> Saved one OOM victim from being needlessly killed. > >> > >> That is, guarding setting MMF_OOM_SKIP works as if synchronize_rcu(); it waits for anybody > >> who already acquired (or started waiting for) oom_lock to release oom_lock, in order to > >> prevent select_bad_process() from needlessly selecting new OOM victim. > > > > Hmm, is this a practical problem though? Do we really need to have a > > broader locking context just to defeat this race? > > Yes, for you think that select_bad_process() might take long time. It is possible > that MMF_OOM_SKIP is set while the owner of oom_lock is preempted. It is not such > a small window that select_bad_process() finds an mm which got MMF_OOM_SKIP > immediately before examining that mm. I only do care if the race is practical to hit. And that is why I would like a simplification first (so drop the oom_lock in the oom_reaper path) and then follow up with some decent justification on top. -- Michal Hocko SUSE Labs