From patchwork Fri Aug 25 13:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13365796 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 9B589C71133 for ; Fri, 25 Aug 2023 13:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11A0F2800BC; Fri, 25 Aug 2023 09:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A88D42800C1; Fri, 25 Aug 2023 09:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 698978E0015; Fri, 25 Aug 2023 09:59:26 -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 360002800BF for ; Fri, 25 Aug 2023 09:59:26 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 15472406BC for ; Fri, 25 Aug 2023 13:59:26 +0000 (UTC) X-FDA: 81162784332.15.3F35468 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 7069B1C0028 for ; Fri, 25 Aug 2023 13:59:23 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C1AIhNTd; dmarc=none; spf=none (imf20.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=1692971964; 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=n+gxEXWZCOB3pRmnNNsPASJ2gcVnzHVf7MDBK5BYIds=; b=F1laVAIiUvFFZpItVnnSjIzwtFY8RLfFVdxIZbH3pPzHNEQyVreD7sTMoFs5lY1U/NV52C zdtAU0DoDFtKoq7x5rUFYSIR78jnVrjOB/hm9/m1/nVTZSoJNsXZscODj0ekhGf0NA/YIK WxUoGmt92evJoTWGFBruqP4QUQU/Lk8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C1AIhNTd; dmarc=none; spf=none (imf20.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=1692971964; a=rsa-sha256; cv=none; b=mjQM8f3n8rqSgV6ySOMz+s2745HYxr1ojI1/M1xM8eUB2wfouB3zx58ACBnnKWBdXRSKjh TnT7M/KABvosQGl+S61Fb34kMY0d154jNx+nuC2Us0c8bmPudhGIQbWSjB6Iaj7LWdptxX y+P9IkWnHzSc8ksuL/T3+afLIUJ7ylY= 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=n+gxEXWZCOB3pRmnNNsPASJ2gcVnzHVf7MDBK5BYIds=; b=C1AIhNTdfXvn5iu7QjD5whStLg a7k16PfsvU0LPKKuuS0a6Jhdo32htVLuUBimitrmpIodEIpK6u/pb+RqtzUxbaZRf6zBE1n+bDe1D 6GgErNixDdHDxiOt84woNkcVe13OAI/fEsmd5eySQnm/HrPRr8an7qxFOWLWBxciPI+VuQ/hTpsY3 W4nxsS6ss78gx9YQ7+33GrLGbgSNEbIivS+HP2d/VBVJRuCeFpOXKvF1hT/xNUkcsLkocselsfpum 7sBINZvnRXmGR4pntZ6TomzPmHvOB3aPDJ/UfS+KPB+01zgeTXFbKVhBNj2p6TWyQcVp+E5T+d9ZK fI1VH4vw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qZXLN-00HTR8-V0; Fri, 25 Aug 2023 13:59:22 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [RFC PATCH 09/14] mm: Handle large folios in free_unref_folios() Date: Fri, 25 Aug 2023 14:59:13 +0100 Message-Id: <20230825135918.4164671-10-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230825135918.4164671-1-willy@infradead.org> References: <20230825135918.4164671-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: trjrc1mgzbszt7kqtk97rojuwwkdt9kc X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7069B1C0028 X-HE-Tag: 1692971963-953821 X-HE-Meta: U2FsdGVkX19lbElWZzgtCkQXEeYb7mlNVroZQgfblpFKwZNQxcYQhnQYRE5VEjp+3YeMYg4yUb7cBYnKPyUUAPNCLDSK6bttLhuAiZhAIvSgmOiY+g6A7RpNNS/wORUBmCa9Vq3BzUhAnE9FRDsz6MItks7dKJqN1kXXVefa1EB6lDJfHJiNgKqCajAKEeZ3yZchbcxHqk3yrsBammmQGUyeHWsSatw0kidyW6j1ca0PQRt03+dk/AEWrDRLVg2MCdE7wKGL6HoejaBsTs91s+SZYovX2h1U6Q0pgaNQCXR07lFVRNoEhhdf/nDql/DZT4wX3Mje67odRW8pCPVn8eJ9+ejRfXHSBi+b0EJJtLplFdS0cO7+bo8kHSY1GA1brTkMYFLOXwyotcvWviM0UKsmk2+eSNwqAyEz+iGYvS74TjXJrBoKSXx+o+zMdwGZ7tq/NiZtqFft9KHv4fYcsQKRDH9dKWCYeObhX4PYCYlJHIuMCHUa44/IgeWqsPlfTFbgCd0WubkXbaNLx/YDS30C3FHeQQ5NlfkZAk5fDKUap25Imm2hAsDEzdaPnoV/witf27wrZxgQoD7h3QfKDi66I38fzCNG4bf/txk0TZVrR9mQzfPLbLPBJQ5MkvRpcqshhYG4Ys50PfUORJ3EvJizBzb6Vlj8c9xHMr4J6uRLqUCCHbxP7ol5+AVp9E/6fBUcQq6qK4jomemz0rUCoHoPErebzQdQiwgBCuYluVyOGFd+9r3ECOYj924ZwhSiJzmkVFWBa3yW1r+4NmcPzAKYaNhbgqqyRzszlv360xJmmqBiSsFaFpEzF/K+86d04o2nmgXQIv3lou83GxCQ03frHXONEjkRkFwAYYbM0z3+mfZW+SFRbq3w5jlNY+jxAgZY5lpTnqxxmQP9TQ3owTgKAV5nVeLmkHAC03vP/MtLimZOLj/35D2+lIkrLZsPXx7/eveLetbVJxLXB3z VZ6GYw7X mQhIRZ7YZE0luc74pSO/jK+Kk30b0YGuzHs2wE6+12hBy4jijspCInEYWeby1KTpjn7VGHlQX1RZYLHP8VBSqd8VylmToWP4Rf0VDoJYHsqDRJk4qi5t8VF3B7RZ9/C7MAYI0aZ485XeZz7vmSbIujWI97ERLuxVuSHD3aCL+Z0Dmf29j6A9YUfCdEIuLhWlwJ2OZRPIaaXAQq4R92aUFgn4kBAMo/KWkbycy 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: 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bca5c70b5576..e586d17fb7f2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2465,7 +2465,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) { @@ -2478,7 +2478,11 @@ 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; /* @@ -2486,11 +2490,13 @@ void free_unref_folios(struct folio_batch *folios) * comment in free_unref_page. */ migratetype = get_pcppage_migratetype(&folio->page); - if (unlikely(is_migrate_isolate(migratetype))) { + if (order > PAGE_ALLOC_COSTLY_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++; @@ -2500,7 +2506,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 */ @@ -2519,7 +2527,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; @@ -2535,7 +2543,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) {