From patchwork Sun Feb 6 21:27:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12736725 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 29859C433EF for ; Sun, 6 Feb 2022 21:27:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4ED4A6B0072; Sun, 6 Feb 2022 16:27:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 475F56B0073; Sun, 6 Feb 2022 16:27:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EEED6B0074; Sun, 6 Feb 2022 16:27:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 18C736B0072 for ; Sun, 6 Feb 2022 16:27:54 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C317595C89 for ; Sun, 6 Feb 2022 21:27:53 +0000 (UTC) X-FDA: 79113642426.07.C08CB9A Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf29.hostedemail.com (Postfix) with ESMTP id 679CF120002 for ; Sun, 6 Feb 2022 21:27:53 +0000 (UTC) Received: by mail-qt1-f173.google.com with SMTP id x5so10477282qtw.10 for ; Sun, 06 Feb 2022 13:27:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=zqtCWZR8fUoymI1gulqeyWRyxqO7AdNIEXaSeKYJoAM=; b=kqO/dGkR7ZxLu6uzdv1UcwYe2PBhojIF61LbLnI2gnfowsuH9YQ4GKiePJOm4UV4S0 kI1vcq7XCbJ8uGmdEN7B74kHKjJVfgORIcqXAaRxBvUiK0GyTtQF4dxjjvnDfkW5H0wA pmU1AfpN15yefaFud3l6uSYL3PqmoXTzn76klqjoMzVLwb8cY1U6RmfR5nIsZKLlw4SF 4h2uXpkQI9NTF/Wan27jjVvQcbKD3sYStczmq3zuYF+36sFhdFw6elhvxV2Kfvbv+hmW F8JoQqC2vMQ/Es6+jfyIhrbET7x/Q8vLFKjkauyo3/mO2AwntPC3xZFWdJw+B4Kl01cV Cx+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=zqtCWZR8fUoymI1gulqeyWRyxqO7AdNIEXaSeKYJoAM=; b=vcliEMF2vg0in1dWKZK8p5AxUxlaGBqkQAx1xPoK6voTm4h5JKnmoNNVcBOm4k/fyZ prTLnS79lH3NgQ5A2oyT2GIvoPcMcYmbdesFJ4Y834RGdn5N05J45xcQcIxJjDBDR8uP MFKvEZsbTwnHywlPqQxwCi1mhOjUCiujkVICh8NQiyKx8mmXPJ4AUANTh1wWX+7UwHe3 KdCJq1VrgRpPLlzagS1ujer71rbJZRA5hWGetWZ92Q3kp2dcRObFLLVhlO5rLfQy4Xur VqC8qd0oYwC5okVlmettgOLlZ+hqW3lVODM6pXcM4t1Yn0r6P2rMyaahdbhagHoaU6rC CoGQ== X-Gm-Message-State: AOAM5303I5rhNdy0NjZAQnZxuJTDsxLewzhjOrfF/4koLOZqFYH+ZLQJ uMlaqZZFqoa+sgbC6ck8k9WCdQ== X-Google-Smtp-Source: ABdhPJz5Tu/r8mnrKYdIrl/e/+oMWgxDcrxeVttb0N1e1D1ZK6ss3WrC744gLeUyabu6oL9mLlNQfQ== X-Received: by 2002:ac8:5aca:: with SMTP id d10mr6091273qtd.565.1644182872541; Sun, 06 Feb 2022 13:27:52 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id b9sm4372948qkj.24.2022.02.06.13.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 13:27:52 -0800 (PST) Date: Sun, 6 Feb 2022 13:27:41 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Michal Hocko , Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 00/13] mm/munlock: rework of mlock+munlock page handling Message-ID: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 679CF120002 X-Rspam-User: nil Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="kqO/dGkR"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of hughd@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: 5pg7nooo54xqxnk9wckr7xtwck8c666g X-HE-Tag: 1644182873-463122 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: I wondered whether to post this munlocking rework in https://lore.kernel.org/linux-mm/35c340a6-96f-28a0-2b7b-2f9fbddc01f@google.com/ There the discussion was OOM reaping, but the main reason for the rework has been catastrophic contention on i_mmap_rwsem when exiting from multiply mlocked files; and frustration with how contorted munlocking is. Here it is based on 5.17-rc2, applies also to -rc3, almost cleanly to mmotm 2022-02-03-21-58 (needs two easy fixups in mm/huge_memory.c); but likely to conflict (I hope not fundamentally) with several concurrent large patchsets. tl;dr mm/mlock.c | 634 +++++++++++++++----------------------- 23 files changed, 510 insertions(+), 779 deletions(-) In my own opinion, this is ready to go in: that whatever its defects, it's a big practical improvement over what's presently there. Others may differ; and it may be too much to arrive at a quick opinion on. My hope is that it will strike a chord with some who have laboured in this area in the past: I'll be short of time to do much more with it, so maybe someone else could take over if necessary. At present there's no update to Documentation/vm/unevictable-lru.rst: that always needs a different mindset, can follow later, please refer to commit messages for now. There are two half-related mm/thp patches at the end: enhancements we've had for a long time, but more suited after the mlock changes. 01/13 mm/munlock: delete page_mlock() and all its works 02/13 mm/munlock: delete FOLL_MLOCK and FOLL_POPULATE gupflags 03/13 mm/munlock: delete munlock_vma_pages_all(), allow oomreap 04/13 mm/munlock: rmap call mlock_vma_page() munlock_vma_page() 05/13 mm/munlock: replace clear_page_mlock() by final clearance 06/13 mm/munlock: maintain page->mlock_count while unevictable 07/13 mm/munlock: mlock_pte_range() when mlocking or munlocking 08/13 mm/migrate: __unmap_and_move() push good newpage to LRU 09/13 mm/munlock: delete smp_mb() from __pagevec_lru_add_fn() 10/13 mm/munlock: mlock_page() munlock_page() batch by pagevec 11/13 mm/munlock: page migration needs mlock pagevec drained 12/13 mm/thp: collapse_file() do try_to_unmap(TTU_BATCH_FLUSH) 13/13 mm/thp: shrink_page_list() avoid splitting VM_LOCKED THP include/linux/mm.h | 2 include/linux/mm_inline.h | 11 include/linux/mm_types.h | 19 + include/linux/rmap.h | 23 - kernel/events/uprobes.c | 7 mm/gup.c | 43 -- mm/huge_memory.c | 55 --- mm/hugetlb.c | 4 mm/internal.h | 64 ++- mm/khugepaged.c | 14 mm/ksm.c | 12 mm/madvise.c | 5 mm/memcontrol.c | 3 mm/memory.c | 45 -- mm/migrate.c | 42 +- mm/mlock.c | 634 +++++++++++++++----------------------- mm/mmap.c | 32 - mm/mmzone.c | 7 mm/oom_kill.c | 2 mm/rmap.c | 156 ++------- mm/swap.c | 89 ++--- mm/userfaultfd.c | 14 mm/vmscan.c | 6 23 files changed, 510 insertions(+), 779 deletions(-) Hugh