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 A7C35C6FD1C for ; Wed, 22 Mar 2023 07:42:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 450CB6B0078; Wed, 22 Mar 2023 03:42:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4016E6B007B; Wed, 22 Mar 2023 03:42:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C91F6B007D; Wed, 22 Mar 2023 03:42:40 -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 1E0346B0078 for ; Wed, 22 Mar 2023 03:42:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CB592A0315 for ; Wed, 22 Mar 2023 07:42:39 +0000 (UTC) X-FDA: 80595742038.08.67EBE0D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id C44F8180009 for ; Wed, 22 Mar 2023 07:42:37 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679470958; 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=KN5gMGhD0+a8/vry/z6ADUuYxJgWjfvReIoN+D3Z3GM=; b=bpBilkICE8DOzibs+uTqKM3N5iry9hbsjD6Qqi2vvYxjEpsWVRCU8hBs6fbbIF/IlT7cFm p8ZNA1nhVquVvoREC0tYdSV/IQOjcQVkCH3pk7MV2SAwOVYQ/zzatNEHGmnGg9bVgLN6ek 3LeTn226SRdHBNxqUNCdFwa3CwxkL98= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679470958; a=rsa-sha256; cv=none; b=xoJQotUDLZbizDX1jHnI7bEVNqkoSh39ho+HxuUD7K+15OQocYk0OxxQpXsSqvq4nU+gfn Z3sfbGstupdTV8q1ZoHdg/uKzZSDsmRS+Hy74UZwabG9djsR67iRJwHZ4VUwQk6QW2+Tdd 5g+jgnN3vAEHisntq3gzpIoU3Q8vyJw= 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 B1A7A4B3; Wed, 22 Mar 2023 00:43:20 -0700 (PDT) Received: from [10.57.65.162] (unknown [10.57.65.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D20143F67D; Wed, 22 Mar 2023 00:42:35 -0700 (PDT) Message-ID: <625cc49a-f632-7114-dfe4-8cdb2eba6984@arm.com> Date: Wed, 22 Mar 2023 07:42:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [RFC PATCH 4/6] mm: Implement folio_add_new_anon_rmap_range() Content-Language: en-US To: Yin Fengwei , Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org References: <20230317105802.2634004-1-ryan.roberts@arm.com> <20230317105802.2634004-5-ryan.roberts@arm.com> <2cab90ef-96e1-98ed-51c4-ce744d2e0ca0@intel.com> From: Ryan Roberts In-Reply-To: <2cab90ef-96e1-98ed-51c4-ce744d2e0ca0@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Stat-Signature: pru53t57pnzg6joapqohhhdq3aja4c43 X-Rspam-User: X-Rspamd-Queue-Id: C44F8180009 X-Rspamd-Server: rspam06 X-HE-Tag: 1679470957-140880 X-HE-Meta: U2FsdGVkX18aL8NwBy1RS2/fDBO7x5LkOBuIPmbX+5AHRzf/tjo5TSCEvXt4fexqcz77MzwhrJbydVvtniHc7M2fsQrqSOhaOWMxQMJ/ASCSfYJ63tCoEzyrH1VB4lMjahcuBkkrDUJKV926pN9lWLUa7C3SWhMTDdgwDKoWbWuStL6i6puHasB989ZNn5ihLydNZDdbZTv18Km7ohrp51U/mlI20hTFP2OsV1JbcjzchJPaH9bpA9oMIHGnTVby/jVTKH5j/So5Gcn9rfBIy4JhoTW4d5sUkyDb2g6HUG4P7v3BTrpX1hMku3YCpoxIkLOQAipTX/ZM+H44rFFFOTZId/o1UM+d+t43NoMeDUv5vS+z1i5gDshLJxJNFGmy48FI6uddcsgbIRIAwzT1Pfwof3zzLUucD6q5c9HZjo7M652q3WgFzMNR7OGk6vBwO6xuJtYSzmOF8sBydMwhi+TzmSlUL/M7oVUsrt0kc1h0378tzz5qXHLENeHJkBIq6bpXWWGgweiHiDrNzSI8GJXs7FKH2Sth1D7GZ1kY5thCmrCcQvhU5SDPWvfMj51awCqJFDQQ5hRSNlm8OP2asOIZq9e67kI18X3qnlfd0ENdWtIunAN3eQ1TF0T8z3Y6FFYvXlKM/SdRu02INI6rd/rpgAAdiBjhwuLLxijvM+GwsnsgOTY9YSbC+DS7AAvco3ojaKmtqJIGfnj6H3RA80nCZ21DWerEuTa0SFtmHnJH/uIPHMoG0xGGP9z2C1qTp2MOm+jrhPblFLS/y7UH8nK3f/u1/RH5ZAwI9Ic1oVO7wI05CbRVuoEJq5D+Ry9yncHGnfue5bwTnyol/F2ranUqYRfUwMt2bd/2jOoRY8xcHooYloq+Vvp7maKjfHOscwouqLEn4GpFVQxPw9qT2Z+6O7Z242lWVXplvqrjI3WpVO6tDozIvqDzng/7/SBWZTpCsJuLRGmNzeiCN2L puUFXgbF 0kB4uE/JRpayDgLBseSJhfzCKQOvx01kNBaUAkBRGlYOLSCqQkN1WbK0D4J+mS4DXZfj5HhmbruxtRC8BnZv4iH4M6/XJ5w/nMX5uEk8aja1YglVIxkteff0Em0SBigPefM4wzG7ldLPe3u8MniVa0QICVbIpozIYak6N/i/fsBOzw5bsVV9cZO2pP98F/ixj7Jq8TpnUu44X0sKNZ52yvk69Y0BJf1KH3KTL 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 22/03/2023 07:10, Yin Fengwei wrote: > On 3/17/23 18:58, Ryan Roberts wrote: >> Like folio_add_new_anon_rmap() but batch-rmaps all the pages belonging >> to a folio, for effciency savings. >> >> Signed-off-by: Ryan Roberts >> --- >>   include/linux/rmap.h |  2 ++ >>   mm/rmap.c            | 43 +++++++++++++++++++++++++++++++++++++++++++ >>   2 files changed, 45 insertions(+) >> >> diff --git a/include/linux/rmap.h b/include/linux/rmap.h >> index b87d01660412..d1d731650ce8 100644 >> --- a/include/linux/rmap.h >> +++ b/include/linux/rmap.h >> @@ -196,6 +196,8 @@ void page_add_new_anon_rmap(struct page *, struct >> vm_area_struct *, >>           unsigned long address); >>   void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, >>           unsigned long address); >> +void folio_add_new_anon_rmap_range(struct folio *folio, >> +        struct vm_area_struct *vma, unsigned long address); >>   void page_add_file_rmap(struct page *, struct vm_area_struct *, >>           bool compound); >>   void page_remove_rmap(struct page *, struct vm_area_struct *, >> diff --git a/mm/rmap.c b/mm/rmap.c >> index 8632e02661ac..05a0c0a700e7 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -1302,6 +1302,49 @@ void folio_add_new_anon_rmap(struct folio *folio, >> struct vm_area_struct *vma, >>       __page_set_anon_rmap(folio, &folio->page, vma, address, 1); >>   } >> >> +/** >> + * folio_add_new_anon_rmap_range - Add mapping to a new anonymous potentially >> + * large but definitely non-THP folio. >> + * @folio:      The folio to add the mapping to. >> + * @vma:        the vm area in which the mapping is added >> + * @address:    the user virtual address of the first page in the folio >> + * >> + * Like folio_add_new_anon_rmap() but must only be called for new *non-THP* >> + * folios. Like folio_add_new_anon_rmap(), the inc-and-test is bypassed and the >> + * folio does not have to be locked. All pages in the folio are individually >> + * accounted. >> + * >> + * As the folio is new, it's assumed to be mapped exclusively by a single >> + * process. >> + */ >> +void folio_add_new_anon_rmap_range(struct folio *folio, >> +            struct vm_area_struct *vma, unsigned long address) >> +{ >> +    int i; >> +    int nr = folio_nr_pages(folio); >> +    struct page *page = &folio->page; >> + >> +    VM_BUG_ON_VMA(address < vma->vm_start || >> +              address + (nr << PAGE_SHIFT) > vma->vm_end, vma); >> +    __folio_set_swapbacked(folio); >> + >> +    if (folio_test_large(folio)) { >> +        /* increment count (starts at 0) */ >> +        atomic_set(&folio->_nr_pages_mapped, nr); >> +    } >> + >> +    for (i = 0; i < nr; i++) { >> +        /* increment count (starts at -1) */ >> +        atomic_set(&page->_mapcount, 0); >> +        __page_set_anon_rmap(folio, page, vma, address, 1); > My bad. You did call it here. Yes, calling it per subpage to ensure every subpage is marked AnonExclusive. Although this does rely on calling it _first_ for the head page so that the index is set correctly. I think that all works out though. I did wonder if the order of the calls (__page_set_anon_rmap() vs __lruvec_stat_mod_folio() might matter - I've swapped them. But I haven't found any evidence that it does from reviewing the code. > > Regards > Yin, Fengwei > >> +        page++; >> +        address += PAGE_SIZE; >> +    } >> + >> +    __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); >> + >> +} >> + >>   /** >>    * page_add_file_rmap - add pte mapping to a file page >>    * @page:    the page to add the mapping to >> -- >> 2.25.1 >> >