Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp384192rwi; Mon, 31 Oct 2022 02:41:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qb6xmJRsFnv8obhBlQze0vovvdRaa6FqEmJZYl111bGzhg5xjJX0qgW0mXqPK83zX1LxD X-Received: by 2002:a05:6402:4444:b0:458:f355:ce04 with SMTP id o4-20020a056402444400b00458f355ce04mr13040439edb.422.1667209299473; Mon, 31 Oct 2022 02:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667209299; cv=none; d=google.com; s=arc-20160816; b=eyr0vAuBN+xTbDuAZq6aL5Opqf6ahmOGxu7/fbCPSsbQPDlhrWwn1YwEOPvTAXl3Em 64lizplMju4S1hVLvrHdXCAlV0qyU/PV3+Vjr2RQCROa9OI6p1sXcX6qhmc0PR9kZtam X9QU2CSloHJ8a8pXcyL+GMTsza0AUt6m6kwppplOKgjl035lHdBDAGS5zwrtGdPhuHFQ Cb1sJO8XbLrfxzO0bZoxRHS+stPa6rOUaysUmdsENr17sUYVeW+PFE8WgWJov+r1di0T 8t1g1ejYJIB/DPTHNStLLqkIGPzh9aZ0kj+XOLK/e30BY2Exiy98bvci6umG8hx20qeh Wmhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=m26dbh7SjZHwQm0vw8FQlUAYjNdiwKxLSgQsfeZ1PmE=; b=V5GM7FSympdVCMzA7zliEdiYBqrBe3srR+Uz1kpxh0vvTmohsKO1MX+bOoMFYZAVDe YLZeZ4zItg9ovLpQLAvHJbU/BvQvPKADc2/VowdqP5Sxqgf663PwtEOufbkhxqknp1Bq 4a4Uxt8hUPTfKkWxShTULtLJ7GgxV4E3xjCoy4koY8c+L4yM3cPEVaJd9k17+FTBFiLa TYLcnpj2CeJ2M0fVJpeVm3Phc8pKnLPXZfaqMCLXPiH3plp1nQU4vXiqcFWbOrJjOCvX wJJGNK6hqb0NvGF44NbD72zR3tMn+ZA9gP8V4AO62HWgv8I7H9qWbvhWP1JHXxUyJvf7 XWcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=PspoWzpz; 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 j14-20020a05640211ce00b00448b88378f8si6537485edw.359.2022.10.31.02.41.15; Mon, 31 Oct 2022 02:41:39 -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=@infradead.org header.s=casper.20170209 header.b=PspoWzpz; 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 S229876AbiJaJ3X (ORCPT + 99 others); Mon, 31 Oct 2022 05:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiJaJ3U (ORCPT ); Mon, 31 Oct 2022 05:29:20 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B9E0C74 for ; Mon, 31 Oct 2022 02:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=m26dbh7SjZHwQm0vw8FQlUAYjNdiwKxLSgQsfeZ1PmE=; b=PspoWzpzdQZwU1bDxNJlFTQCSd BmsCZ5XvRS7VcCAqXfgCqL3jdajhe8rVZieSueir12iklJ2deY2idzmQfnoQegSEWFIzp4PyjxD6u Etimo3Dz5Vb1e8tTJ/ylYS6q1rHd2vu0TLc4JqFuN4t/VaaqvF06yo0dlFF5EVvPLT+Dpvv+3VYxs iPAIgPRHoTUeQEPfkP0D/vjpTs80KtpNFjsYkO1DUuEdHjBY3aO7CwYGcCOWxIVqIZ+QOBWHTvLwz p0Zr6R9GhjokkEM1fa6qiZErP9m+8M/lXn28QEcPRV/a4zrKr68gmFOb0B8EMBYNL0ETBWVnbL/gt lXVV3x5g==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1opR6N-003YhK-Uh; Mon, 31 Oct 2022 09:29:04 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id F0A1930008D; Mon, 31 Oct 2022 10:28:57 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CD70C20FEEEC2; Mon, 31 Oct 2022 10:28:57 +0100 (CET) Date: Mon, 31 Oct 2022 10:28:57 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: Nadav Amit , 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 Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment Message-ID: References: <47678198-C502-47E1-B7C8-8A12352CDA95@gmail.com> <140B437E-B994-45B7-8DAC-E9B66885BEEF@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 On Sun, Oct 30, 2022 at 03:47:36PM -0700, Linus Torvalds wrote: > include/linux/rmap.h | 1 + > mm/memory.c | 3 ++- > mm/rmap.c | 24 ++++++++++++++++++++++++ > 3 files changed, 27 insertions(+), 1 deletion(-) > > diff --git a/include/linux/rmap.h b/include/linux/rmap.h > index bd3504d11b15..f62af001707c 100644 > --- a/include/linux/rmap.h > +++ b/include/linux/rmap.h > @@ -196,6 +196,7 @@ void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, > unsigned long address); > void page_add_file_rmap(struct page *, struct vm_area_struct *, > bool compound); > +void page_zap_pte_rmap(struct page *); > void page_remove_rmap(struct page *, struct vm_area_struct *, > bool compound); > > diff --git a/mm/memory.c b/mm/memory.c > index f88c351aecd4..c893f5ffc5a8 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1452,8 +1452,9 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > likely(!(vma->vm_flags & VM_SEQ_READ))) > mark_page_accessed(page); > } > + page_zap_pte_rmap(page); > + munlock_vma_page(page, vma, false); > rss[mm_counter(page)]--; > - page_remove_rmap(page, vma, false); > if (unlikely(page_mapcount(page) < 0)) > print_bad_pte(vma, addr, ptent, page); > if (unlikely(__tlb_remove_page(tlb, page))) { > diff --git a/mm/rmap.c b/mm/rmap.c > index 2ec925e5fa6a..28b51a31ebb0 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1412,6 +1412,30 @@ static void page_remove_anon_compound_rmap(struct page *page) > __mod_lruvec_page_state(page, NR_ANON_MAPPED, -nr); > } > > +/** > + * page_zap_pte_rmap - take down a pte mapping from a page > + * @page: page to remove mapping from > + * > + * This is the simplified form of page_remove_rmap(), that only > + * deals with last-level pages, so 'compound' is always false, > + * and the caller does 'munlock_vma_page(page, vma, compound)' > + * separately. > + * > + * This allows for a much simpler calling convention and code. > + * > + * The caller holds the pte lock. > + */ > +void page_zap_pte_rmap(struct page *page) > +{ One could consider adding something like: #ifdef USE_SPLIT_PTE_PTLOCKS lockdep_assert_held(ptlock_ptr(page)) #endif > + if (!atomic_add_negative(-1, &page->_mapcount)) > + return; > + > + lock_page_memcg(page); > + __dec_lruvec_page_state(page, > + PageAnon(page) ? NR_ANON_MAPPED : NR_FILE_MAPPED); > + unlock_page_memcg(page); > +} Took me a little while, but yes, .compound=false seems to reduce to this.