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=-3.9 required=3.0 tests=BAYES_00,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 1C697C4727E for ; Sun, 27 Sep 2020 00:05:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53F712388E for ; Sun, 27 Sep 2020 00:05:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="CmacqtDM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53F712388E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 71E166B005C; Sat, 26 Sep 2020 20:05:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D2E76B005D; Sat, 26 Sep 2020 20:05:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E5AB6B0068; Sat, 26 Sep 2020 20:05:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 4961C6B005C for ; Sat, 26 Sep 2020 20:05:00 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0703D1DE4 for ; Sun, 27 Sep 2020 00:05:00 +0000 (UTC) X-FDA: 77306895960.30.women88_170800027174 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id D8705180B3C83 for ; Sun, 27 Sep 2020 00:04:59 +0000 (UTC) X-HE-Tag: women88_170800027174 X-Filterd-Recvd-Size: 5451 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Sun, 27 Sep 2020 00:04:59 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id k25so5449342ljk.0 for ; Sat, 26 Sep 2020 17:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=U1OUqNTBnVCMPp1ia2uQg45U9rR6Q8tgrXbVfMePRQs=; b=CmacqtDMqmSt6zlNRn6vPCkQB5zdpAqt8v8RN0LEGgbCnEGv1D+2OztGRck+T6aaQE yycrdozsfp4ydQKjMWyOEluArt7NX0xdprQuuRUGiiFEqxpn4RtcmKRnkL4BjDLpGXdF aEKlIfuHb7kE+yxm6N6kbm9UO0f0bQBp0nJ7E= 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=U1OUqNTBnVCMPp1ia2uQg45U9rR6Q8tgrXbVfMePRQs=; b=jbeR6ATXLUlOQT5VxcNhshpj3+6L+FK/nrKD6EEhThih0jr7REnuYP/vH4cjKXYZta TkP3WN4SaFWggpfNRzCx3mse3AQxaWuTUsFF5Ye2bkuuN+N/pOqNjNsY4ZNuSXEBGMrf oICN2yNOzRg3xghqCjnmE0lBEIer/dD6djE7ruRFCgBCmgYAlJFe4IyevZ2WVkUwZjvn jtgU21pt6tpbCm1nrd+piJMWM57kJDj5IzGZmy8bpPsx/4zaWiwsgZ0e8hKKcgMGEIc4 4gsPOVSKBArCWxzqhSSwXVBg6te6UvsjW3DIg17nDWDh9ai/7tCX/ThutzaSSDwNM98R s4Vw== X-Gm-Message-State: AOAM531O2cycxB8TMMfdX+mE8A1xXtBQ0vjOrd6lFE8KzXL3jPOWoSSk JgDCrV62yljbAXHBH1cq6LN2GLnJ0qzkdw== X-Google-Smtp-Source: ABdhPJxsLA9/t5Y6E3PXyhg42pBf50vv0ILXS/yiQhv2EaXZU+bKwIPXd/mY3SCsECMqXmIWYRITTA== X-Received: by 2002:a2e:8e63:: with SMTP id t3mr2941530ljk.132.1601165097266; Sat, 26 Sep 2020 17:04:57 -0700 (PDT) Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com. [209.85.208.181]) by smtp.gmail.com with ESMTPSA id t2sm2216164lff.157.2020.09.26.17.04.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 26 Sep 2020 17:04:54 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id u21so5410856ljl.6 for ; Sat, 26 Sep 2020 17:04:54 -0700 (PDT) X-Received: by 2002:a05:651c:514:: with SMTP id o20mr3433991ljp.312.1601165094039; Sat, 26 Sep 2020 17:04:54 -0700 (PDT) MIME-Version: 1.0 References: <20200925222600.6832-1-peterx@redhat.com> <20200925222600.6832-4-peterx@redhat.com> <20200926232335.GA348793@ziepe.ca> In-Reply-To: <20200926232335.GA348793@ziepe.ca> From: Linus Torvalds Date: Sat, 26 Sep 2020 17:04:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/4] mm: Do early cow for pinned pages during fork() for ptes To: Jason Gunthorpe Cc: Peter Xu , Linux Kernel Mailing List , Linux-MM , John Hubbard , Andrew Morton , Christoph Hellwig , Yang Shi , Oleg Nesterov , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Jann Horn , Michal Hocko , Jan Kara , Andrea Arcangeli , Leon Romanovsky Content-Type: text/plain; charset="UTF-8" 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 Sat, Sep 26, 2020 at 4:23 PM Jason Gunthorpe wrote: > > Linus's version doesn't do pte_sw_mkyoung(), but looks OK to have it I don't think it matters. But I don't think it should make it young, since there's no access, but it's not like it's a big deal. > > + pte = maybe_mkwrite(pte_mkdirty(pte), new); > > maybe_mkwrite() was not in Linus's version but it is wp_page_copy(). Actually, it is in my version too, just in a different form. I did it using if (vma->vm_flags & VM_WRITE) *src_pte = pte_mkwrite(*src_pte); instead, ie avoiding the write to src_pte if it wasn't a writable vma (and I had checked that it was dirty and not done this at all if not, so no need for the mkdirty). > It seemed like mk_pte() should set the proper write > bit already from the vm_page_prot? No, vm_page_prot won't have the writable bit for a COW mapping. The write bit gets set when the write happens (which may be on the first access, of course), by the code that makes sure it's a private copy. > Perhaps this is harmless but redundant? No, the pte_mkwrite() is required in some form, whether it's that "maybe_mkwrite()" that looks at the vm flags, or in that explicit form. > > + page_add_new_anon_rmap(new_page, new, addr, false); > > + rss[mm_counter(new_page)]++; > > + set_pte_at(dst_mm, addr, dst_pte, pte); > > Linus's patch had a lru_cache_add_inactive_or_unevictable() here, like > wp_page_copy() Yeah, I do think that is needed so that we have the new page on the LRU and it gets properly evicted under memory pressure. Linus