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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02B4FC433FE for ; Thu, 30 Dec 2021 17:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFF286B0071; Thu, 30 Dec 2021 12:29:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EACDA6B0072; Thu, 30 Dec 2021 12:29:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4DD56B0074; Thu, 30 Dec 2021 12:29:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id C28ED6B0071 for ; Thu, 30 Dec 2021 12:29:53 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4CE0687C95 for ; Thu, 30 Dec 2021 17:29:53 +0000 (UTC) X-FDA: 78975148266.12.9B22816 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf07.hostedemail.com (Postfix) with ESMTP id D3B6B40007 for ; Thu, 30 Dec 2021 17:29:52 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id i3so59717940ybh.11 for ; Thu, 30 Dec 2021 09:29:52 -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=oHSt4ia9HUMCTnajrSH0I50wrVyu7BkC7WP9xxYyS7k=; b=AOm95os7wumcTlCNjGWCKpfopdAzw1OsbSc+dt4WPheXzeGd8PLat3bxu66O6gcjBj 2g+hWptJKS+CKtxJjX9Fqn/8SbLmbGeL+59ZH80o68wrfyC++pDtbNmDsh8bXk0zpD6d isnUP2vMv/Ti8zotAJYNY6PJvJ5Sq8MKNslUnbDyM3ZsXEfDki+4vfPeuzr23dwmQD6P z4GbOVABFNv+567EEAlbg9Qatx6WQhXSDMLUWkmdHsAYiXgyMLkQPu/p5jmZ0ee2Fo5l 4bTlhjLrtqf4qWk62qhR5kn28H/+gYENSX33XjzqavQtZYgjGg6K0rdrI/W0aE0VNIXW 5Wig== 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=oHSt4ia9HUMCTnajrSH0I50wrVyu7BkC7WP9xxYyS7k=; b=KbyifIiBC4Q/oDATEOfoXDRoJFpQlfwxwdK8NEH9sc/fWnyJTooqzCjj8R8oLL11Qa QgF5ETy2lupxK9yaLd8SnFQft53j9IydRiM+FLXszWF4Fw2zXJCQc+QvecvRosJcLIwb s/QAzQG07vTbaBdGevxVEv+rVMiAb+FZlNF1TvZqbj39k/gNyNZZtp5Ft4uI5mADdrr3 eRQeuTWZ5iK6joaaupOtqry1Jpilu8nShHB+NA3JhM6i/XZovLcDJzyHb1f98uKqGwlq 2niKQamS4NIieJgr59sz8UTGjeNEZhLLvlw498DYuHQcBKZs95nA5HruIIIO42lL0gzk /wZg== X-Gm-Message-State: AOAM531fUiW6eYqdzL9vPoDzUYRcDS5SlOLoxzUVg6Ckc+THN7IO1081 eayd+SeGy8mYTJLY/vLb8RTSfqSe5vorHFKD8vnPaw== X-Google-Smtp-Source: ABdhPJzXnsvrLp/bjUIpiAU8JAapt9I7Y9HTXQGuQGBZNebyOcws9IdTpASUVoie96Vk3fmx1uf8/o8R9e/GZ9v26dM= X-Received: by 2002:a25:a448:: with SMTP id f66mr39114675ybi.225.1640885391860; Thu, 30 Dec 2021 09:29:51 -0800 (PST) MIME-Version: 1.0 References: <20211208212211.2860249-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 30 Dec 2021 09:29:40 -0800 Message-ID: Subject: Re: [PATCH 4/3] mm: drop MMF_OOM_SKIP from exit_mmap To: Michal Hocko Cc: Johannes Weiner , Andrew Morton , David Rientjes , Matthew Wilcox , Roman Gushchin , Rik van Riel , Minchan Kim , "Kirill A. Shutemov" , Andrea Arcangeli , Christian Brauner , Christoph Hellwig , Oleg Nesterov , David Hildenbrand , Jann Horn , Shakeel Butt , Andy Lutomirski , Christian Brauner , Florian Weimer , Jan Engelhardt , Tim Murray , linux-mm , LKML , kernel-team Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D3B6B40007 X-Stat-Signature: u3pb34ku96gpehzqj8wqa9g968q1y6db Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AOm95os7; spf=pass (imf07.hostedemail.com: domain of surenb@google.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1640885392-462428 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: On Thu, Dec 30, 2021 at 12:24 AM Michal Hocko wrote: > > On Wed 29-12-21 21:59:55, Suren Baghdasaryan wrote: > [...] > > After some more digging I think there are two acceptable options: > > > > 1. Call unlock_range() under mmap_write_lock and then downgrade it to > > read lock so that both exit_mmap() and __oom_reap_task_mm() can unmap > > vmas in parallel like this: > > > > if (mm->locked_vm) { > > mmap_write_lock(mm); > > unlock_range(mm->mmap, ULONG_MAX); > > mmap_write_downgrade(mm); > > } else > > mmap_read_lock(mm); > > ... > > unmap_vmas(&tlb, vma, 0, -1); > > mmap_read_unlock(mm); > > mmap_write_lock(mm); > > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > > ... > > mm->mmap = NULL; > > mmap_write_unlock(mm); > > > > This way exit_mmap() might block __oom_reap_task_mm() but for a much > > shorter time during unlock_range() call. > > IIRC unlock_range depends on page lock at some stage and that can mean > this will block for a long time or for ever when the holder of the lock > depends on a memory allocation. This was the primary problem why the oom > reaper skips over mlocked vmas. Oh, I missed that detail. I thought __oom_reap_task_mm() skips locked vmas only to avoid destroying pgds from under follow_page(). > > > 2. Introduce another vm_flag mask similar to VM_LOCKED which is set > > before munlock_vma_pages_range() clears VM_LOCKED so that > > __oom_reap_task_mm() can identify vmas being unlocked and skip them. > > > > Option 1 seems cleaner to me because it keeps the locking pattern > > around unlock_range() in exit_mmap() consistent with all other places > > it is used (in mremap() and munmap()) with mmap_write_lock taken. > > WDYT? > > It would be really great to make unlock_range oom reaper aware IMHO. What exactly do you envision? Say unlock_range() knows that it's racing with __oom_reap_task_mm() and that calling follow_page() is unsafe without locking, what should it do? > > You do not quote your change in the full length so it is not really > clear whether you are planning to drop __oom_reap_task_mm from exit_mmap > as well. Yes, that was the plan. > If yes then 1) could push oom reaper to timeout while the > unlock_range could be dropped on something so that wouldn't be an > improvement. 2) sounds like a workaround to me as it doesn't really > address the underlying problem. With (1) potentially blocking due to allocation I can see why this is a problem. Agree about (2). > > I have to say that I am not really a great fan of __oom_reap_task_mm in > exit_mmap but I would rather see it in place than making the surrounding > code more complex/tricky. Agree. So far I could not find a cleaner solution. I thought (1) would be a good one but the point you made renders it invalid. If you clarify your comment about making unlock_range oom reaper aware maybe that will open a new line of investigation? Thanks, Suren. > > -- > Michal Hocko > SUSE Labs