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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53A0FFA3740 for ; Mon, 31 Oct 2022 09:29:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 912406B0071; Mon, 31 Oct 2022 05:29:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C2C86B0073; Mon, 31 Oct 2022 05:29:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 789DB6B0074; Mon, 31 Oct 2022 05:29:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4EB9C6B0071 for ; Mon, 31 Oct 2022 05:29:06 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E8DB680C15 for ; Mon, 31 Oct 2022 09:29:05 +0000 (UTC) X-FDA: 80080720650.27.23C34FC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 7F0AA40007 for ; Mon, 31 Oct 2022 09:29:04 +0000 (UTC) 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: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667208545; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m26dbh7SjZHwQm0vw8FQlUAYjNdiwKxLSgQsfeZ1PmE=; b=xCWSx+ZLGlxY0gm3JcW5EsasopXjHcy1D/tn21lt8fvYWGdSoKNa2XjykesB70F/B6ifkd 46dzloQMFy6lpRMvDz0seBykSDNPjSGoUF2e5P3a5N26T0a6dcA0Yui6XeypOzn2Krkv1b 44yqK7q0MTUJSF20RsBflxuIR/icctY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PspoWzpz; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667208545; a=rsa-sha256; cv=none; b=gnLKDUL/BozRjpIgbe81jP6Bm6SEisQv1FQ2U2vnHKxKT7YggMEI8YHWuSgRtHGrxctXcM ayKg0UBJYd0MawtybuYDIB8COG8MbpSf/doPoJvgDJfChlGaYWChngabW3RVwgThUQFwiR 1crxkUwRSiO1+QQzZkbJQPG/jTXdpJc= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7F0AA40007 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PspoWzpz; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-Stat-Signature: ns587jmk67p5sx6bxz6h9x84nzhxsyff X-Rspam-User: X-HE-Tag: 1667208544-37298 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 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.