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 E948AC433F5 for ; Sat, 21 May 2022 04:22:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686956B0072; Sat, 21 May 2022 00:22:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 636A76B0073; Sat, 21 May 2022 00:22:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 488CF6B0074; Sat, 21 May 2022 00:22:36 -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 38B626B0072 for ; Sat, 21 May 2022 00:22:36 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 019713238F for ; Sat, 21 May 2022 04:22:35 +0000 (UTC) X-FDA: 79488453870.18.4BD85FE Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf14.hostedemail.com (Postfix) with ESMTP id A6F1710001C for ; Sat, 21 May 2022 04:22:32 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id w200so9229602pfc.10 for ; Fri, 20 May 2022 21:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=ikfQc/ZOG7EJokBAFYccHiaAA1f4v5zShuvB/Kv0HFo=; b=S8c1LgySUO1SkmryhkzPJ3RvfXMRba+mg9/9xI+hvcBVKrUQPLH0gTxcsz3RvmzOnF y9jwVOkN/aw7fivKVtZbStb4mmKayCfLzWRtRtdPh8hwcbU+9RsBbGpxB+qlFE8pxDNa NwY+1oDT0JXMwIOwUDk3yOJ9e/nTEjM7E6dYJUQ9SQ1GV6lUklSRidG7NudQrGcopR95 Xc5rez12atmEBrQ1JxDZNFIBOHNDHc0zirX+s9pRTZKxA79r3lkaz7luO2UV42cNTOLv TIslk8+TY0UGEJOLY3ZFl6fGB7dexSWc9qPbzu3OVTqAM+vgney4Rf78y4GNZhZ30UU/ SvZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=ikfQc/ZOG7EJokBAFYccHiaAA1f4v5zShuvB/Kv0HFo=; b=XnMXiEpy8qxyFFhalQ0OJrJ3vrVR5G90N/P2hI+mawN/xuJxMT7rJXLVN3wdwFVUnD f0WU2yrNmxvwsk7pKeYqW8l18lqA118YNLXgqWYYcNjVbhMA3RtEstNHWXwVQ5Pn/qw3 ggR7QYJd8Xhsq/Ijy4Vv0ZbMFNClZ/o0uXK9XD5MXkAFnOq8YAQkSkQocGZNSi6gNcpV VcYeWqzhDTCJy2aJc0oCnu+jcp8agnewmLPLiQNAECcSctcR2F9geaxQiCWLgX27O+62 K3Mvmbz+Bxj3idCUaTwoRNAP0cMLelyuNyUFQnCzWmw5OCS2ey9LEr/A7moAh/HFqgnY pDCQ== X-Gm-Message-State: AOAM530WDfORdddtHkNI8vkeTzpZzOJfgf6lmTqRYFebweyVpQhjCEDs p6FUoZg2oWIQ8lHmCr0hi7c= X-Google-Smtp-Source: ABdhPJzC5CTTqYDCd+XR2nrxRX2wUxCcyZJB323gUU3hN1BZrHGT7mhZQ09MVvVpmCcLuqQFm7zHcA== X-Received: by 2002:a05:6a00:1254:b0:517:c9ef:bdaf with SMTP id u20-20020a056a00125400b00517c9efbdafmr13401028pfi.14.1653106954379; Fri, 20 May 2022 21:22:34 -0700 (PDT) Received: from strix-laptop (2001-b011-20e0-15d4-84b3-8c62-a0b8-199e.dynamic-ip6.hinet.net. [2001:b011:20e0:15d4:84b3:8c62:a0b8:199e]) by smtp.gmail.com with ESMTPSA id jb11-20020a17090b408b00b001dcf9fe5cddsm2651420pjb.38.2022.05.20.21.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 21:22:33 -0700 (PDT) Date: Sat, 21 May 2022 12:22:25 +0800 From: Chih-En Lin To: Christophe Leroy Cc: Andrew Morton , "linux-mm@kvack.org" , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Christian Brauner , "Matthew Wilcox (Oracle)" , Vlastimil Babka , William Kucharski , John Hubbard , Yunsheng Lin , Arnd Bergmann , Suren Baghdasaryan , Colin Cross , Feng Tang , "Eric W. Biederman" , Mike Rapoport , Geert Uytterhoeven , Anshuman Khandual , "Aneesh Kumar K.V" , Daniel Axtens , Jonathan Marek , Pasha Tatashin , Peter Xu , Andrea Arcangeli , Thomas Gleixner , Andy Lutomirski , Sebastian Andrzej Siewior , Fenghua Yu , David Hildenbrand , "linux-kernel@vger.kernel.org" , Kaiyang Zhao , Huichun Feng , Jim Huang Subject: Re: [RFC PATCH 5/6] mm, pgtable: Add the reference counter for COW PTE Message-ID: <20220521042225.GB1508515@strix-laptop> References: <20220519183127.3909598-1-shiyn.lin@gmail.com> <20220519183127.3909598-6-shiyn.lin@gmail.com> <3ac4823b-8f44-c2d8-e550-7d3abf49a87e@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3ac4823b-8f44-c2d8-e550-7d3abf49a87e@csgroup.eu> X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A6F1710001C X-Stat-Signature: ziwzmqk1nninzrbyyzr9573oejzt6ydc Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=S8c1LgyS; spf=pass (imf14.hostedemail.com: domain of shiyn.lin@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=shiyn.lin@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1653106952-529086 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 Fri, May 20, 2022 at 02:30:29PM +0000, Christophe Leroy wrote: > > > Le 19/05/2022 à 20:31, Chih-En Lin a écrit : > > Add the reference counter cow_pgtable_refcount to maintain the number > > of process references to COW PTE. Before decreasing the reference > > count, it will check whether the counter is one or not for reusing > > COW PTE when the counter is one. > > > > Signed-off-by: Chih-En Lin > > --- > > include/linux/mm.h | 1 + > > include/linux/mm_types.h | 1 + > > include/linux/pgtable.h | 27 +++++++++++++++++++++++++++ > > mm/memory.c | 1 + > > 4 files changed, 30 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 221926a3d818..e48bb3fbc33c 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2329,6 +2329,7 @@ static inline bool pgtable_pte_page_ctor(struct page *page) > > __SetPageTable(page); > > inc_lruvec_page_state(page, NR_PAGETABLE); > > page->cow_pte_owner = NULL; > > + atomic_set(&page->cow_pgtable_refcount, 1); > > return true; > > } > > > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > > index 5dcbd7f6c361..984d81e47d53 100644 > > --- a/include/linux/mm_types.h > > +++ b/include/linux/mm_types.h > > @@ -221,6 +221,7 @@ struct page { > > #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS > > int _last_cpupid; > > #endif > > + atomic_t cow_pgtable_refcount; /* COW page table */ > > pmd_t *cow_pte_owner; /* cow pte: pmd */ > > } _struct_page_alignment; > > > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > > index faca57af332e..33c01fec7b92 100644 > > --- a/include/linux/pgtable.h > > +++ b/include/linux/pgtable.h > > @@ -604,6 +604,33 @@ static inline bool cow_pte_owner_is_same(pmd_t *pmd, pmd_t *owner) > > true : false; > > } > > > > +extern void cow_pte_fallback(struct vm_area_struct *vma, pmd_t *pmd, > > + unsigned long addr); > > 'extern' keyword is pointless for fonction prototypes. No new ones > should added. I see. It totally does not need the extern to the non-static function. > > + > > +static inline int pmd_get_pte(pmd_t *pmd) > > +{ > > + return atomic_inc_return(&pmd_page(*pmd)->cow_pgtable_refcount); > > +} > > + > > +/* If the COW PTE page->cow_pgtable_refcount is 1, instead of decreasing the > > + * counter, clear write protection of the corresponding PMD entry and reset > > + * the COW PTE owner to reuse the table. > > + */ > > +static inline int pmd_put_pte(struct vm_area_struct *vma, pmd_t *pmd, > > + unsigned long addr) > > +{ > > + if (!atomic_add_unless(&pmd_page(*pmd)->cow_pgtable_refcount, -1, 1)) { > > + cow_pte_fallback(vma, pmd, addr); > > + return 1; > > + } > > + return 0; > > I would do something more flat by reverting the test: > > { > if (atomic_add_unless(&pmd_page(*pmd)->cow_pgtable_refcount, -1, 1)) > return 0; > > cow_pte_fallback(vma, pmd, addr); > return 1; > } > Thanks!