Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp29118pxb; Mon, 7 Feb 2022 05:52:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIGSxUimN30qhidcEqC/E+ST60M7hamgYGlHQmFURaZF9DSQP7BiT5DqQC71ZSUVVChi3y X-Received: by 2002:a05:6402:42c6:: with SMTP id i6mr14460263edc.166.1644241947840; Mon, 07 Feb 2022 05:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644241947; cv=none; d=google.com; s=arc-20160816; b=BqCmTMBEJqDjW1YPge4QuPmeVmeU2rj3mGW7pCCCy/gkUQSomggLF1n+e2CSEgIQWJ 6KN0FHLzCGEjeKNo3a71KdvSn4bd9uDauB0nsf41A9TGlYwaVUM94roUbyc0DicVFNdG r/OLC1bLKnmAILXMRVb4GzVO2oEzzv2IkAY0zKa0kCq1iywWih620t9zIm/UlXtPXPGq plBgw9RcLICq43xdSfI3/IzAFruDFI2xpQ7cK6uz1buBaVvZ5mdg2cPG5DWRljtvAEml 6w8lbDLxD4+vwDGTWJgOEySqkqMnoRsjoytBlLZirEIvjjQvHhUpjWB9RJPeiezoIFmj RDFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=zqtCWZR8fUoymI1gulqeyWRyxqO7AdNIEXaSeKYJoAM=; b=G4ux1hICU1//vSQwIZviuw1u4WsdqEBOk7OPqRbFqkQTTFdxJKrzlaeJchiCaXvHRB ZlAy3jvQDq07ipnLJ4n/t9L36I0AifM8Y+FcGaVyyL77hAZZJ0q2uaBPH+7xI0Meueyh +I9dUsSgg4AtJGoZYkuUfovf+UDdDr8M0GMdiw3DenecIDLdY3mVKiw/JOkY+NWGqNT9 raG74JGvPlgTxDbeKB7L4Rxd345hPSlxDOYF5xJzkCfjGj7hBmZiwAcMxT+63rD6fceA tZc9TvRVEZLRBRsDLQsOQ42+joWax/fFSlpA6dZpTOUenqKG9hTmDUDw3DeslsqMA0oG QEIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="kqO/dGkR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6si201182edr.654.2022.02.07.05.52.03; Mon, 07 Feb 2022 05:52:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="kqO/dGkR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238534AbiBFV17 (ORCPT + 99 others); Sun, 6 Feb 2022 16:27:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbiBFV16 (ORCPT ); Sun, 6 Feb 2022 16:27:58 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B0F7C06173B for ; Sun, 6 Feb 2022 13:27:53 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id t1so4485302qtq.13 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=L3UxPy1MeSSwC+UsOnrrYDMyJVs8WLywURMM7l0VM+q9px2+3/scn9/xpvK7QSDSvL M2xRliQ1aKJiTzNKIV/nYkjh3zCXsZPpfap398bk1y9WRYSJDuXl3vMMoGiLhvH4QZhq dNHs0Sjrd2ZQZsfLd0FaRO6/JmoM3TNxnOui0fO0UZmeXY4PR0cwGR3k2U+QRD5ZD8uW 6WAyxadHvlriqNqLALntI7LG+xUB59Rne8hMyhyUOf4ryXljF4cUgIiGirX1C4VUgKm4 z6ktng+vZcz/Je1zy20QL44DzOxRY8Br5mOQZooHQaWt+6680cmReYBfea4YXAxHX+zK vZ6Q== X-Gm-Message-State: AOAM533kDiRyGYn+zIGcC1GdJ9U8H7d93Rbux3aKOvj7UpwatnQa8lxf ibCMX2oy9q+CLm87M/VI0RQaxw== 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 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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