Received: by 10.192.165.156 with SMTP id m28csp674567imm; Tue, 17 Apr 2018 18:00:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Hwv3aHCJxw5asu0NPE64Jq51QAemJn/t9ARnmFFFMniQAOSU7QZVjW8G7YmWgDbQsqA+K X-Received: by 2002:a17:902:7290:: with SMTP id d16-v6mr13506pll.43.1524013213270; Tue, 17 Apr 2018 18:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524013213; cv=none; d=google.com; s=arc-20160816; b=WnvjUl2hX7ZQQAzcQfg7l8ZewRTYIc5xxlBOYKiJO/Z7kX3wgql40m0HtMBZl4WSEr 74BKx3RQGUQrYBPUP0OPzdJiXmEMEypBcfqXNmavd+gThrhJEsc/vDUqtPzBgwCxGUgj EXxIrqvk1iwyl6lXdQIxhMSiIZSIo7m1kdJr6V2Mftv/hRpAYrXEvve/d73/GDc/CR5P UmhBYRAq6p+Zqmc+GiqR8Jk8oPQHfUK3gWW9DVifFdcpNHmZEnRZ/+KrBhqBt4K1FYwX WC56oW71dV1iaNlOT/2dvJZsB0VyUyRXrrLbKgUsFQwDKcOPqKGpB5vbZMpxDWs1ywFD hHeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :references:date:mime-version:cc:to:from:subject:message-id :arc-authentication-results; bh=ooXC6Qeq+2B2gc4y5MdpiwupMAT8IPcBUWKLE+I5Zvg=; b=PFh1OUiAn+GjIZYb4iz1esWOGILa5OOBoUk1P11uvhMfZGUyapacS/oO3luJnfIRjV cY3IqULFBfX066XdyiPqZlz/cz6Co0xuYFdovP09aQ8fpyU2fiQm/Sen0t0YX2JszXpS P3lkMlDgaxIHYqtLPsKebONy/WedvUecT0o76uGBoeZfYuybU1h7yEIWLHvlU0J2A+cH QYPCrmYQ6lPQm2uXVeAlsu+6jJfL/gCVffkXNgUwVsH/6rqOv80TXHhlFklxNPDCMOae zwUcvYOc4zglesVTc0rAZTtSCyg0l1FvrClsLvwSh8darli/1xCGWtJVEZhNJ2ZOrCHe 0GWw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si57103pfw.173.2018.04.17.17.59.47; Tue, 17 Apr 2018 18:00:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753002AbeDRA5s (ORCPT + 99 others); Tue, 17 Apr 2018 20:57:48 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:10974 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeDRA5r (ORCPT ); Tue, 17 Apr 2018 20:57:47 -0400 Received: from fsav403.sakura.ne.jp (fsav403.sakura.ne.jp [133.242.250.102]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w3I0vjh9034954; Wed, 18 Apr 2018 09:57:45 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav403.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav403.sakura.ne.jp); Wed, 18 Apr 2018 09:57:45 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav403.sakura.ne.jp) Received: from www262.sakura.ne.jp (localhost [127.0.0.1]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w3I0viWf034950; Wed, 18 Apr 2018 09:57:44 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: (from i-love@localhost) by www262.sakura.ne.jp (8.14.5/8.14.5/Submit) id w3I0vieV034949; Wed, 18 Apr 2018 09:57:44 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Message-Id: <201804180057.w3I0vieV034949@www262.sakura.ne.jp> X-Authentication-Warning: www262.sakura.ne.jp: i-love set sender to penguin-kernel@i-love.sakura.ne.jp using -f Subject: Re: [patch] mm, oom: fix concurrent munlock and oom reaper unmap From: Tetsuo Handa To: David Rientjes Cc: Andrew Morton , Michal Hocko , Andrea Arcangeli , Tetsuo Handa , Roman Gushchin , linux-kernel@vger.kernel.org, linux-mm@kvack.org MIME-Version: 1.0 Date: Wed, 18 Apr 2018 09:57:44 +0900 References: In-Reply-To: Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David Rientjes wrote: > Since exit_mmap() is done without the protection of mm->mmap_sem, it is > possible for the oom reaper to concurrently operate on an mm until > MMF_OOM_SKIP is set. > > This allows munlock_vma_pages_all() to concurrently run while the oom > reaper is operating on a vma. Since munlock_vma_pages_range() depends on > clearing VM_LOCKED from vm_flags before actually doing the munlock to > determine if any other vmas are locking the same memory, the check for > VM_LOCKED in the oom reaper is racy. > > This is especially noticeable on architectures such as powerpc where > clearing a huge pmd requires kick_all_cpus_sync(). If the pmd is zapped > by the oom reaper during follow_page_mask() after the check for pmd_none() > is bypassed, this ends up deferencing a NULL ptl. I don't know whether the explanation above is correct. Did you actually see a crash caused by this race? > > Fix this by reusing MMF_UNSTABLE to specify that an mm should not be > reaped. This prevents the concurrent munlock_vma_pages_range() and > unmap_page_range(). The oom reaper will simply not operate on an mm that > has the bit set and leave the unmapping to exit_mmap(). But this patch is setting MMF_OOM_SKIP without reaping any memory as soon as MMF_UNSTABLE is set, which is the situation described in 212925802454: At the same time if the OOM reaper doesn't wait at all for the memory of the current OOM candidate to be freed by exit_mmap->unmap_vmas, it would generate a spurious OOM kill. If exit_mmap() does not wait for any pages and __oom_reap_task_mm() can not handle mlock()ed pages, isn't it better to revert 212925802454 like I mentioned at https://patchwork.kernel.org/patch/10095661/ and let the OOM reaper reclaim as much as possible before setting MMF_OOM_SKIP?