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 9D6B4C0015E for ; Wed, 26 Jul 2023 06:42:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20B148D0001; Wed, 26 Jul 2023 02:42:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BAC86B0074; Wed, 26 Jul 2023 02:42:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 083138D0001; Wed, 26 Jul 2023 02:42:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EA78A6B0071 for ; Wed, 26 Jul 2023 02:42:34 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A912B1A010F for ; Wed, 26 Jul 2023 06:42:34 +0000 (UTC) X-FDA: 81052819428.04.6CDBD41 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 91DB91C0003 for ; Wed, 26 Jul 2023 06:42:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690353753; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oGKah+zZpY7eMBG6ew35+6MeM0tgLOYKjMmq066ah3o=; b=Jq08hLMnDimm6QC8MYSY9hPTcgXHrq+0pTLzqop+ZFIMLeomZmIjKZLlqEOnr1c8N3T0Fs BnhJC88Il3eihfIKJvhs2jaqtJ3l2aFnB4ES6/vxf/MIUCJngBhF5XxAOsvdzFxDPK8kcU 59VxDnYMjucv6Pmw2yfnjcGS6r0oBQI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690353753; a=rsa-sha256; cv=none; b=KUTdSDEYmDJmaLx5FoexyvyOD5srPrTiLf+j0ZFs52uagYmA15ADtg8cQifuC6fzMXr855 /MdsONY5F+aClhBZgTux5DakV8vuVGQzRS5z0gM3CljBi85ETvYnftg++JNKdfD1nqcQdh p8sY1groijI3+JmVeUvmAhMBlcyoOx4= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3BDEF11FB; Tue, 25 Jul 2023 23:43:14 -0700 (PDT) Received: from [10.57.77.6] (unknown [10.57.77.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3FB0B3F5A1; Tue, 25 Jul 2023 23:42:28 -0700 (PDT) Message-ID: <4ae1b75e-8e9b-c4f5-a50c-9fbeca245cee@arm.com> Date: Wed, 26 Jul 2023 07:42:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v3 2/3] mm: Implement folio_remove_rmap_range() To: Yu Zhao , Matthew Wilcox Cc: Andrew Morton , Yin Fengwei , David Hildenbrand , Yang Shi , "Huang, Ying" , Zi Yan , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230720112955.643283-1-ryan.roberts@arm.com> <20230720112955.643283-3-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 91DB91C0003 X-Stat-Signature: ddpszd4ym414hfeh6hi5g6r35tkituwh X-HE-Tag: 1690353752-896764 X-HE-Meta: U2FsdGVkX1+nOuXF4VWSE1j6Obm+G9IRfDY6NnXx029s1i1DuGOxhJgq3ek9bbha/OhAn3lrMbpumYc3+Zl9lrP0l2ET5FdoX/8CqPa+JYS3RCBvLpH2TTn0xUzxT76R17aZjPI+jzPaNBV9cv51ScIS4fcg0PvbnkgUC2+bwXYGoJlCIpQqMA0TznnrP80dn9ASkL88Po4zQ3Eoy2EEb/kRoFcRSlYTdzlngA6sBf5cegKEwk0f+uwVJuX9R4MmwiHBey72q6MRnJ69XRkbdQ4OSsRBTb8eR+OaEpNKDjYM1GDVOROFHSh6GPmkKKy4fjfbBEVrKwox0kIdN63GuvGiA2T9A+36B/dhrpjLvdgvmRj8iaj+qBNg9nRHhrEzAAqiaQsyZJrMdEjTIJIT7oChlDH1ZYaiHTD9uHMbGXIo6unMMGnHodmoRO31gzSyXD1gNTmuQJYw5MqEoxlyccS7FBdgCMvhTrd6Y2bMqMwdCqUpUCeF6Z44F4X8oeLikMvt+ghXML//kskkkki3Ht9zF5XKMgVHH1rUHiDh1dbty97rK0aiNbWcgf4BlyHTBplCqb+cFM60WZJ8BZtRGf49nVzJV9nEw7CWpgSIQK0gDBUDsqOnUKK0KpwxDKMssGae6081RaLoUyCblFW3PgqD1gDzFHrwhNTP85itJg43gtqmVe/3o1/6Mh7ux/gHl/gJ2CnuEOWWJwKJt56FBfP8ctWoZa9+V7VvlvwoDmsyWML2uuLYIYnwXFtcifRUxXXWkJNLFTOtzeR2QvlpsLAahyW97sn2U1oCwKYEes832lIv18f8abSHK5NqKJWBlLzsXoMmeQeozNNi2/1WBJJZsNvUqhUGfTNWUfLPCjyhBmWK61wOVnN0LnYaj547U7pRuBJg3vxWi7oV/2LJq4wR5zAI8fsAPdKwPxvBxU68EvE67bZzLxUWZ9JDtJ4uWuGzaLdbD9gDfPUL424 rD9JLQi7 ofSgL3dU1ZZoHLe7qVFswevZ8gazO0LqZJNBEqQJ4VNnU7PoTFHCbao+iU5YgYh6mGnox+F7HfP1LECpRyHi5R7fiBmdlbugD8KH4rkK5Y2pscroHljDepOO1R1XZRsVOd83NufWhiz6PG1USeytHienG45OJe7mChVnLpWEH8ugbNYKM1ZMryGsPu7fDZ8WLDgSfPqqUwILOlMwBwiHONbq6hA== 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 26/07/2023 06:53, Yu Zhao wrote: > On Thu, Jul 20, 2023 at 5:30 AM Ryan Roberts wrote: >> >> Like page_remove_rmap() but batch-removes the rmap for a range of pages >> belonging to a folio. This can provide a small speedup due to less >> manipuation of the various counters. But more crucially, if removing the >> rmap for all pages of a folio in a batch, there is no need to >> (spuriously) add it to the deferred split list, which saves significant >> cost when there is contention for the split queue lock. >> >> All contained pages are accounted using the order-0 folio (or base page) >> scheme. >> >> page_remove_rmap() is refactored so that it forwards to >> folio_remove_rmap_range() for !compound cases, and both functions now >> share a common epilogue function. The intention here is to avoid >> duplication of code. >> >> Signed-off-by: Ryan Roberts >> --- >> include/linux/rmap.h | 2 + >> mm/rmap.c | 125 ++++++++++++++++++++++++++++++++----------- >> 2 files changed, 97 insertions(+), 30 deletions(-) >> >> diff --git a/include/linux/rmap.h b/include/linux/rmap.h >> index b87d01660412..f578975c12c0 100644 >> --- a/include/linux/rmap.h >> +++ b/include/linux/rmap.h >> @@ -200,6 +200,8 @@ void page_add_file_rmap(struct page *, struct vm_area_struct *, >> bool compound); >> void page_remove_rmap(struct page *, struct vm_area_struct *, >> bool compound); >> +void folio_remove_rmap_range(struct folio *folio, struct page *page, >> + int nr, struct vm_area_struct *vma); > > I prefer folio_remove_rmap_range(page, nr, vma). Passing both the > folio and the starting page seems redundant to me. I prefer to pass folio explicitly because it makes it clear that all pages in the range must belong to the same folio. > > Matthew, is there a convention (function names, parameters, etc.) for > operations on a range of pages within a folio? > > And regarding the refactor, what I have in mind is that > folio_remove_rmap_range() is the core API and page_remove_rmap() is > just a wrapper around it, i.e., folio_remove_rmap_range(page, 1, vma). I tried to do it that way, but the existing page_remove_rmap() also takes a 'compound' parameter; it can operate on compound, thp pages and uses the alternative accounting scheme in this case. I could add a compound parameter to folio_remove_rmap_range() but in that case the range parameters don't make sense - when compound is true we are implicitly operating on the whole folio due to the way the accounting is done. So I felt it was clearer for folio_remove_rmap_range() to deal with small page accounting only. page_remove_rmap() forwards to folio_remove_rmap_range() when compound=false and page_remove_rmap() directly deals with the thp accounting when compound=true. > > Let me post a diff later and see if it makes sense to you.