From patchwork Thu Aug 10 14:29:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 134053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp507882vqi; Thu, 10 Aug 2023 08:43:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTWekzQlmZhDou2dUFwbEYh0KfsLfI2IRIqqvVYfNKXliq7kxnd4K7MCIUd3ibGzldL6En X-Received: by 2002:a05:6512:3456:b0:4fe:cca:c6f7 with SMTP id j22-20020a056512345600b004fe0ccac6f7mr1739837lfr.48.1691682192371; Thu, 10 Aug 2023 08:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691682192; cv=none; d=google.com; s=arc-20160816; b=hYwYhxCt4GFUW+ApEsGD38OSPWUL4dsTXgWSbsW+g6qEuFnqPtWuirrEr8/PjhHu8o bxBUylDQubU82wB/bOva01W+kaFWvC9EvsTl+pBd1Mu77X3FoB2GE+5nNFrmFxzsqNoi 7f6whzuXPyZASPwLVn2oSNtWbEF8jwTyNfDdCYygfPOCVxHlUZQsaPCEisMpqoDnCUNV r3KPqPJ8FLyLLfPynrSocfjahPKhCsb9PMfIxUBDOqhLVgi+rZVyKWOrClcD+Vkj7p/8 NMgZ7KpojQVxXXLoxMYR12F4oovw/EsJLbTxVfCFn+5uSUn35XzzAvuRBEoFINfAmWab 7iYA== 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=hZn/3SZrqk4Mk6iz6WOdEWWcv8iCLvWmnIBLw6ALzj4=; fh=2S5jT4dIIqOhOs7q3j0K2DFa5C1ZmfWI8H2ybAUe/oA=; b=uxTUHySw4jyiq927YO6Cty40lPO09FjebUA3hjSKEqab9NqZf4B7xehV5KH8SS0A6V 9+w1F14wnntSOEVdFatUk56TwOkymk72bMfYpr9259VVttN6PW06tVhDUrUw0ls/8Ly+ LMcYwWvkMp5/o+9WOiu3H0OGSXGhlph2zYG1SCAr6u2v8sBsBVybe22j+jNoywIccms2 hMohsc5NWb0Y49L3hZMLuO32QMC4oQrts7frAO2i8E/Vv+VNXVFVe/6ytcBlqRPHDoAb bEd6DlF5sZf4iMAqEpA5Lp0jrRuLjZbvggnRl8llAofAEO1rIR+ejK8xPmlzVqttvrAJ AHjQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a50ec90000000b00522f060f8desi1710673edr.326.2023.08.10.08.42.41; Thu, 10 Aug 2023 08:43:12 -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 S235734AbjHJOaG (ORCPT + 99 others); Thu, 10 Aug 2023 10:30:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235726AbjHJO37 (ORCPT ); Thu, 10 Aug 2023 10:29:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49ABF26BC for ; Thu, 10 Aug 2023 07:29:58 -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 72BCB139F; Thu, 10 Aug 2023 07:30:40 -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 B5B913F64C; Thu, 10 Aug 2023 07:29:55 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" Cc: Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 2/5] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Thu, 10 Aug 2023 15:29:39 +0100 Message-Id: <20230810142942.3169679-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230810142942.3169679-1-ryan.roberts@arm.com> References: <20230810142942.3169679-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773857346406476564 X-GMAIL-MSGID: 1773857346406476564 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 769fcabc6c56..d1ff92b4bf6b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1266,31 +1266,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); } /**