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 6B9BFC6FD1D for ; Wed, 15 Mar 2023 16:08:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0599B6B0072; Wed, 15 Mar 2023 12:08:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F26046B0075; Wed, 15 Mar 2023 12:08:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC5E36B0078; Wed, 15 Mar 2023 12:08:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C99E36B0072 for ; Wed, 15 Mar 2023 12:08:08 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7DC26120735 for ; Wed, 15 Mar 2023 16:08:08 +0000 (UTC) X-FDA: 80571614256.04.5233B0C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 5D937180008 for ; Wed, 15 Mar 2023 16:08:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.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=1678896486; 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=Hb0GrvcH17Ql11lnwUCPY4vtOC0sDYTGNzYbTu3Ylus=; b=ipwca5hD8gE50llDj9Kpzvow5NixYi+TxZSXGhwTHMwZaFlSzAWO82KC4OXqUOO6bByYRz W0SiBHdH5UX2M/FH3HdQqt3IiAXLJ8jovBzUPh4dQDr1z9d5LQtxAC0+so680bCm/83h+L 1pqTw27sVGCRkWdMk096gCFFD8BGDJo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf24.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=1678896486; a=rsa-sha256; cv=none; b=izBHovh/EK9q/s1MOZ3oDP4V9SuAFI8da/nRimM9+vtdmnttCQF/+aWJXETdU8kTP/fLeF AFRkz7+hAKRGHavAmVb8SCz3HjQmyozmJMStJEtoJug75Z9J3Wpe2IpeyataoBatutNs94 1duc+TfV9zXShCsLSaZ+xs4TPD95sw8= 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 322B04B3; Wed, 15 Mar 2023 09:08:49 -0700 (PDT) Received: from [10.57.64.236] (unknown [10.57.64.236]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B3C7B3F67D; Wed, 15 Mar 2023 09:08:04 -0700 (PDT) Message-ID: <01071d9c-483f-2d95-87a6-e1030acaf8dd@arm.com> Date: Wed, 15 Mar 2023 16:08:03 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v4 34/36] rmap: add folio_add_file_rmap_range() Content-Language: en-US From: Ryan Roberts To: "Matthew Wilcox (Oracle)" , linux-arch@vger.kernel.org Cc: Yin Fengwei , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230315051444.3229621-1-willy@infradead.org> <20230315051444.3229621-35-willy@infradead.org> <387dc921-de2b-f244-985c-d1e6336d5909@arm.com> In-Reply-To: <387dc921-de2b-f244-985c-d1e6336d5909@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5D937180008 X-Stat-Signature: ycf1f579zbddo84z5s6psog6kwynqxcb X-HE-Tag: 1678896486-472572 X-HE-Meta: U2FsdGVkX1/CrY3mHhQcK1s+bTlOjImdX9IOje29nhWBF0HfHHUXME4+nVx6LWcoU207DtKuSEIrrcQQ9C/sPPhr1KWYfcBrGIUMkPSZrmEXwXBO3YXD1+JgiAnJkc5HqrDBgcxFu/LZ0HyunULGg4aNeqW6Ke1r/bHHLuoaTZG5azOSAXxqhGxXocI96qDBqXPB/dNu5FMfJ8wbhNtCjAbHK+BDJmXbuNC+S+F/XG2s4aIW3x0tVuW5pwGmaftkZvId5uSXJtWWu3Twqh6lmy5RuSfnfopB1zt7WGXh784qTJ+omiGz5Ph7abAiMXPA9/+Jqt4lzrlORPLZd9Zi73M77P87ZkgxOX0EsBEmKTrK1BbBOliQlytmp9fxcrx/olcoAOzymTmAkml7KncYRYZZuI0E5NgbNSid663U+ez8FylnAEgt562XwQqoO+YEyMlLbjIyRfYhRmy6D3VSrrRpJOyjJwhb5HpROw86UbYThqE3pY5ZDy36PCZ7mapoU7eohGQ12eZr6Lfg3epOJk5r7zn8exREvi765+C7CjQgwVE4akcVl5pwEkSrcmHC/2T7BH+GFidQvk7XKHDUA+KPy1b04+LxzwVd8E+CnAg26UaHHHBkZs+bpg/JOUasT+zhQN3y4eWVtItiM414IRGnOa+EzgDdnkPB7XPp+WYc/I+NTMm4QRCaDeVLuLvij7oZ0FNcg8I4eKZbEqR7kAIWT8ZfHvhKu6j/jBwdQbDlerfPsAGn3OgzApcKDdWY9Z5oDwhg6eIWTK4ax4VnQgtWKTCfKR5xJoFWajP5XK4wWLhijggq6sKPLzAUFDkb6avLJ3hCmx6rJYjxAfsQwteOeHjJKoO8P5bKQjZ+2SqfgSs2xU8yClKMipmAtslbjq1o1dylW+zVxn/3w6HGuvZGKXpiItvqSSPd5iHKloYHTOL9r4Nq91ZKBAQqqTb1nZYzflNd71nTeuW8yLC V1uWakJ1 /xQ/o7jN8+q3Sjcvn0sBfgBPJY64Ou9xkbabTH5Rl+JCjGdGYIrz03cWf4j+7QTE0T2XPxmJRGN4+DfegNY2OvBRQ2+CUryU9axBWsUAXR1146zA3y1lFFf3NFjM8AC3NOhcj3dbcLyRH0H7VZXIvHjh8IZkieYW/Vfi7uAvOiiKJApCcN18kJsgH6kYYJYPUBui7+ckf4bXQmatrBSsHR4jHg5dsCfERejUZ6AQklV4GPAsmkUFyYVo4PRx9Vqf0Fb2VSM6tQd/ewykBvmRf9sXIhMazB6NgDTBmR5L/U/P84sEsrfgACsMk26CHuuqyVFLKxuqa6sm39OourvqNYdwWfUAyMZ9KkOWc5s7sO532F9E= 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 15/03/2023 13:34, Ryan Roberts wrote: > On 15/03/2023 05:14, Matthew Wilcox (Oracle) wrote: >> From: Yin Fengwei >> >> folio_add_file_rmap_range() allows to add pte mapping to a specific >> range of file folio. Comparing to page_add_file_rmap(), it batched >> updates __lruvec_stat for large folio. >> >> Signed-off-by: Yin Fengwei >> Signed-off-by: Matthew Wilcox (Oracle) >> --- >> include/linux/rmap.h | 2 ++ >> mm/rmap.c | 60 +++++++++++++++++++++++++++++++++----------- >> 2 files changed, 48 insertions(+), 14 deletions(-) >> >> diff --git a/include/linux/rmap.h b/include/linux/rmap.h >> index b87d01660412..a3825ce81102 100644 >> --- a/include/linux/rmap.h >> +++ b/include/linux/rmap.h >> @@ -198,6 +198,8 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, >> unsigned long address); >> void page_add_file_rmap(struct page *, struct vm_area_struct *, >> bool compound); >> +void folio_add_file_rmap_range(struct folio *, struct page *, unsigned int nr, >> + struct vm_area_struct *, bool compound); >> void page_remove_rmap(struct page *, struct vm_area_struct *, >> bool compound); >> >> diff --git a/mm/rmap.c b/mm/rmap.c >> index 4898e10c569a..a91906b28835 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -1301,31 +1301,39 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, >> } >> >> /** >> - * page_add_file_rmap - add pte mapping to a file page >> - * @page: the page to add the mapping to >> + * folio_add_file_rmap_range - add pte mapping to page range of a folio >> + * @folio: The folio to add the mapping to >> + * @page: The first page to add >> + * @nr_pages: The number of pages which will be mapped >> * @vma: the vm area in which the mapping is added >> * @compound: charge the page as compound or small page >> * >> + * The page range of folio is defined by [first_page, first_page + nr_pages) >> + * >> * The caller needs to hold the pte lock. >> */ >> -void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, >> - bool compound) >> +void folio_add_file_rmap_range(struct folio *folio, struct page *page, >> + unsigned int nr_pages, struct vm_area_struct *vma, >> + bool compound) >> { >> - struct folio *folio = page_folio(page); >> atomic_t *mapped = &folio->_nr_pages_mapped; >> - int nr = 0, nr_pmdmapped = 0; >> - bool first; >> + unsigned int nr_pmdmapped = 0, first; >> + int nr = 0; >> >> - VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); >> + VM_WARN_ON_FOLIO(compound && !folio_test_pmd_mappable(folio), folio); >> >> /* Is page being mapped by PTE? Is this its first map to be added? */ >> if (likely(!compound)) { >> - first = atomic_inc_and_test(&page->_mapcount); >> - nr = first; >> - if (first && folio_test_large(folio)) { >> - nr = atomic_inc_return_relaxed(mapped); >> - nr = (nr < COMPOUND_MAPPED); >> - } >> + do { >> + first = atomic_inc_and_test(&page->_mapcount); >> + if (first && folio_test_large(folio)) { >> + first = atomic_inc_return_relaxed(mapped); >> + first = (nr < COMPOUND_MAPPED); > > This still contains the typo that Yin Fengwei spotted in the previous version: > https://lore.kernel.org/linux-mm/20230228213738.272178-1-willy@infradead.org/T/#m84673899e25bc31356093a1177941f2cc35e5da8 > > FYI, I'm seeing a perf regression of about 1% when compiling the kernel on > Ampere Altra (arm64) with this whole series on top of v6.3-rc1 (In a VM using > ext4 filesystem). Looks like instruction aborts are taking much longer and a > selection of syscalls are a bit slower. Still hunting down the root cause. Will > report once I have conclusive diagnosis. I'm sorry - I'm struggling to find the exact cause. But its spending over 2x the amount of time in the instruction abort handling code once patches 32-36 are included. Everything in the flame graph is just taking longer. Perhaps we are getting more instruction aborts somehow? I have the flamegraphs if anyone wants them - just shout and I'll email them separately. > > Thanks, > Ryan > > >> + } >> + >> + if (first) >> + nr++; >> + } while (page++, --nr_pages > 0); >> } else if (folio_test_pmd_mappable(folio)) { >> /* That test is redundant: it's for safety or to optimize out */ >> >> @@ -1354,6 +1362,30 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, >> mlock_vma_folio(folio, vma, compound); >> } >> >> +/** >> + * page_add_file_rmap - add pte mapping to a file page >> + * @page: the page to add the mapping to >> + * @vma: the vm area in which the mapping is added >> + * @compound: charge the page as compound or small page >> + * >> + * The caller needs to hold the pte lock. >> + */ >> +void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, >> + bool compound) >> +{ >> + struct folio *folio = page_folio(page); >> + unsigned int nr_pages; >> + >> + VM_WARN_ON_ONCE_PAGE(compound && !PageTransHuge(page), page); >> + >> + if (likely(!compound)) >> + nr_pages = 1; >> + else >> + nr_pages = folio_nr_pages(folio); >> + >> + folio_add_file_rmap_range(folio, page, nr_pages, vma, compound); >> +} >> + >> /** >> * page_remove_rmap - take down pte mapping from a page >> * @page: page to remove mapping from >