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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B534C43334 for ; Wed, 15 Jun 2022 19:52:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D760A6B0071; Wed, 15 Jun 2022 15:52:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D25226B0072; Wed, 15 Jun 2022 15:52:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC57F6B0074; Wed, 15 Jun 2022 15:52:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AD8746B0071 for ; Wed, 15 Jun 2022 15:52:16 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8668628E for ; Wed, 15 Jun 2022 19:52:16 +0000 (UTC) X-FDA: 79581516672.18.F2194C3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 2AA91C0098 for ; Wed, 15 Jun 2022 19:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655322735; 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=YRLwzrcO75eUkj7xSmsgTB+2q1qWebaIXpEC9jk4So8=; b=BhhkgoCyO9fthZhLIveEPC+GUcYDfIww1x4IyWI4MDA4PG3gtQ480qklLwLUIFpOC5Qvib 0Cq+EvZm02bxa7tReuaoJmrGGIGgzniZ3hyhI39biRRgnPS2rCcUnGjMNEozlE0NQ6s5tp FzgC7Az8c0iSoA7PKii6WnH6uJyPsE0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-79-bu_jDSllPVyfc9lUO-uNmA-1; Wed, 15 Jun 2022 15:52:14 -0400 X-MC-Unique: bu_jDSllPVyfc9lUO-uNmA-1 Received: by mail-wm1-f69.google.com with SMTP id m23-20020a05600c3b1700b0039c6e3c169aso1655957wms.2 for ; Wed, 15 Jun 2022 12:52:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=YRLwzrcO75eUkj7xSmsgTB+2q1qWebaIXpEC9jk4So8=; b=0thp8p85U430QkSyqrksmh7eShQ0/VVN1dFjK0fkSQgHEA7HNg5rbbnkjjX7kTF5d8 OeeitOGVlHu2su21iRRQFe9Wtd5v2QhypnLbmiBGhoTWqMcX7RpRT2V8y2hw3js9hAYf pjAdGrv1RIIxY5qtmaL9SNM35VVr4eJ6NAu5rqEFEPEcXEj9bpvCYEgNrRihBbm+R4ib 3VFHPtqnHn0pdEEAnBDNt210M+ZmdoAkiK3icpMLYfZHz5rYV7OWYILNYT6SClg9p2YA Hkx7X9gm16oFjPi/SgSNToiOKEFZda2R1HJ2SdtxXBwvRXnbSYyTxSvhtydAFtujXVPl 6IQg== X-Gm-Message-State: AJIora8WBxUaWZhtMvnKS12wVQxHtqhlJsPpMHi0FOLbt29TgLSnZrbl pifAEYMdr1WX0pNt9P3WgXV01vQReSI0jpphsBtoN7GED2kStW0t0lnKBF0pnhJiodALDmTtpjM s6IBAr1SP0BA= X-Received: by 2002:adf:f385:0:b0:213:bb0e:383a with SMTP id m5-20020adff385000000b00213bb0e383amr1320011wro.481.1655322733543; Wed, 15 Jun 2022 12:52:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uLuCrcc2dD7oeLp1sOoZuvyfwuwYmCD090QJLv13+V/Kkg/fUSiN7SqNEnaj6HOVRhsUTsgg== X-Received: by 2002:adf:f385:0:b0:213:bb0e:383a with SMTP id m5-20020adff385000000b00213bb0e383amr1319996wro.481.1655322733286; Wed, 15 Jun 2022 12:52:13 -0700 (PDT) Received: from ?IPV6:2003:cb:c70a:2700:1d28:26c3:b272:fcc6? (p200300cbc70a27001d2826c3b272fcc6.dip0.t-ipconnect.de. [2003:cb:c70a:2700:1d28:26c3:b272:fcc6]) by smtp.gmail.com with ESMTPSA id d9-20020a5d6449000000b002101ed6e70fsm15466874wrw.37.2022.06.15.12.52.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jun 2022 12:52:12 -0700 (PDT) Message-ID: <3f190cd4-df87-feeb-bae4-56348498fa82@redhat.com> Date: Wed, 15 Jun 2022 21:52:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Collingbourne , Linus Torvalds , Andrew Morton , Nadav Amit , Dave Hansen , Andrea Arcangeli , Yang Shi , Hugh Dickins , Mel Gorman References: <20220614093629.76309-1-david@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3] mm/mprotect: try avoiding write faults for exclusive anonymous pages when changing protection In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655322736; h=from:from:sender: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:dkim-signature; bh=YRLwzrcO75eUkj7xSmsgTB+2q1qWebaIXpEC9jk4So8=; b=VBWuWgJwVymdE67wBZBOQQxCohwW+BIClVGMu8CH7W0Ofuw0hAC1EOQO2KCqbXC1DD0hlq ukOf73Xc7ocR6TGcGUcIYz1T6j0oU5ZGtMqCv3eiwXMzTpHl7qxGvtLaJvn8QG5WGRKzvg sGtO3lal7lDun6pU7ie3VNCMs2JPo4g= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BhhkgoCy; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655322736; a=rsa-sha256; cv=none; b=e8MLq3NdC/oXRbGZs5YYBUkw5Xjof5bJTXA55wt4p1QjANFbDvI3JteyO0yQtGJoJToQ57 FSndQ5ylXOdASWMDoxQNWChUQ5HkzetBQCrN/m7x7k351hwQGQ8ZdPX6t0YXuJwxCfB3Ub K1rAaryJA+mS9y8EpbQZ1LQPnIUzp1o= X-Rspamd-Queue-Id: 2AA91C0098 X-Rspam-User: X-Stat-Signature: ddki3my45u75udrebw54p8ptbo51oicx Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BhhkgoCy; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam04 X-HE-Tag: 1655322736-579512 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 15.06.22 17:25, Peter Xu wrote: > On Tue, Jun 14, 2022 at 11:36:29AM +0200, David Hildenbrand wrote: >> Similar to our MM_CP_DIRTY_ACCT handling for shared, writable mappings, we >> can try mapping anonymous pages in a private writable mapping writable if >> they are exclusive, the PTE is already dirty, and no special handling >> applies. Mapping the anonymous page writable is essentially the same thing >> the write fault handler would do in this case. >> >> Special handling is required for uffd-wp and softdirty tracking, so take >> care of that properly. Also, leave PROT_NONE handling alone for now; >> in the future, we could similarly extend the logic in do_numa_page() or >> use pte_mk_savedwrite() here. >> >> While this improves mprotect(PROT_READ)+mprotect(PROT_READ|PROT_WRITE) >> performance, it should also be a valuable optimization for uffd-wp, when >> un-protecting. >> >> This has been previously suggested by Peter Collingbourne in [1], >> relevant in the context of the Scudo memory allocator, before we had >> PageAnonExclusive. >> >> This commit doesn't add the same handling for PMDs (i.e., anonymous THP, >> anonymous hugetlb); benchmark results from Andrea indicate that there >> are minor performance gains, so it's might still be valuable to streamline >> that logic for all anonymous pages in the future. >> >> As we now also set MM_CP_DIRTY_ACCT for private mappings, let's rename >> it to MM_CP_TRY_CHANGE_WRITABLE, to make it clearer what's actually >> happening. > > I'm personally not sure why DIRTY_ACCT cannot be applied to private > mappings; it sounds not only for shared but a common thing. I also don't TBH, I think the name is just absolutely unclear in that context. > know whether "change writable" could be misread too anyway. Say, we're > never changing RO->RW mappings with this flag, but only try to unprotect > the page proactively when proper, from that POV Nadav's suggestion seems > slightly better on using "unprotect". write unprotection is a change from RO->RW, so I don't immediately see the difference. Anyhow, I don't like the sounding of TRY_WRITE_UNPROTECT. I made it match the function name that I had: MM_CP_TRY_CHANGE_WRITABLE -> !pte_write()? -> can_change_pte_writable() ? ->pte_mkwrite() Maybe MM_CP_TRY_MAKE_WRITABLE / MM_CP_TRY_MAKE_PTE_WRITABLE is clearer? Open for suggestions because I'm apparently not the bast at naming things either. > > No strong opinion, the patch looks correct to me, and thanks for providing > the new test results, > > Acked-by: Peter Xu > Thanks Peter! -- Thanks, David / dhildenb