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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 0BFCEC4707F for ; Thu, 27 May 2021 23:37:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7807F611C2 for ; Thu, 27 May 2021 23:37:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7807F611C2 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 C84976B006C; Thu, 27 May 2021 19:37:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0DC16B006E; Thu, 27 May 2021 19:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A60276B0070; Thu, 27 May 2021 19:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0068.hostedemail.com [216.40.44.68]) by kanga.kvack.org (Postfix) with ESMTP id 6F8B76B006C for ; Thu, 27 May 2021 19:37:24 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F0B73181AF5CA for ; Thu, 27 May 2021 23:37:23 +0000 (UTC) X-FDA: 78188624766.37.94DEC75 Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 1816E2000AFE for ; Thu, 27 May 2021 23:37:15 +0000 (UTC) Received: by mail-il1-f171.google.com with SMTP id z1so1856034ils.0 for ; Thu, 27 May 2021 16:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZchUHYL6aLWcNxOkw0qYO3wif5kNxqL4X0sOnPqBgYQ=; b=RwIrJsAKXIc0kazg6L0OP/1SLHJAOcfkMjfRvxUtE0S795oxq66Ud0xRM0/mGsNbMA OoTU/b/BBWQZ5lq7pC8dDrlIiwk3ThJmdM+2e0YjCadqqZigKH5row5etj3yWu1qrhxx o0ly3/hF/Vbyf/Oypanc4QFpGD0qv/sjHwDJG7/fOqLwYe7kKADWO77ad/7z8c3n6pA8 TFVr2UkyAYJQkjN7qd5AR077EWu+sjgEsM1HJK3A+XhSQkzEPLWWlt3Fzp88/wkFV9Io dk8Xdoht5pJUoAlVzA0ywPHLFhFSvqknGQi2SHcOWrwN7uMvNral7v7DRe2U+cVwOIyK ipSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZchUHYL6aLWcNxOkw0qYO3wif5kNxqL4X0sOnPqBgYQ=; b=KSrTSnHZRjqpbgQDVGu8cwNxElhwJfW7EAAehaEH/4XPdva+mDPZZpRGpLLuzpIKaU IINhANCMLuM1TzIqZ/Def13StmSZ1jdj2rszhZRIkulorbsXMurYfCT3uVo0MInTzkdV nZqCASIN56XsDTqdN0YURGD13LQrGF6Ca9WivpSyvE9lkcJ+6rcrzKqaCPFK5ncNRFZ+ xu4iK9cTc5yz2q32D7oGNXO3OWbd/3D+EkVILdXGBNGUNgIdG/THV+QQMSL6eYq5hEWd iJgSciqKBvF9c0c/UrIw+8wFG/eEPtPMMNME2hZjwpgvSQXphCiN/IUhI8H+z8uVf3Jt Ew2Q== X-Gm-Message-State: AOAM530wZRBmivl7ULLUdaE4TMNqHdB5m8kTWDt0GmLEPT4K17PI2nwl w3Nw7oE5LuQ0x/1R/jEoV0y6cegoAkhCiHJf+a/VyQ== X-Google-Smtp-Source: ABdhPJxEKVuZWPAfW/38f3J8rf2q07PHjdAxlWq+Xd2y4uywAmrvUMlgBP7TV1+Cy3Jv4Tc/UlCRz6HZ7nsT0fSF5+Q= X-Received: by 2002:a92:dcd1:: with SMTP id b17mr4651424ilr.145.1622158642858; Thu, 27 May 2021 16:37:22 -0700 (PDT) MIME-Version: 1.0 References: <20210527190453.1259020-1-pcc@google.com> In-Reply-To: From: Peter Collingbourne Date: Thu, 27 May 2021 16:37:11 -0700 Message-ID: Subject: Re: [PATCH v4] mm: improve mprotect(R|W) efficiency on pages referenced once To: Peter Xu Cc: Andrew Morton , Kostya Kortchinsky , Evgenii Stepanov , Andrea Arcangeli , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=RwIrJsAK; spf=pass (imf18.hostedemail.com: domain of pcc@google.com designates 209.85.166.171 as permitted sender) smtp.mailfrom=pcc@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1816E2000AFE X-Stat-Signature: q68bk1bnynmiws61cjh3j13fjnekps4n X-HE-Tag: 1622158635-331114 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 27, 2021 at 2:41 PM Peter Xu wrote: > > Peter, > > On Thu, May 27, 2021 at 12:04:53PM -0700, Peter Collingbourne wrote: > > [...] > > > +static bool may_avoid_write_fault(pte_t pte, struct vm_area_struct *vma, > > + unsigned long cp_flags) > > +{ > > + if (!(cp_flags & MM_CP_DIRTY_ACCT)) { > > + if (!(vma_is_anonymous(vma) && (vma->vm_flags & VM_WRITE))) > > + return false; > > + > > + if (page_count(pte_page(pte)) != 1) > > + return false; > > + } > > Can we make MM_CP_DIRTY_ACCT still in charge? IIUC that won't affect your use > case, something like: > > /* Never apply trick if MM_CP_DIRTY_ACCT not set */ > if (!(cp_flags & MM_CP_DIRTY_ACCT)) > return false; > > The thing is that's really what MM_CP_DIRTY_ACCT is about, imho (as its name > shows). Say, we should start to count on the dirty bit for applying the write > bit only if that flag set. With above, I think we can drop the pte_uffd_wp() > check below because uffd_wp never applies MM_CP_DIRTY_ACCT when do > change_protection(). I don't think that would work. The anonymous pages that we're interesting in optimizing are private writable pages, for which vma_wants_writenotify(vma, vma->vm_page_prot) would return false (and thus MM_CP_DIRTY_ACCT would not be set, and thus your code would disable the optimization), because of this code at the top of vma_wants_writenotify: /* If it was private or non-writable, the write bit is already clear */ if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED))) return 0; IIUC, dirty accountable is about whether we can always apply the optimization no matter what the ref count is, so it isn't suitable for situations where we need to check the ref count. Peter