From patchwork Tue Feb 27 17:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13574201 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 B5275C5478C for ; Tue, 27 Feb 2024 17:43:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7EF96B00EF; Tue, 27 Feb 2024 12:43:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CFBD86B00E7; Tue, 27 Feb 2024 12:43:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 581666B00EC; Tue, 27 Feb 2024 12:43:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ED02F6B00E5 for ; Tue, 27 Feb 2024 12:43:03 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A7FE5A11D9 for ; Tue, 27 Feb 2024 17:43:03 +0000 (UTC) X-FDA: 81838304646.06.A701EC5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 1DCAE14000D for ; Tue, 27 Feb 2024 17:42:59 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XIdZvzcl; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709055782; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g+JIHiaEA+ow4Xu3v6j8UgfoxcK+pXriMoQCo3/vWmc=; b=x/OZZvoDr2y5mKCEqjySmhTejtNXVhHhKQ2QSOpOwzmAA46onjempzbGmw8H6C2P6jUzep iRIxkJ/DH2PHFv5UC1ruftfYXPt0rywnsv7Y7gbhDMV0NrCA8XZ06ivjwe4YHBemCICAvj JyBUow3bUPOvylpM1KjIiWuZTCQvoT0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XIdZvzcl; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709055782; a=rsa-sha256; cv=none; b=oPO800SyOfA0jlS76L0nXRsa4Nml61QleWKopgQzW74Js/aW/j/JSWgMwGvTL9RLbLTTrA fleNONybH2AX4p2bTfhm+/3S7NHIM48+uGfqU44zTnkTX2LQU2H9RurU8lZ/2iLA1MRk6K rLwjnUD1EVBCtDcinNbGh/XSZB7sAzs= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=g+JIHiaEA+ow4Xu3v6j8UgfoxcK+pXriMoQCo3/vWmc=; b=XIdZvzclPkFmta7jCnoJjtGtPs /FvU6xUq0gn4elsefXd9Q1FqbQggaFE/zPsXlehVy/hLP9VoOh1YyTapVm4m4WCOIaU/WX4bhMuC5 gzNtENyg3WuRybX+PI/CGpfRzYUHWUTLYbfxRLnOeRvLerya8ysZSfT+7WvMFV7T90+z750sqYG3A b4MHEXbzUPsJ9fBQT7NcfJpHJWTeQ3wIetoOmdDNkq7UmpTMnZEVSRVleepgg4leblV2uybKGe/0C ayQ55C7SfcOCO4ugtmRbcoxcyECZNf8umMNJxtzF/+TrXQ70G65d85JJHX0o9a6a79yQj7yRggkmG fnJMYBOA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rf1Tm-00000002yrS-3QsR; Tue, 27 Feb 2024 17:42:58 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v3 09/18] mm: Handle large folios in free_unref_folios() Date: Tue, 27 Feb 2024 17:42:43 +0000 Message-ID: <20240227174254.710559-10-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227174254.710559-1-willy@infradead.org> References: <20240227174254.710559-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: rx8yspgz61pfksjdy49o9eifwcd78afg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1DCAE14000D X-HE-Tag: 1709055779-190555 X-HE-Meta: U2FsdGVkX1+usMfg5MoER55PGEYwB+aARee6IBVcsy/jfgtWKQxuSZ1pdPBi70kchBQ86Z4f8D2h1dSXG0ezPE4n/jcWokKJhzN72sMNNjfRwETm+/BNwA4WhRy0fmiINUbp6xc27iOhTWqVXIc6ZUZ6aoudg2YBT5+AW4nkSXYONHSy0h/Nm+qiUVkUHnsdcI51BzGGKJTn2z2fwLzeGFdWydGDYOKERWL5gkGhXj6RVHQYzG/E5BcQdF3Jb7QBDGU+t/WfdYVcZYwa1QV1IzPOBLT0y7O4EwchwN7+oyCHzgkTtMApYsQ9Jw4G1LyZ3bYQdju8QlXLuce3ZwsksMTGznbJsI/oJ28R143e+twp4MPjeHfCGt2reWD9gPKXkUJ+bsDWuHZSolTMo4l3nN3xjSl8s7jN22q5eDCBmziIIvGuX5p7viGgIxy8qdqlj14/wPBMm3fQUr3j1MzNIKBJO/HSRX6uYEISbHRpkNB5zagmWPLL1CgG42zGXUmLl+xrBb7MVPjV7f0xr2E/yl+RQIiMQgOddok26LxN2A/g/17M2IQIGZDXId1Ac4+t6mOa+7g6SwO2S5mfSpWqKhUVhf/NkG9+p3EEa+qZMv9+/etNn+nPSkRQnlYojTcRcKW/NIdixmM0uzpJJU0gugFsGJS+K1R3bdjrCXeNtEc21A9GyTVJmN5QZAnzxfNhWYY7VPVE2NoAz4JaztyI0KML+itvRMDA2zt482FhNeaUYG22tTYPpOUSjjgQqPAQyibgu/8CkheOnw+a/WOHHhr4QC44j5ovr/J96bRD6ej/AyxQPKwbrdzQxfOj7I4/pkIgHhiHeFRB+Nt3THUJBwDneJON2s29V76cjOWwzdCPLyfKhMpCL1BeX5XkHoyZQsAeqPo10skyA3fJQ75uzdBtiFILdJ5s 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: List-Subscribe: List-Unsubscribe: Call folio_undo_large_rmappable() if needed. free_unref_page_prepare() destroys the ability to call folio_order(), so stash the order in folio->private for the benefit of the second loop. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page_alloc.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ff8759a69221..aa7026d81d07 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2552,7 +2552,7 @@ void free_unref_page(struct page *page, unsigned int order) } /* - * Free a batch of 0-order pages + * Free a batch of folios */ void free_unref_folios(struct folio_batch *folios) { @@ -2565,19 +2565,25 @@ void free_unref_folios(struct folio_batch *folios) for (i = 0, j = 0; i < folios->nr; i++) { struct folio *folio = folios->folios[i]; unsigned long pfn = folio_pfn(folio); - if (!free_unref_page_prepare(&folio->page, pfn, 0)) + unsigned int order = folio_order(folio); + + if (order > 0 && folio_test_large_rmappable(folio)) + folio_undo_large_rmappable(folio); + if (!free_unref_page_prepare(&folio->page, pfn, order)) continue; /* - * Free isolated folios directly to the allocator, see - * comment in free_unref_page. + * Free isolated folios and orders not handled on the PCP + * directly to the allocator, see comment in free_unref_page. */ migratetype = get_pcppage_migratetype(&folio->page); - if (unlikely(is_migrate_isolate(migratetype))) { + if (!pcp_allowed_order(order) || + is_migrate_isolate(migratetype)) { free_one_page(folio_zone(folio), &folio->page, pfn, - 0, migratetype, FPI_NONE); + order, migratetype, FPI_NONE); continue; } + folio->private = (void *)(unsigned long)order; if (j != i) folios->folios[j] = folio; j++; @@ -2587,7 +2593,9 @@ void free_unref_folios(struct folio_batch *folios) for (i = 0; i < folios->nr; i++) { struct folio *folio = folios->folios[i]; struct zone *zone = folio_zone(folio); + unsigned int order = (unsigned long)folio->private; + folio->private = NULL; migratetype = get_pcppage_migratetype(&folio->page); /* Different zone requires a different pcp lock */ @@ -2606,7 +2614,7 @@ void free_unref_folios(struct folio_batch *folios) if (unlikely(!pcp)) { pcp_trylock_finish(UP_flags); free_one_page(zone, &folio->page, - folio_pfn(folio), 0, + folio_pfn(folio), order, migratetype, FPI_NONE); locked_zone = NULL; continue; @@ -2622,7 +2630,8 @@ void free_unref_folios(struct folio_batch *folios) migratetype = MIGRATE_MOVABLE; trace_mm_page_free_batched(&folio->page); - free_unref_page_commit(zone, pcp, &folio->page, migratetype, 0); + free_unref_page_commit(zone, pcp, &folio->page, migratetype, + order); } if (pcp) {