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=-12.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 66F19C433F5 for ; Wed, 22 Sep 2021 20:23:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0A2D161019 for ; Wed, 22 Sep 2021 20:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0A2D161019 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 9E7C96B006C; Wed, 22 Sep 2021 16:23:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 970BA6B0071; Wed, 22 Sep 2021 16:23:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EA58900002; Wed, 22 Sep 2021 16:23:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 7048B6B006C for ; Wed, 22 Sep 2021 16:23:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2F3D3181CC1C4 for ; Wed, 22 Sep 2021 20:23:28 +0000 (UTC) X-FDA: 78616334496.24.578C898 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id D525EE001990 for ; Wed, 22 Sep 2021 20:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632342207; 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=YVbeoTaMblrjpDgFDVGvCcjBz8Qir6DmYn1S2zIAe9c=; b=R1AvbUJ5tQgIO2VEeaYMcUa3nDnqYTbDzvQ3uZ4ZNsEr+vNowFgBTB03u9ZUIjn/z11GdB 29AxrtWTAbkVEs/kyHG2rx43R40sQUHxlkLQkJ2MCkncqAveeQ/aXWCuWGovsAbBVmI5JX Pvj293cqaJWp89jAUMFAzV+6qrioYzk= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-QwJ7SjpXPtOkZ_Jg4gwJTQ-1; Wed, 22 Sep 2021 16:23:24 -0400 X-MC-Unique: QwJ7SjpXPtOkZ_Jg4gwJTQ-1 Received: by mail-qt1-f197.google.com with SMTP id o9-20020ac80249000000b002a0c9fd54d5so11432053qtg.4 for ; Wed, 22 Sep 2021 13:23:24 -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=YVbeoTaMblrjpDgFDVGvCcjBz8Qir6DmYn1S2zIAe9c=; b=pfYavV5vL/hfzi/X0Hab+LUYnJcQReZGurEvXCay++UrUTpH1uqXqvY6dFu99515lj mJ7+x6ae8CbM7WUbmfDWyQ01jrIDxo+lKZyP2lSpChImh4iFIV9Eb8SLtkIZVJDrfqjD VEo9eW26EyZl2qoR5iuKNih8bSilas3+CMk+Q4c5Zuw9S7qtOnMsl8jubCoezDzC84jI ORRxsVcR2AeolBVJ9xb31hqWiKHiDH31vSrZ9ThQOp6+Q6G0mQv4jdjRTNQkkAHV7UHH WXAZlyqtbp5Ud8Lapf4QSaju2ucNEUmvm98lecY5fH5gujtzkwiRIkUibeQsg8d3DCUu LhMw== X-Gm-Message-State: AOAM532y5rZ/f5pGHwnlXQ6Iy6d3i7x1fP+w9VjxvGGvZoLWGUSQhazI jWUGzSZoTKehij6sCbDx40wUbZNNqINL3uXQ4lPzFRn3EZGXS0yhgGQDit1Lw27LCqb/pS/FHuy 5kdFN3FIGusA= X-Received: by 2002:ac8:1e93:: with SMTP id c19mr1313220qtm.60.1632342203842; Wed, 22 Sep 2021 13:23:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcOXxTuN0eQjzkMusH8rj1CjLqI2bazEFBAGq+lK7mxZ3BQ0khzrCDQUBODpcRcwUbqrb7wA== X-Received: by 2002:ac8:1e93:: with SMTP id c19mr1313193qtm.60.1632342203556; Wed, 22 Sep 2021 13:23:23 -0700 (PDT) Received: from t490s ([2607:fea8:56a2:9100::d3ec]) by smtp.gmail.com with ESMTPSA id d9sm2565059qko.111.2021.09.22.13.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 13:23:23 -0700 (PDT) Date: Wed, 22 Sep 2021 16:23:21 -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: eg1p1cjc9bxq1nar7pf384aeir1cwtju Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R1AvbUJ5; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.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: D525EE001990 X-HE-Tag: 1632342207-432993 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 Wed, Sep 22, 2021 at 04:04:44PM -0400, Peter Xu wrote: > 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. Perhaps I need something like this: ---8<--- diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 045cc579f724..c63e957336d1 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1583,6 +1583,15 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) pmd = mm_find_pmd(mm, addr); if (!pmd) continue; + /* + * When a vma is registered with uffd-wp, we can't recycle the + * pmd pgtable because there can be pte markers installed. + * Skip it only, so the rest mm/vma can still have the same + * file mapped hugely, however it'll always mapped in small + * page size for uffd-wp registered ranges. + */ + if (userfaultfd_wp(vma)) + continue; /* * We need exclusive mmap_lock to retract page table. * ---8<--- I won't post a v2 because then that patch will be shmem-only and uffd-wp-only. I'll keep it with the upcoming series I'm going to post to support shmem. Thanks, -- Peter Xu