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 X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 C11F9C433EF for ; Wed, 22 Sep 2021 20:04:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67EFA611CA for ; Wed, 22 Sep 2021 20:04:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 67EFA611CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E42066B006C; Wed, 22 Sep 2021 16:04:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF1DD6B0071; Wed, 22 Sep 2021 16:04:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE0786B0072; Wed, 22 Sep 2021 16:04:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id C03796B006C for ; Wed, 22 Sep 2021 16:04:49 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7CD658249980 for ; Wed, 22 Sep 2021 20:04:49 +0000 (UTC) X-FDA: 78616287498.38.65292E7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 162241000099 for ; Wed, 22 Sep 2021 20:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632341088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wfmAQj1eLnqe1D78zRkvZrSAGszWVxZZuAA8OYkxiNY=; b=dTZHuDv4yfexAkMojFRr6fa4n0vb2w7/q7UPMdGm6Xj2K9GSDiwFDQs7dc2KKG2PUL9QMV dOB6v3RpkJwYxpNXrJvp8vnvHXLPyO+d16cGgaOe68PB+mO37qNe7BKbyRECOVRc6AwUa3 c+OQOGruFRlRdInXDXbMsPL0h/9e0nU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-34-zwLG4R52PHihWnkNnrdCtw-1; Wed, 22 Sep 2021 16:04:47 -0400 X-MC-Unique: zwLG4R52PHihWnkNnrdCtw-1 Received: by mail-qk1-f200.google.com with SMTP id i16-20020a05620a249000b004558dcb5663so6285815qkn.9 for ; Wed, 22 Sep 2021 13:04:47 -0700 (PDT) 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:references :mime-version:content-disposition:in-reply-to; bh=wfmAQj1eLnqe1D78zRkvZrSAGszWVxZZuAA8OYkxiNY=; b=LJeGXQB4oAcsCP2XJMmjAoWoEJfVnGa/H9bflwIVLKpfcKN3v3OyDrq9bMInXUQ31c V+UWRDPhCvKEycZs7zSeQH37CNr39w09ilXSa64fJPKhC7766OZXv/dk05uI7v9eMfha zDTEnyhzpeJyg5L2i+b7PP8WliLocGcHSG0rhgCHYzQIbWP4nTQM91UTxr2O/Tlqe7lI Y+Vm9+8vWBU7nxlL/fnM7KUyqtuImtiGtiluE6dmAmkeBYn9zS+rB2paYN6l6+p7eHIw CeDPLphkvZ1tILBT3fDxbwDhEcjP4h+YaTqGN28gG/ZwwIIwvEKxV5OhhsO7hWlCi4ow W1Uw== X-Gm-Message-State: AOAM530lUInI6sHtbovlpD0XsGOb6sxi/fJlrKPkW78CrLenotDJeIdw o5Dk36I+ZBf70KMindDEx8Utx1QDHIkAn3P03JvXy7FnpdavKilF1kWAIOzz82AfBdf/LUC7Iz1 vEzAhPhwHzss= X-Received: by 2002:a37:6147:: with SMTP id v68mr1233864qkb.154.1632341086865; Wed, 22 Sep 2021 13:04:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx59BS+mKq7RFbazbYa4OejIGX9idyrFiC7plgv0UVXb4KSxkno+8Th2LDmkABtJdcfJe2OTg== X-Received: by 2002:a37:6147:: with SMTP id v68mr1233831qkb.154.1632341086602; Wed, 22 Sep 2021 13:04:46 -0700 (PDT) Received: from t490s ([2607:fea8:56a2:9100::d3ec]) by smtp.gmail.com with ESMTPSA id n13sm2533690qke.100.2021.09.22.13.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 13:04:46 -0700 (PDT) Date: Wed, 22 Sep 2021 16:04:44 -0400 From: Peter Xu To: Yang Shi Cc: David Hildenbrand , Linux Kernel Mailing List , Linux MM , Andrew Morton , Andrea Arcangeli , Axel Rasmussen , Hugh Dickins , Nadav Amit Subject: Re: [PATCH] mm/khugepaged: Detecting uffd-wp vma more efficiently Message-ID: References: <20210922175156.130228-1-peterx@redhat.com> <6bbb8e29-9e21-dfbe-d23d-61de7e3cc6db@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: 3sroncmgz71pkmor7wtdc4bqccggkiws Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dTZHuDv4; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf07.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 162241000099 X-HE-Tag: 1632341088-979314 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000170, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 22, 2021 at 12:29:35PM -0700, Yang Shi wrote: > khugepqged does remove the pgtables. Please check out > retract_page_tables(). The pmd will be cleared and the ptes will be > freed otherwise the collapsed THP won't get PMD mapped by later > access. Indeed. I should probably still properly disable khugepaged for at least VM_SHARED && VM_UFFD_WP, then I'd keep the anonymous && minor mode behavior untouched. The other problem is even if current mm/vma doesn't have UFFD_WP registered, some other mm/vma could have UFFD_WP enabled there that mapped the same file. Checking that up within retract_page_tables() on all VMAs seems to be a bit too late. Checking it early may not trivially work too - I can walk the vma interval tree at the entry of khugepaged_scan_file(), making sure no vma has UFFD_WP set. However I don't see how it'll stop some of the vma from having UFFD_WP registered later after that point but before retract_page_tables(). I'll need to think about it, but thanks for the input, Yang. That's a very important point. -- Peter Xu