Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp2342220rwj; Sun, 30 Oct 2022 16:00:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5p7XhuY0cqjbENOjT2JT2xFTtS2pxPLVep+CTjOHxrMRlxB51tpXsCrOWV9Z7vVAEuWwg7 X-Received: by 2002:a17:906:c151:b0:78d:cdbc:9fb7 with SMTP id dp17-20020a170906c15100b0078dcdbc9fb7mr9823163ejc.688.1667170827568; Sun, 30 Oct 2022 16:00:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667170827; cv=none; d=google.com; s=arc-20160816; b=m9ObH85W/4+UkDBcd9swI/Tz0G2YIOZepbrDtEzxLtU9jma5YWL/Ji6DukT6LApzXM Vop4SCrAH3URUC3dYqBvwKcA0LE7jtX4cFPUoE5RlE8VNFa8MrkWdZ1d0vGXEdCiorCb Vq9yMOGfn9ouU7hDhAAM9AIfWWH4H5KsuwEYBfnAfNJj7BVDg4evb72jDP5VfFB1R6SM hUitog9rzxOj4GP/LG1mIyCGBGQwDWDWqSm9vvF/Baqb31glvwgDHsLU/mZMZbmb4wH7 swVSMM3RE/lNSfJ7kJofj2nnFwYLCT1aWdr2dycI1MfWd5caInwu10GRmar1EPc6evyV LPVw== 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=0uDy81JIlS00RxkvQyiXflyESZuBwGjhJsGtrADkh88=; b=vmcNzoc0ntxjnKZFFe+tWKcaGwPOPYGgz1Qyg/1iHlMrMQMktwf03WDAJ4W+Y87oqy KnM4Sy0RY3a58nMWip7gzSHQYocUNGXls687v3xGORY5Ui6rQSNTVv+xUS4ErobysgtR 8Pe0Zr3ByUvrliCVZQ8UfFipVovuOosTIf+ZaTOSDZDUYiWwv0eNz0ULp9UgsvOsmu3b /8w4fD5zrSXmu3CGZ2zUj/rvcPGx7FmYgPcJFi3w/GET1YliUq0z4uXrVUHeDcpqAm8I wTsLV5A6LGi3lo9KU6uWjZdFPj61CNIzb96aCCwOHMqhYeyKD7lgCQeAZgYLJr83xBSE emVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZDYCyZPK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga35-20020a1709070c2300b007832270e889si6036188ejc.90.2022.10.30.16.00.02; Sun, 30 Oct 2022 16:00:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZDYCyZPK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbiJ3Wr6 (ORCPT + 99 others); Sun, 30 Oct 2022 18:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiJ3Wr4 (ORCPT ); Sun, 30 Oct 2022 18:47:56 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7B2A1A2 for ; Sun, 30 Oct 2022 15:47:55 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id e15so7436844qvo.4 for ; Sun, 30 Oct 2022 15:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0uDy81JIlS00RxkvQyiXflyESZuBwGjhJsGtrADkh88=; b=ZDYCyZPKiuisYOnqKd9OOo9aCSgQziltL5JGmc+Yx9XO8F9okoDzTYioyCovhztVt+ PsxdYcEJyWI5ZBpFAkO0NlLVfqbGaYA4r27U5/8YtEPl0MusWmkjMKRs8a3f4GW4tXgY BDV6rPkuC8OsTHNGE8Dtujn+3ANJvpOxd6Xog= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0uDy81JIlS00RxkvQyiXflyESZuBwGjhJsGtrADkh88=; b=j9hzNAutzVAV61skkMSrhWKGOaChyWjRVnQJ/ySUksxKsVyEXbme84hEVPYn1UNIuY RuZxd9v73IldorSwozt+ADnUdiWA92u7uWKeFgtdRCXQCyMFZKHioNwxaJCKFU4mNrZ+ TFNKDC1waLQ41+OvZls9MjDC+7AsSyHsIa4IbK7X5LHksfxnsF5vPeX4pVerTxzc8K8X AFuRQcP0cBRLdLDzorNRj2TL6VtS4NQWxMi3h7Sk5t5pCoDsSJpRgXWNIfYWqBggOOOo rZiFggJud8fyshgPuapt47h4kPtzDNILoptxh4r/6vGjdwNZJdBIGYC7678ZBrn9p5aP Lvlw== X-Gm-Message-State: ACrzQf13xZbRX9LyoyHiNMmHup09qyx2/8XV00w31jEjmaxqp9/cpMNG FW2hIaCXVxa2BN9HVM+KNVMdSXhdJG6FbQ== X-Received: by 2002:a0c:b447:0:b0:4b3:cf2b:92f6 with SMTP id e7-20020a0cb447000000b004b3cf2b92f6mr8705863qvf.79.1667170074600; Sun, 30 Oct 2022 15:47:54 -0700 (PDT) Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com. [209.85.128.175]) by smtp.gmail.com with ESMTPSA id m15-20020a05620a24cf00b006ef0350db8asm3606426qkn.128.2022.10.30.15.47.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Oct 2022 15:47:53 -0700 (PDT) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-367cd2807f2so93991127b3.1 for ; Sun, 30 Oct 2022 15:47:52 -0700 (PDT) X-Received: by 2002:a0d:c246:0:b0:370:2d8c:81d6 with SMTP id e67-20020a0dc246000000b003702d8c81d6mr10193775ywd.112.1667170072503; Sun, 30 Oct 2022 15:47:52 -0700 (PDT) MIME-Version: 1.0 References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> <6C548A9A-3AF3-4EC1-B1E5-47A7FFBEB761@gmail.com> <47678198-C502-47E1-B7C8-8A12352CDA95@gmail.com> <140B437E-B994-45B7-8DAC-E9B66885BEEF@gmail.com> In-Reply-To: From: Linus Torvalds Date: Sun, 30 Oct 2022 15:47:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment To: Nadav Amit Cc: Peter Zijlstra , Jann Horn , John Hubbard , X86 ML , Matthew Wilcox , Andrew Morton , kernel list , Linux-MM , Andrea Arcangeli , "Kirill A . Shutemov" , jroedel@suse.de, ubizjak@gmail.com, Alistair Popple Content-Type: multipart/mixed; boundary="000000000000f406c305ec484700" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000f406c305ec484700 Content-Type: text/plain; charset="UTF-8" On Sun, Oct 30, 2022 at 11:51 AM Linus Torvalds wrote: > > We could keep the current placement of the TLB flush, to just before > we drop the page table lock. > > And we could do all the things we do in 'page_remove_rmap()' right now > *except* for the mapcount stuff. > > And only move the mapcount code to the page freeing stage. So I actually have a three-commit series to do the rmap simplification, but let me just post the end result of that series, because the end result is actually smaller than the individual commits (I did it as three incremental commits just to make it more obvious to me how to get to that end result). The three commits end up being mm: introduce simplified versions of 'page_remove_rmap()' mm: inline simpler case of page_remove_file_rmap() mm: re-unify the simplified page_zap_*_rmap() function and the end result of them is this attached patch. I'm *claiming* that the attached patch is semantically identical to what we do before it, just _hugely_ simplified. Basically, that new 'page_zap_pte_rmap()' does the same things that 'page_remove_rmap()' did, except it is limited to only last-level PTE entries (and that munlock_vma_page() has to be called separately). The simplification comes from 'compound' being false, from it always being about small pages, and from the atomic mapcount decrement having been moved outside the memcg lock, since it is independent of it. Anyway, this simplification patch basically means that the *next* step could be to just move that ipage_zap_pte_rmap()' after the TLB flush, and now it's trivial and no longer scary. I did *not* do that yet, because it still needs that "encoded_page[]" array - except now it doesn't encode the 'dirty' bit, now it would encode the 'do a page->_mapcount decrement' bit. I didn't do that part, because needed to do the rc3 release, plus I'd like to have somebody look at this introductory patch first. Linus --000000000000f406c305ec484700 Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l9vxsbj50 IGluY2x1ZGUvbGludXgvcm1hcC5oIHwgIDEgKwogbW0vbWVtb3J5LmMgICAgICAgICAgfCAgMyAr Ky0KIG1tL3JtYXAuYyAgICAgICAgICAgIHwgMjQgKysrKysrKysrKysrKysrKysrKysrKysrCiAz IGZpbGVzIGNoYW5nZWQsIDI3IGluc2VydGlvbnMoKyksIDEgZGVsZXRpb24oLSkKCmRpZmYgLS1n aXQgYS9pbmNsdWRlL2xpbnV4L3JtYXAuaCBiL2luY2x1ZGUvbGludXgvcm1hcC5oCmluZGV4I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