From patchwork Wed Jul 7 20:08:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12364019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B4C5C07E95 for ; Wed, 7 Jul 2021 20:39:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E367E61C5F for ; Wed, 7 Jul 2021 20:39:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E367E61C5F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 977816B0011; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94E236B005D; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EEFA6B006C; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 5D6726B0011 for ; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AB5A227706 for ; Wed, 7 Jul 2021 20:39:35 +0000 (UTC) X-FDA: 78336957510.28.584C32B Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf17.hostedemail.com (Postfix) with ESMTP id 49DD6F001FB7 for ; Wed, 7 Jul 2021 20:39:35 +0000 (UTC) Received: by mail-oi1-f181.google.com with SMTP id t3so4960813oic.5 for ; Wed, 07 Jul 2021 13:39:35 -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 :mime-version; bh=AEUjbJEHgjwZH84O8/yOmL96IkupdJt703GIG/Lw/Sw=; b=aIfEXDg7X8c6i6RMt2XjPCogxnvkLnZWUZiLZ79qAP2eZuzQiThqTe/Wt23LFK/d7N k5hF8xQNkmVcxNu3wCGxN8L3VJungjMW9tWj0G+iUEcY6hZlHdjRSKfQzIIf+z+y9Jzh QNficFcQho0jB2dIVnAssiHtmbwVSgh8cAQI56fRqelW/syOtyiwPFHRwF9M86BFkIFW QvQXm/BAjmg/ClC5HPMT/QsmFc1D5/6INGIn9IUq4Yq2yLZOr+9X116mQy+W8Hzar+qh QieIJ96JHJlqH6Wnxd7BDUWPkIvipTfS9+3awv6YTUQ438T23gxjXb/F2y3VlzRa5z/j ZgGQ== 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:mime-version; bh=AEUjbJEHgjwZH84O8/yOmL96IkupdJt703GIG/Lw/Sw=; b=aHZzxDBgEmmHijUwftQfpFwYXkkLQJv/4cqMog7tKgoK/sWUlIxwMwtmUwnSKfNMpp wJHzu4rg/kPOo11FEdOOC/3u2NjiBgYBllF3G0LjJH0gaNQqHy/KJdR131BpOjDwckgL rWxer2Dj9hYJEYOshSy0sXroFXSU0onn6ZVOzHGbpvws+SFnOpoZY15BLzGtNkSuDEgx F4GU6Z55r7IXtuRJFxu40pIT31rr9M0TAubUtb/42qbAPdK/QSa5aHuPJfatiiY3yeV2 m5afF9ywUInb2U3OfP1oknP9guGJ8cmio/5J4XVQJ2JjUmm8fM7rn/ixPHYyshk4LFga Uc0A== X-Gm-Message-State: AOAM530BKpktnvV/PvpsL+aIERILmvSPKObJdtg+zG0JK4MgQbXb/Jzt VGIcLKl4Sp5WGTtr0itXT/apxYBdAno1dw== X-Google-Smtp-Source: ABdhPJwtImQxt1QzEcdZdsVyVe8aD+gMiqiWoksjK7o9JOc9vBTzXLdVlrO6UFB4z710wRyFTr0zXQ== X-Received: by 2002:aca:db44:: with SMTP id s65mr11399367oig.139.1625688536945; Wed, 07 Jul 2021 13:08:56 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 25sm3729500oir.58.2021.07.07.13.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 13:08:56 -0700 (PDT) Date: Wed, 7 Jul 2021 13:08:53 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Christoph Hellwig , Yang Shi , "Kirill A. Shutemov" , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm/rmap: fix old bug: munlocking THP missed other mlocks In-Reply-To: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> Message-ID: References: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=aIfEXDg7; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-Stat-Signature: mzz7d8hrtzym5w1crkd7g5xjaimo33ie X-Rspamd-Queue-Id: 49DD6F001FB7 X-Rspam-User: nil X-HE-Tag: 1625690375-575199 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: The kernel recovers in due course from missing Mlocked pages: but there was no point in calling page_mlock() (formerly known as try_to_munlock()) on a THP, because nothing got done even when it was found to be mapped in another VM_LOCKED vma. It's true that we need to be careful: Mlocked accounting of pte-mapped THPs is too difficult (so consistently avoided); but Mlocked accounting of only-pmd-mapped THPs is supposed to work, even when multiple mappings are mlocked and munlocked or munmapped. Refine the tests. There is already a VM_BUG_ON_PAGE(PageDoubleMap) in page_mlock(), so page_mlock_one() does not even have to worry about that complication. (I said the kernel recovers: but would page reclaim be likely to split THP before rediscovering that it's VM_LOCKED? I've not followed that up.) Fixes: 9a73f61bdb8a ("thp, mlock: do not mlock PTE-mapped file huge pages") Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Signed-off-by: Hugh Dickins Acked-by: Kirill A. Shutemov --- mm/rmap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 746013e282c3..0e83c3be8568 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1442,8 +1442,9 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, */ if (!(flags & TTU_IGNORE_MLOCK)) { if (vma->vm_flags & VM_LOCKED) { - /* PTE-mapped THP are never mlocked */ - if (!PageTransCompound(page)) { + /* PTE-mapped THP are never marked as mlocked */ + if (!PageTransCompound(page) || + (PageHead(page) && !PageDoubleMap(page))) { /* * Holding pte lock, we do *not* need * mmap_lock here @@ -1984,9 +1985,11 @@ static bool page_mlock_one(struct page *page, struct vm_area_struct *vma, * munlock_vma_pages_range(). */ if (vma->vm_flags & VM_LOCKED) { - /* PTE-mapped THP are never mlocked */ - if (!PageTransCompound(page)) - mlock_vma_page(page); + /* + * PTE-mapped THP are never marked as mlocked, but + * this function is never called when PageDoubleMap(). + */ + mlock_vma_page(page); page_vma_mapped_walk_done(&pvmw); }