Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp854072rwb; Wed, 26 Jul 2023 04:07:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyPRng6EMUwqmTKhbXELkJNVcuVAV9fzPHwuRTkRj+MqGmnobL0KfcvMdrMBJBl+0nurj+ X-Received: by 2002:a05:6a00:1907:b0:63a:ea82:b7b7 with SMTP id y7-20020a056a00190700b0063aea82b7b7mr2184582pfi.28.1690369672249; Wed, 26 Jul 2023 04:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690369672; cv=none; d=google.com; s=arc-20160816; b=h2nY4EqbAZw4K1UTDV/7zxT1ZML9RLZqtU4FYsp1Nkw+tKzUhvUAW8JLiY3x7qKtwx 0OsceD2Sy4JbOii6Sd3k7iE/O0cdX8WzlxRix4RbBw5sNQFivck3uH8Of7gNf2WYsa12 v9Jjatt+hPeVBKpLXXj3RXTdhI/YBc2HYh80rszwGgEr/UhFvDZtYvMjuxg+GtWmdlHu wxBAQT7jIGyIHabnRPQuZRmbmkofeyHnBKH0HaOqKRJ0I/HlPSz5BnQePU5uztCLnNYz 9iVhx1GC8Jeeed7goeftA9yS+2jkNoHJ8BHWv3UTN3GFI/jV4VCAJjwSflpsxhIUk+Ey 4j+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=P8ft9n3i6LFq7DQLCMNj+awnrZC8BqgiGOJGw+Gf8+8=; fh=7mShmVuH9suBfBzgvZMyGTZzqI3OVCsEZy4ihinIHw8=; b=tNdFWsClgypG5CduA1onYf/vyV3+Huwh0YC4JfOsxSHLg19oWjeCjvQTE6morjvA89 UbC1ujoSkfQcGFv5I3+B+ukXlHo4K8XqlNU1cAxF8o53Wqb0CIwtBqBV3ghzJbV/7f7i rhzvJYZ/3dTB0POxnUIcMlrUgCgie/KlPgWnfJCNM2BvkWrGp3tXvRzFawQj5oODCtdU xLzrmAxSdiNkoNE0WZ3qmrCp+aGjaSjlvJiEQXeC9ppWzU0oyKUUDJc6qFUOqTH8gqHu Sf1pEYz4j6XDrh8okW/opFWovbTzCtNK2cWYz5a0lrnnX4CcSNAlORR1UOFoh40B0V+j Oy/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b00551bb2b99besi703685pgq.85.2023.07.26.04.07.38; Wed, 26 Jul 2023 04:07:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233756AbjGZJwl (ORCPT + 99 others); Wed, 26 Jul 2023 05:52:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbjGZJwQ (ORCPT ); Wed, 26 Jul 2023 05:52:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE3D0272A for ; Wed, 26 Jul 2023 02:52:02 -0700 (PDT) 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 31F81169C; Wed, 26 Jul 2023 02:52:45 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAB913F67D; Wed, 26 Jul 2023 02:51:59 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama Cc: Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/5] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Wed, 26 Jul 2023 10:51:42 +0100 Message-Id: <20230726095146.2826796-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230726095146.2826796-1-ryan.roberts@arm.com> References: <20230726095146.2826796-1-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for LARGE_ANON_FOLIO support, improve folio_add_new_anon_rmap() to allow a non-pmd-mappable, large folio to be passed to it. In this case, all contained pages are accounted using the order-0 folio (or base page) scheme. Reviewed-by: Yu Zhao Reviewed-by: Yin Fengwei Signed-off-by: Ryan Roberts --- mm/rmap.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 0c0d8857dfce..b3e3006738e4 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1278,31 +1278,44 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, * This means the inc-and-test can be bypassed. * The folio does not have to be locked. * - * If the folio is large, it is accounted as a THP. As the folio + * If the folio is pmd-mappable, it is accounted as a THP. As the folio * is new, it's assumed to be mapped exclusively by a single process. */ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address) { - int nr; + int nr = folio_nr_pages(folio); - VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma); + VM_BUG_ON_VMA(address < vma->vm_start || + address + (nr << PAGE_SHIFT) > vma->vm_end, vma); __folio_set_swapbacked(folio); - if (likely(!folio_test_pmd_mappable(folio))) { + if (likely(!folio_test_large(folio))) { /* increment count (starts at -1) */ atomic_set(&folio->_mapcount, 0); - nr = 1; + __page_set_anon_rmap(folio, &folio->page, vma, address, 1); + } else if (!folio_test_pmd_mappable(folio)) { + int i; + + for (i = 0; i < nr; i++) { + struct page *page = folio_page(folio, i); + + /* increment count (starts at -1) */ + atomic_set(&page->_mapcount, 0); + __page_set_anon_rmap(folio, page, vma, + address + (i << PAGE_SHIFT), 1); + } + + atomic_set(&folio->_nr_pages_mapped, nr); } else { /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0); atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED); - nr = folio_nr_pages(folio); + __page_set_anon_rmap(folio, &folio->page, vma, address, 1); __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr); } __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); - __page_set_anon_rmap(folio, &folio->page, vma, address, 1); } /** -- 2.25.1