Received: by 10.192.165.148 with SMTP id m20csp1964115imm; Sat, 21 Apr 2018 20:48:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4955eRbVJsVeMtO4OxMGIr7ES4cV6U4NK99Cj7RBSF0XxJZ/wv25TQHath2w1RSAClyrieE X-Received: by 10.101.67.129 with SMTP id m1mr12674225pgp.373.1524368912959; Sat, 21 Apr 2018 20:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524368912; cv=none; d=google.com; s=arc-20160816; b=B/4ljc+Z+ka8LVIsCiIbDno6gYmLR4MI11v1dCW+RKCR4UYDYMmyvTPbXzczQkUTld Si2JxPw6X0m9pgEVjSBfoWai/45mPCGDnlMTv0kpJBE5qF3ucavIExWBU4j9vKJEjjtS CUjg4QvnhoB5IeMjzH5K45sDL9rzPvsKCB3WvKvQ3Xgx5EYjHinq2jy8C5qSCX8bsEcF rsi27K0yDl2fI+K/+Ej+FaR38S1Sb7J23mOHoybIs1ms9qqHpvN/Qy+KXzMgQWPkNxBM sC+97vYowyBoBGphhO38pS9ukx5A3ErW1uk8AcB7+a9UQdd+TvZcHXthB1UYTXP7/KNE +76g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=t5cg6AXKCY5ClYlywlBqPrbyy8sS8s8cW4AfSWPvv50=; b=rFzx2pB5g0WFbyi3P770as5tSzP8y1QZEaINwRl8tIkrSW3M95CtXtGdv0B5YvRD3q 8tW/DM0QpNhQBj46AXRN6Oz+MHRcTi4eOqaIWqzt1wlrhkgoNP7l2BZ5FKWAS6BxvU+7 hT330WSZOiz2gMwtwRV/3PFGO2L5Zo7fXuGbfYYjoHmJZBWiuWmimeZG2EA4av6iNZvl tKU72Ihhk9/gxdezXz0Qsw+veOzs3A3CyGUY/ueY3TsD28eJ8kS1op2opMJLSl45AlxJ mUItemimL/LATC6Vg/ma4+txJtIluerWdT/JLSYja5FsYTOUhD8ZYHPCi/lGZkikcq+4 idyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Uv6jn0Kw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w61-v6si8887987plb.155.2018.04.21.20.47.55; Sat, 21 Apr 2018 20:48:32 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Uv6jn0Kw; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753378AbeDVDpP (ORCPT + 99 others); Sat, 21 Apr 2018 23:45:15 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:37630 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753025AbeDVDpO (ORCPT ); Sat, 21 Apr 2018 23:45:14 -0400 Received: by mail-pf0-f193.google.com with SMTP id p6so6501534pfn.4 for ; Sat, 21 Apr 2018 20:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=t5cg6AXKCY5ClYlywlBqPrbyy8sS8s8cW4AfSWPvv50=; b=Uv6jn0KwZqcUnsLMVn5nzgY36LRLSrJHjY6TCdFZqjJhZkYV1juMNE3NOV6giGTNUf kIJ+/kRSihdmgK/AgFE1QhRqSjGSH3SEMhT2LxUQzaQNKgTb4a4N1kMdyqNeNfb6zOzN oZmpP3oj0hTQRWglYOP4r0l+XBvlWcPrqhU2nv+bDKwApM2HUlTU0v5QHFWkSvMozus2 Bzfv5YgGldfF0PGE4cVGPTt3wCJGV3EbLSJm3xK2fpgoyRRLC/lBgGEkHdcESG0RXEUo QpqtMLPGO2q77bXoUq91BZ+LovKXgBAyUvYCRYdi8EdWzIxScTy+HCVm93/ZEsoGDzjx /YbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=t5cg6AXKCY5ClYlywlBqPrbyy8sS8s8cW4AfSWPvv50=; b=STdDj2e3FryHQiy/J4ZpNmskAW0qT48U0y/o81PszZ1g6Jj2WNvRgh0ulmVfFrw0mS 9CHQZw3cDIxleN+2ILKo39kdtLVcajA5RYGg2EZHVTmyTmxvgD7QkYhtLdrUB/Viy7y6 ITmlP08FWrhhPoAz/kKuoOcvSi29RTRcSzUwyRHhs/cKUMzn3vnmq7tP4WgTMg9BGo8j Bv/y6igvrQB6cTsV6aXPHQocu3y+viOfZ8FkOA83U8gOyyvEJA3mu+kJTblCPDZ+oglZ mNzobRN/Iee63HyEzXXMLrpYQLp9vBzzHVrJXn92dXJx/sBEn5MXef662uXbW69FaACa UDhA== X-Gm-Message-State: ALQs6tC96EDa/WkfqkLCFLZvVLwFh1ZAM+Lb0EXcTSs72kzdL7djMZAV PIb6kd6lMquKGARrhNNY3YyHjg== X-Received: by 10.99.174.73 with SMTP id e9mr12687307pgp.38.1524368713704; Sat, 21 Apr 2018 20:45:13 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id j1sm12053966pgn.69.2018.04.21.20.45.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Apr 2018 20:45:12 -0700 (PDT) Date: Sat, 21 Apr 2018 20:45:11 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Michal Hocko cc: Andrew Morton , Tetsuo Handa , Andrea Arcangeli , Roman Gushchin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch v2] mm, oom: fix concurrent munlock and oom reaper unmap In-Reply-To: <20180420082349.GW17484@dhcp22.suse.cz> Message-ID: References: <201804180057.w3I0vieV034949@www262.sakura.ne.jp> <20180418075051.GO17484@dhcp22.suse.cz> <20180419063556.GK17484@dhcp22.suse.cz> <20180420082349.GW17484@dhcp22.suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Apr 2018, Michal Hocko wrote: > > The solution is certainly not to hold > > down_write(&mm->mmap_sem) during munlock_vma_pages_all() instead. > > Why not? This is what we do for normal paths. exit path just tries to be > clever because it knows that it doesn't have to lock because there is no > concurent user. At least it wasn't until the oom reaper came. So I > really fail to see why we shouldn't do the most obvious thing and use > the locking. > Because the oom reaper uses the ability to acquire mm->mmap_sem as a heuristic to determine when to give up and allow another process to be chosen. If the heuristics of the oom reaper are to be improved, that's great, but this patch fixes the oops on powerpc as 4.17 material and as a stable backport. It's also well tested. > > If > > exit_mmap() is not making forward progress then that's a separate issue; > > Please read what I wrote. There is a page lock and there is no way to > guarantee it will make a forward progress. Or do you consider that not > true? > I don't have any evidence of it, and since this is called before exit_mmap() sets MMF_OOM_SKIP then the oom reaper would need to set the bit itself and I would be able to find the artifact it leaves behind in the kernel log. I cannot find a single instance of a thread stuck in munlock by way of exit_mmap() that causes the oom reaper to have to set the bit itself, and I should be able to if this were a problem. > > Holding down_write on > > mm->mmap_sem otherwise needlessly over a large amount of code is riskier > > (hasn't been done or tested here), more error prone (any code change over > > this large area of code or in functions it calls are unnecessarily > > burdened by unnecessary locking), makes exit_mmap() less extensible for > > the same reason, > > I do not see any of the calls in that path could suffer from holding > mmap_sem. Do you? > > > and causes the oom reaper to give up and go set > > MMF_OOM_SKIP itself because it depends on taking down_read while the > > thread is still exiting. > > Which is the standard backoff mechanism. > The reason today's locking methodology is preferred is because of the backoff mechanism. Your patch kills many processes unnecessarily if the oom killer selects a large process to kill, which it specifically tries to do, because unmap_vmas() and free_pgtables() takes a very long time, sometimes tens of seconds.