From patchwork Sat Feb 17 02:25:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13561206 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 19898C48BEF for ; Sat, 17 Feb 2024 02:26:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BBC96B0098; Fri, 16 Feb 2024 21:25:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E99C6B009B; Fri, 16 Feb 2024 21:25:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64DD66B00A1; Fri, 16 Feb 2024 21:25:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 239F16B009E for ; Fri, 16 Feb 2024 21:25:54 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F1FF916012A for ; Sat, 17 Feb 2024 02:25:53 +0000 (UTC) X-FDA: 81799705386.11.F9E996C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 58CC720003 for ; Sat, 17 Feb 2024 02:25:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=wUK393+U; dmarc=none; spf=none (imf03.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=1708136752; 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=t5PILiViggT1JshWVG5xib00pMcFIIu0Z3GmM+yVzOI=; b=G1ZsU1ugK+Av4pHjLg5c5vopxbRgePqxPp14Ujks/g1gl7ctLGIN8aM2t+KLD2hFvr5zf/ O32lfqspgDm/QoXFY1IV35QEFNKoNxJg/YJ/ZAPPPyX+wcVSwEBWb+PRppzM1p2jtk5Bof 21H+s0YkWbeP0BXjCjfO1/jm0KbE7lM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=wUK393+U; dmarc=none; spf=none (imf03.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=1708136752; a=rsa-sha256; cv=none; b=NEFzlBl3B03wp9saXFHaKZ5Yc39RBD30ZLz4mkxqa4JndZUVvbDyiO0GsF0DFRWYAnDgGC bGwVysOdQQLOs7u9/PpNOVHYIrv7qsvEljyhHMyhlXScqdgRwU1X47MhuQhwoenCznV6qO /LR+AtvA3oY0Yqc1NJyDjmWh6hf5xyo= 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=t5PILiViggT1JshWVG5xib00pMcFIIu0Z3GmM+yVzOI=; b=wUK393+UoQ042NCda5+YFCHJp2 WIcR9OesVEaYPk0ax6Kxi7OeEuPDPbgXWaK5F1hNiemAQv05kYdQvJAelkES3IXXWhGN234V4CoC6 U7y3KB/sbt7wG/GqcUoLhXrqX7jyfYdsgxK1dUJ6mWLTelRnumX7kql/U4ZYlAbeSqz1WEwgxlkzD EzCcGgzfFJyolNQ69RFZ5fa5aPwcwG+xvkTsGBV84ZPTRUi4zuPlvVzAogRbymMpkWkmzIckktFAg 2OZtd9uRjwFgjKax7YOsGQ7KPTtqvmlVc/YUQGf5TneecGGpQqZ/2MH9feJ1g1JDkQ9qbdzTHwJPm YO4dYCzA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbAOj-00000006HDR-0ii1; Sat, 17 Feb 2024 02:25:49 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Mel Gorman Subject: [PATCH v2 11/18] mm: Free folios in a batch in shrink_folio_list() Date: Sat, 17 Feb 2024 02:25:37 +0000 Message-ID: <20240217022546.1496101-12-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240217022546.1496101-1-willy@infradead.org> References: <20240217022546.1496101-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 58CC720003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4aa9rx1mco6et5h793tymxraatsbufoj X-HE-Tag: 1708136752-179602 X-HE-Meta: U2FsdGVkX19tEsV/ImS9me+9eCLXpHUjnSnLbFwgpBGxsGXTTlMRLNaWPtxuGKxrC/wyOFh1oXDDEWWR39Sd4maEaNmaRTxmGS/9IT29APfrKIaf7zNTCnGqtGECtnMWtILjgWFqCUn93I2Ann6OLkroDjCzXh5Ql/C8O6n8NqEqGTVfq0TNJTu5kr6nQM08zEBv19PTUqVF317BAqz8iVPgQ84aSy3Ykl2t7ZL9rVd5i0D9ZvxJob1U2SOTWEtPXczdzD5oEnjKpB2sNDJ0qPukxCeXzpjPzek9bcuV0PnTtwzt16JD4SUAIHemjmOUcTh74zYfYZTpHHa/gA0oNvTACp56vq4+vgKBHXu5mPXQNs/f6CRhRH8WthCLVIP3FfzS4F9Svyr2Q5Q9gRx03c6NFpVdUPHNWSRADNOD5kvnOTUgCXGqxu9Mf+msiX//mM0b1Pg57K9RKCmoWqneOEcM0B+vsrImspj6RTrYK2c1IYHjs01AfGKpmUa68USJdtL3qM85h6eJVNaKc/wQNCfBAgp4XlegQtK+B1+RwVC+Ls/1mXUGAx9PGCW6SK2jtNHkLhSwq7jsi8n/IDuqTU9hO6XbA+yYw5FDwLA49zpR6zZLA4csDugFBlDKgyDPfdW/p8lQlK6mWic6hQyhHxLVioMOfGxqwQRYYRIJKvl7NuLw381VOYtg2AJC/xrvWSImciuwHSgSbryKXesT+IO6xNCdXaQCq7yV5vFbC9tOUsuGPCaNNKlu07THYw+cFbm2UfsC6wvbg2uqLhclRr0UHs/2AYTrStcjm8Sypcu4wJpm7NTasWyrucPnWolgYOkNRPNK8rRFKpM6lw0Yp7OjoLCgBWWvwA3VjA+HbqYBoNuNkDeoLYV5gRFtQDVQbGdDJTFJWU6sqA+8kXk6VkWmWEKZ8XxoYlQAFM1+0nmghapa98aom7ErfTxk5CMZwSGILgO/u/TNdGVKoQQ uuPpEhJi Cnj5sXPZWpKuEYSpo6dF6lqK5hflhjeH29H/t3IOptss3vbL3xgwTvADTNr7UfSFjf/J3IgYsiABT1Sm1KIOSGFaXLYkR7Og95M5ObXbo0fIqxaRJvfGGHWYSXD9gaql0QqiqZUleMeCoWqBgePu+RtAKYLktiJzkI0dRxWhKsAsSlAupqE7q2gzRhcPGjBGITOKExPFZiLyhGcF1OhxIG6V8HGnrfOOG1Pep 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: Use free_unref_page_batch() to free the folios. This may increase the number of IPIs from calling try_to_unmap_flush() more often, but that's going to be very workload-dependent. It may even reduce the number of IPIs as we now batch-free large folios instead of freeing them one at a time. Signed-off-by: Matthew Wilcox (Oracle) Cc: Mel Gorman --- mm/vmscan.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 87df3a48bdd7..e2292855f58e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1023,14 +1023,15 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, struct pglist_data *pgdat, struct scan_control *sc, struct reclaim_stat *stat, bool ignore_references) { + struct folio_batch free_folios; LIST_HEAD(ret_folios); - LIST_HEAD(free_folios); LIST_HEAD(demote_folios); unsigned int nr_reclaimed = 0; unsigned int pgactivate = 0; bool do_demote_pass; struct swap_iocb *plug = NULL; + folio_batch_init(&free_folios); memset(stat, 0, sizeof(*stat)); cond_resched(); do_demote_pass = can_demote(pgdat->node_id, sc); @@ -1429,14 +1430,11 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, */ nr_reclaimed += nr_pages; - /* - * Is there need to periodically free_folio_list? It would - * appear not as the counts should be low - */ - if (unlikely(folio_test_large(folio))) - destroy_large_folio(folio); - else - list_add(&folio->lru, &free_folios); + if (folio_batch_add(&free_folios, folio) == 0) { + mem_cgroup_uncharge_folios(&free_folios); + try_to_unmap_flush(); + free_unref_folios(&free_folios); + } continue; activate_locked_split: @@ -1500,9 +1498,9 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, pgactivate = stat->nr_activate[0] + stat->nr_activate[1]; - mem_cgroup_uncharge_list(&free_folios); + mem_cgroup_uncharge_folios(&free_folios); try_to_unmap_flush(); - free_unref_page_list(&free_folios); + free_unref_folios(&free_folios); list_splice(&ret_folios, folio_list); count_vm_events(PGACTIVATE, pgactivate);