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=-8.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 77A97C433EF for ; Fri, 24 Sep 2021 10:05:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE34F610CB for ; Fri, 24 Sep 2021 10:05:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE34F610CB 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 7258C940007; Fri, 24 Sep 2021 06:05:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AE19900002; Fri, 24 Sep 2021 06:05:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5276C940007; Fri, 24 Sep 2021 06:05:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id 3C60E900002 for ; Fri, 24 Sep 2021 06:05:29 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E91B12BC34 for ; Fri, 24 Sep 2021 10:05:28 +0000 (UTC) X-FDA: 78622034736.29.C550A0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 93D67B000099 for ; Fri, 24 Sep 2021 10:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632477927; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G1MHHrRMd/7rgiVSmOO3Ic9tCAKxtmx125cnMX3Uf3g=; b=Fli1fw2Mcl0BToow5ZK7kJPKXu3LCvadBoPu8UJlG4qXEOl/faZiqx61780X2nBd3088bR FdG2OgLXrqZ4Jr7c2hS8GvBskeP3pOXAOYegcRUGkNo2hFGHxaOQZgnfaJCtasZxf0XrB5 N17V0AM9zDMcD2mSVWiczikVciNF7dE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-EnHqBOzkP3-LufV_KejCFw-1; Fri, 24 Sep 2021 06:05:26 -0400 X-MC-Unique: EnHqBOzkP3-LufV_KejCFw-1 Received: by mail-wr1-f71.google.com with SMTP id r15-20020adfce8f000000b0015df1098ccbso7653247wrn.4 for ; Fri, 24 Sep 2021 03:05:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=G1MHHrRMd/7rgiVSmOO3Ic9tCAKxtmx125cnMX3Uf3g=; b=QiBr9lY98mIDm4kY+KeyJ0M3aQqZDtRr5e3obGQiIKkDFRZXEDG+dF4FFFTaZbiCqF MhqjebTjcLjDKRRULkqBoQbF6huJ9YxMtz1PJCzBvrXx6G6sjLVCL2M9Yyg3x63+g2nT M62et/IO2ThHhl1S+23xHM8vTdRsLZiWvcxmDAvP+85IKDL9J3Pob1/o2eAYukefGZCy 2N+byJHbgK25pBszmiyMV7yyeUUGDGsL1/QdV7HT00AJmX8Odb2nDjGz99f0IxBfzOq6 Uafk4rL/oSRa45LpMmN2DzGSO8ub8vWaeFqfni1pj281usAp5ukrelFlRoCGQdF98dWV s1tA== X-Gm-Message-State: AOAM533prWpKYkJdd0Gw3A0n9KUk5DRVjtyvZNt6kIGNYIxDueMCECag DTxvIb0TEV3pp6X1ExYuVNN5xdSajkcE/wl7/CDEXXcpP/bAE9Vk9jUXTZY4eu8byUjI5W6SICm valZKSh7v0EA= X-Received: by 2002:adf:e481:: with SMTP id i1mr10430154wrm.353.1632477925753; Fri, 24 Sep 2021 03:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1JpvaN7QXgXQv6sMLeO1OF9LmUYwSp23XprYC2U34yKRztdqKdy9ePX35meKz7gH0zxLCEA== X-Received: by 2002:adf:e481:: with SMTP id i1mr10430127wrm.353.1632477925517; Fri, 24 Sep 2021 03:05:25 -0700 (PDT) Received: from [192.168.3.132] (p5b0c61fc.dip0.t-ipconnect.de. [91.12.97.252]) by smtp.gmail.com with ESMTPSA id y64sm8597845wmc.38.2021.09.24.03.05.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 03:05:25 -0700 (PDT) Subject: Re: [PATCH] mm/khugepaged: Detecting uffd-wp vma more efficiently To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Andrea Arcangeli , Axel Rasmussen , Hugh Dickins , Nadav Amit References: <20210922175156.130228-1-peterx@redhat.com> <6bbb8e29-9e21-dfbe-d23d-61de7e3cc6db@redhat.com> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Fri, 24 Sep 2021 12:05:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Fli1fw2M; spf=none (imf24.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 93D67B000099 X-Stat-Signature: xh8m6fqzo9p5nxhwki6d3hu7g3r4yewu X-HE-Tag: 1632477928-313745 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 22.09.21 20:58, Peter Xu wrote: > On Wed, Sep 22, 2021 at 08:21:40PM +0200, David Hildenbrand wrote: >> On 22.09.21 19:51, Peter Xu wrote: >>> We forbid merging thps for uffd-wp enabled regions, by breaking the khugepaged >>> scanning right after we detected a uffd-wp armed pte (either present, or swap). >>> >>> It works, but it's less efficient, because those ptes only exist for VM_UFFD_WP >>> enabled VMAs. Checking against the vma flag would be more efficient, and good >>> enough. To be explicit, we could still be able to merge some thps for >>> VM_UFFD_WP regions before this patch as long as they have zero uffd-wp armed >>> ptes, however that's not a major target for thp collapse anyways. >>> >> >> Hm, are we sure there are no users that could benefit from the current >> handling? >> >> I'm thinking about long-term uffd-wp users that effectively end up wp-ing on >> only a small fraction of a gigantic vma, or always wp complete blocks in a >> certain granularity in the range of THP. > > Yes, that's a good question. > >> >> Databases come to mind ... > > One thing to mention is that this patch didn't forbid thp being used within a > uffd-wp-ed range. E.g., we still allow thp exist, we can uffd-wp a thp and > it'll split only until when the thp is written. > > While what this patch does is it stops khugepaged from proactively merging > those small pages into thps as long as VM_UFFD_WP|VM_UFFD_MINOR is set. It may > still affect some user, but it's not a complete disable on thp. > >> >> In the past, I played with the idea of using uffd-wp to protect access to >> logically unplugged memory regions part of virtio-mem devices in QEMU -- >> which would exactly do something as described above. But I'll most probably >> be using ordinary uffd once any users that might read such logically >> unplugged memory have been "fixed". > > Yes, even if you'd like to keep using uffd-wp that sounds like a very > reasonable scenario. > >> >> The change itself looks sane to me AFAIKT. > > So one major motivation of this patch of mine is to prepare for shmem, because > the old commit obviously only covered anonymous. > > But after a 2nd thought, I just noticed shmem shouldn't have a problem with > khugepaged merging at all! > > The thing is, when khugepaged is merging a shmem thp, unlike anonymous, it'll > not merge the ptes into a pmd, but it'll simply zap the ptes. It means all > uffd-wp tracking information won't be lost even if merging happened, those info > will still be kept inside pgtables using (the upcoming) pte markers. > > When faulted, we'll just do small page mappings while it won't stop the shmem > thp from being mapped hugely in other mm, afaict. > > With that in mind, indeed I see this patch less necessary to be merged; so for > sparsely wr-protected vmas like virtio-mem we can still keep some of the ranges > mergeable, that sounds a good thing to keep it as-is. > > NACK myself for now: let's not lose that good property of both thp+uffd-wp so > easily, and I'll think more of it. > Thanks for the insights, shmem THP is still mostly unexplored territory on my end :) -- Thanks, David / dhildenb