Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp691828pxk; Wed, 23 Sep 2020 13:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoIPl79ltlz6lYzXskXl+dI8uZevG+rI0AQOVpwpEB+4NEAhlB6n1la0vmHB/6UbCr1UA3 X-Received: by 2002:aa7:c419:: with SMTP id j25mr1119455edq.109.1600893009444; Wed, 23 Sep 2020 13:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600893009; cv=none; d=google.com; s=arc-20160816; b=0QRvnyZo+YnbEq8Y6wb7NPKHCZ2+Mm1aChRdbJOj+TVaFxQcy8EzaSLpTAebydCD5Q s6F25AKhET3mTh2mGySRm9WYdm96yEFffU+38KwuYmG2KjupDHH4P8bXxDG2QpcqbVvu SQ/HzvPW05NO/e28QgwwueOdCTjlhFNQ3AcgdUhv0aaWnyaZDEusrF/HDYcqTtgx1C4/ aMhs7WPpdlYTQj5kYvF/oAO9FbdDnwnYIqj+Y9GLLfyqwZr/TtaS9oK8xrJwkpWncGF+ a9fABVGFAWXlj8BGyRvbLFPvCxdGe9ycTk+mDgzzf3IHIfZqNE4IxZiKo4QgRT+9SyK6 O2bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kLB4DRRXoa8ewsaibQOQoUjg6wFUOgvHUlS6KwrQW+Q=; b=egQlIylPUm0n0YsKfFyeHyJa7yEyBBG/H8/18aohAvCUwppOX09kf9rRjuqLVO8qVT c80PWsgW2uUyR2ej7DJjtOEAqwuDVvQRDMUZCXdq3+NZ609VEhtiPvYbA8GUcOad3jT7 eCudNhQtz2DV1ec9bHCY9wDk9+9sCBz6XgT15woin+F+FBZBVpAHrtqP1A1yOSdDlajn yxYKKgKpVAeO/fACw9ntfWjpQf8PUzZEhJgYZodrSCOiR42gY7R1ATQAZ9FzfN5sEVSG v8QR6QWPT/71gqRO7tQ95eRLqoBu4pVcsaqYp7edU3JQdXlSI0Chm3w0w04+zod5AfAh m8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=LBRKpKsC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v26si554329eja.287.2020.09.23.13.29.44; Wed, 23 Sep 2020 13:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=LBRKpKsC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbgIWU0O (ORCPT + 99 others); Wed, 23 Sep 2020 16:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgIWU0O (ORCPT ); Wed, 23 Sep 2020 16:26:14 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A708BC0613CE for ; Wed, 23 Sep 2020 13:26:13 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id 77so1378426lfj.0 for ; Wed, 23 Sep 2020 13:26:13 -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=kLB4DRRXoa8ewsaibQOQoUjg6wFUOgvHUlS6KwrQW+Q=; b=LBRKpKsCN18FhUCT+ybewb3k/YEEHjRtd7HxGQxdBKW2iF5/B/ldqJlEJGGoY3Dvf0 BnyxMahBOLtdrW1QsvXec8yhZHZZW3OZ0PhjkAvhJ25wity4VnTPnnHOkub/MCsM8CaF uApDqbydEW7dEB4jVZdAyxGzc9jX6WFZUurAI= 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=kLB4DRRXoa8ewsaibQOQoUjg6wFUOgvHUlS6KwrQW+Q=; b=C3FO9bynftz9+WFFbUjaJRnOa8aT5zZRvTA1zegaxoHlUi0MG6d71ZIHuMqBDGAjWf J8P4VXIPRHiDvGbnhMnqlG5E733DV4GGThCzV8QISkstifTOUEEzcwm+zPf1Qwg9Yi7g E5Xqez4FoeVsLJlp6+CrOhceABFywQaRBNOAjRrscj67ZicObTT3IpLvApgDqhcSRS3h ber1EvhBdK7e+R6Da2D3WzxUC5JvdIMa/Gkwn57vslToRq14VqSA6a5hcA/imWW9Pd5+ XLeUWs1emsWFBypiRQgRZq2VPaiqb0TCTkkezIw2HVFS1t6xU1+PaLMTgBmOc1+jdKWZ FaJQ== X-Gm-Message-State: AOAM530+NLdQ3kYVjpeLWE2axW/yNgIHdIy6M0HipfnJfXti3yHjQjrz O86lIji6w3Rlu1AU6it53/8E3XwlNBxKFg== X-Received: by 2002:a19:589:: with SMTP id 131mr480879lff.229.1600892771818; Wed, 23 Sep 2020 13:26:11 -0700 (PDT) Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com. [209.85.208.177]) by smtp.gmail.com with ESMTPSA id l9sm411137lfh.285.2020.09.23.13.26.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Sep 2020 13:26:09 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id r24so770148ljm.3 for ; Wed, 23 Sep 2020 13:26:09 -0700 (PDT) X-Received: by 2002:a2e:7819:: with SMTP id t25mr459528ljc.371.1600892769057; Wed, 23 Sep 2020 13:26:09 -0700 (PDT) MIME-Version: 1.0 References: <20200921211744.24758-1-peterx@redhat.com> <20200921212028.25184-1-peterx@redhat.com> <20200922114839.GC11679@redhat.com> <20200922124013.GD11679@redhat.com> <20200922155842.GG19098@xz-x1> <20200922165216.GF11679@redhat.com> <20200922183438.GL19098@xz-x1> <20200922184359.GI11679@redhat.com> <20200923010332.GP19098@xz-x1> In-Reply-To: <20200923010332.GP19098@xz-x1> From: Linus Torvalds Date: Wed, 23 Sep 2020 13:25:52 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/5] mm: Do early cow for pinned pages during fork() for ptes To: Peter Xu Cc: Oleg Nesterov , Linux-MM , Linux Kernel Mailing List , Michal Hocko , Kirill Shutemov , Jann Horn , Kirill Tkhai , Hugh Dickins , Leon Romanovsky , Jan Kara , John Hubbard , Christoph Hellwig , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli Content-Type: multipart/mixed; boundary="000000000000d2fa5405b000e481" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000d2fa5405b000e481 Content-Type: text/plain; charset="UTF-8" On Tue, Sep 22, 2020 at 6:03 PM Peter Xu wrote: > > > If we rely on "copy_ret == COPY_MM_BREAK_COW" we can unify "again" and > > "again_break_cow", we don't need to clear ->cow_new_page, this makes the > > logic more understandable. To me at least ;) > > I see your point. I'll definitely try it out. I think I'll at least use what > you preferred above since it's actually the same as before, logically. Then > I'll consider drop the again_break_cow, as long as I'm still as confident after > I do the change on not leaking anything :). So the two patches I sent out to re-organize copy_one_pte() were literally meant to make all this mess go away. IOW, the third patch would be something (COMPLETELY UNTESTED) like the attached. I think the logic for the preallocation is fairly obvious, but it might be better to allocate a batch of pages for all I know. That said, I can't really make myself care about the performance of a fork() after you've pinned pages in it, so.. Linus --000000000000d2fa5405b000e481 Content-Type: application/octet-stream; name=patch Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kffu7k9z0 IG1tL21lbW9yeS5jIHwgMzggKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKy0tLS0tLS0K IDEgZmlsZSBjaGFuZ2VkLCAzMSBpbnNlcnRpb25zKCspLCA3IGRlbGV0aW9ucygtKQoKZGlmZiAt LWdpdCBhL21tL21lbW9yeS5jIGIvbW0vbWVtb3J5LmMKaW5kZXggZTMxNWIxZjFlZjA4Li41MjRh YTcxODM5NzEgMTAwNjQ0Ci0tLSBhL21tL21lbW9yeS5jCisrKyBiL21tL21lbW9yeS5jCkBAIC03 NzMsMTAgKzc3MywxNCBAQCBjb3B5X25vbnByZXNlbnRfcHRlKHN0cnVjdCBtbV9zdHJ1Y3QgKmRz dF9tbSwgc3RydWN0IG1tX3N0cnVjdCAqc3JjX21tLAogCXJldHVybiAwOwogfQogCi1zdGF0aWMg aW5saW5lIHZvaWQKKy8qCisgKiBUaGlzIHJldHVybnMgMCBmb3Igc3VjY2VzcywgPjAgZm9yICJz dWNjZXNzLCBhbmQgSSB1c2VkIHRoZSBwcmVhbGxvYyBwYWdlIiwKKyAqIGFuZCA8MCBmb3IgInlv dSBuZWVkIHRvIHByZWFsbG9jYXRlIGEgcGFnZSBhbmQgcmV0cnkiLgorICovCitzdGF0aWMgaW5s aW5lIGludAogY29weV9wcmVzZW50X3B0ZShzdHJ1Y3QgbW1fc3RydWN0ICpkc3RfbW0sIHN0cnVj dCBtbV9zdHJ1Y3QgKnNyY19tbSwKIAkJcHRlX3QgKmRzdF9wdGUsIHB0ZV90ICpzcmNfcHRlLCBz dHJ1Y3Qgdm1fYXJlYV9zdHJ1Y3QgKnZtYSwKLQkJdW5zaWduZWQgbG9uZyBhZGRyLCBpbnQgKnJz cykKKwkJdW5zaWduZWQgbG9uZyBhZGRyLCBpbnQgKnJzcywgc3RydWN0IHBhZ2UgKnByZWFsbG9j KQogewogCXVuc2lnbmVkIGxvbmcg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