Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp3785rdb; Fri, 29 Sep 2023 14:29:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9hj+yJ5KY4/PzdGlh9u04jLZAqamTWmpmxSrj9YnX8AWY4Qf7SGxBJJ1teAjFgbgnizft X-Received: by 2002:a17:902:da86:b0:1c6:bb3:29e6 with SMTP id j6-20020a170902da8600b001c60bb329e6mr5860931plx.16.1696022950431; Fri, 29 Sep 2023 14:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696022950; cv=none; d=google.com; s=arc-20160816; b=Op/M67hzU2mysRmXRtwKHjgaIVnD71QbTO3ZtcOKGU+UhFz/Qd5VuStOFAjqOXY3UA BUMbMkr/NFG0aK6WKN8tWwRHGTEOPymNLBkW/VNhbIjHdoIlfJ61U+McfpyfqdHAy5+O tgjRaxcsHscKnRd9w8bKzx8hos6iMBgaFZaZVpdgDo2Hv6bkKwLm/PJ5TjkOtVBOYH0p XFCQk4pw5Vv/8atMGsBOEvcSKKFduKnwVg8sZQ/bDak93ZNPZcr1rLmMad2UEpMe2Zj/ +ko2aleGUcwV5/PId85xHEOrGxxCQOh8U14fP/vlW6auUEp4Dec5LF98/s30pRRUwSXx /WdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=53zS0Dm+Y24f0pY+y8ab9KkCyrweRer5/VpTxifVF6w=; fh=3FSHGM+g0bdYm2W3voZbECxeiSIkISSQFew0gEiEJ88=; b=fbnXb7kRe36EvX9SX9fHV00U7PvnRa+h3qFmifFRWpkWRN6lmCpvuC0gGbvBz6qFgT FoQg3ZVQgjP69HIrrI+ccfSwvsviDaq0PDuTo2rCgw5tTz9ogjOs4isowBCeEQIDooPo U4lBU9EdL/5Hq0uHxo9GWgpo9ddPQbdve0woDfpJCcD0qOzXvkAXTN1ERrYR5tjojCyK gg3DN/EeOtiWQYCqdCB+vmN2mAWvMaChqfoalSLHp0SU9LzI6GaaK833CzL64fVkrm2q kBiqe+k9Sd2CCXcwjcB5YjA1Ii7iWwatoiIJiSwCHbxWhD1/r2LKo27jwC6ezGGcw/wA N3PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZIGeqA9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id a7-20020a170902ecc700b001c62cfff795si12093706plh.429.2023.09.29.14.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 14:29:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZIGeqA9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9B2748060478; Fri, 29 Sep 2023 06:45:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233403AbjI2Npf (ORCPT + 99 others); Fri, 29 Sep 2023 09:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbjI2Npe (ORCPT ); Fri, 29 Sep 2023 09:45:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A96A61B1 for ; Fri, 29 Sep 2023 06:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695995132; x=1727531132; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=g+gHobaCyDXuYUdTfzKXdvua62/hwJqag4HhUq9dqwI=; b=ZIGeqA9UW/g3H+vTusSAXYmQw8YfkprzaoK29QHWuCGTm2gwezIldR0x jEg53KCrY3HS4OeNzxwpLHxih2nMl8ky/nNE+PqmckbWUZgBxB8hVZJMy pAFHEnJ7mqkSDfZS8i65z1JLKTbt7VUJhTmHm/Ov6vcRBi+B1HZelinuL T58/z+oPZ7+fpA6nXY2H5/6fH/1FUgnHEnlbbwFTvdYXsu9fUp3ap5IJf 1CfKjSmhDMZcvG82zNGqmucqkSw7t/Oe6Bo+hBoAQcnls+mXvGguwie4P ioQ/fsfijJii48Q/eN+5ZC4C3sBGGxc4HqUb0SElxveZBXJ+9xhNIFMS9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10848"; a="382206430" X-IronPort-AV: E=Sophos;i="6.03,187,1694761200"; d="scan'208";a="382206430" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 06:45:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10848"; a="996934729" X-IronPort-AV: E=Sophos;i="6.03,187,1694761200"; d="scan'208";a="996934729" Received: from mziotti-mobl4.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.34.13]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 06:45:27 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id A61F81095FB; Fri, 29 Sep 2023 16:45:24 +0300 (+03) Date: Fri, 29 Sep 2023 16:45:24 +0300 From: "Kirill A. Shutemov" To: Ryan Roberts Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v6 2/9] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Message-ID: <20230929134524.wwyykrxfikhle54k@box.shutemov.name> References: <20230929114421.3761121-1-ryan.roberts@arm.com> <20230929114421.3761121-3-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230929114421.3761121-3-ryan.roberts@arm.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 29 Sep 2023 06:45:46 -0700 (PDT) On Fri, Sep 29, 2023 at 12:44:13PM +0100, Ryan Roberts wrote: > In preparation for anonymous large 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 8600bd029acf..106149690366 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); This code should work for !folio_test_large() case too, no? > } 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 > -- Kiryl Shutsemau / Kirill A. Shutemov