From mboxrd@z Thu Jan 1 00:00:00 1970 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 90E2DEE49B7 for ; Fri, 25 Aug 2023 13:59:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7799C2800C7; Fri, 25 Aug 2023 09:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7E412800C3; Fri, 25 Aug 2023 09:59:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68FCE2800BB; Fri, 25 Aug 2023 09:59:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 743AF2800BF for ; Fri, 25 Aug 2023 09:59:26 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 54079C06B3 for ; Fri, 25 Aug 2023 13:59:26 +0000 (UTC) X-FDA: 81162784332.09.0CDBF6A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 8979980013 for ; Fri, 25 Aug 2023 13:59:24 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UN5WzuQe; dmarc=none; spf=none (imf30.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=zCdiy3Qag8b4OHr2D3vhJJ/icmkUhqWPaFiKm7GSTKs=; b=OsKOJpuxaIWn/T43OIp3n0bDOCwwe2NISejhHWDBjowwoLeZBWZnlGLUc8CauSHx6ROY/t oGCD/m19WmUzQSx7vqFDTP3UHASaGpbW0hsMIuknTFF++ollNosCtFGQHHgXn21fjmN2us C8mLiXJYudw1i6b+IZjr3xvhCc5KJaE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UN5WzuQe; dmarc=none; spf=none (imf30.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=R3dNKuC/KJ39O4OIgDV3saB9wql8vnUVKnwnn5iBT1FespzfLgiVsCr+35l0dSZFRt3dAj F74Vx0LO9S0AiMRyK9rS7dhDeTPj4YI6wcSC3i6PStNkdcQQ8Vhvv4i06ClYD9iauZ/Be4 Kdnwy8MA+zXTF64J7/ONtE/LNFduY1A= 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=zCdiy3Qag8b4OHr2D3vhJJ/icmkUhqWPaFiKm7GSTKs=; b=UN5WzuQeGq8BlLoxmbwgj9IobM 4hgUtnvAJmQtyKiDuBTJGDknMAkv0Z/yWG3Mf+Fv1hL615v1el8iP9GmlZSyEULrqMhi2X970GZZE iWiJD/GoUJ+wER7fGpJRsX2xXWQLl22OOs5a/nICRSRMoFupcyAYQgW8RSRl455dIoYUAhTDkjeH8 ICWb9fAtiVCItY0P70yqqhREja01yoTKxtwHKHfNXai+U1RbKQ5uxVPUQ5rwYx2uiUkJN7+sc7TMu IPVeUxCeMqUzclUBrJrrC/MSITe/TXCxZI5c5lFz7L60of1TafNQ62d6LWUnvJ4SM5Y5cLfEc3Dn9 2LphzJug==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qZXLN-00HTQd-78; Fri, 25 Aug 2023 13:59:21 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [RFC PATCH 03/14] mm: Add free_unref_folios() Date: Fri, 25 Aug 2023 14:59:07 +0100 Message-Id: <20230825135918.4164671-4-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 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8979980013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3xtsrxpih8q5t8qobbqoq7atfkdwqo1u X-HE-Tag: 1692971964-611751 X-HE-Meta: U2FsdGVkX1/UM6QNqjdr85oG67V8U+ZglqKudfrxFtbVmKkRQ4QfqwBkMx0axluwb6Ro2SXvGAkeTeKlvOhZSR1O+laj0nUJlPlnSjy+gw6C6SPJtbCgxcnrzvk676l4GAzpiqo6Cl+r2DJ/QqLoCGO47AChAWUTtm32CK3F/196eGPtuA6BRElJYrJiKSOEnOVduK8RyxvfIaamaB6Zbecrs3hOm/88lauVicq5QC/dXTU6iGALuFyP076+tcycNQbpz+6yN9oLvemOdMODtxyNV8YpDcnvFldrSnCA6PJgYpU1oOzeePIG6XlDgUtgEx124EUzRl4D/93agu0ZlDDa2mHfIxVxL3iscDPZFv9Js0Nc2HL5hUuePsD8ZHammaarEYTQeOUxwBHaPB1vIZSFipDVBElkdm1BzWCTIZFCFPbz0nW5B8MdC5b5uBcgznM7p3+bEP4BWFNpFEcU9zQNkcSoyEMTRUIjr+3VH5DXX6iMnIOGVHH5RIPUffpFP+Dtbz/S9F8hopgNiNsyJd1FvlOjEfgVppDfkl0Sy52NdUee2WOlEpATGOWdc0JtfTAk21Lo0PWIkjpdWskwTNUGSAnD9YDfpoakASKzKPL6mW9Jpf4nEiyIOzTAXDB4LUNg2vXNTgOiN4GA6ERyNElwVcgl+AC3Rm16RvkorHsnVrTT30rozZhHVhRpmMUxAXj2QJxoQFoBsr1yb22swght+u7GDrCMYDgMNLqDN5WGZhYZszTz31WjjnRzt2KMO27rBpmk3BYPUfe5VYq5OLyOPP1VIqR7zEcSiwZE1B3BixaGirl7q79wBypnAy3Icq6/7mS8Wu5TFuaeTM/V/nYzjj6JqQCGkMf3MAmNBE1IH/Qvfu2rf3GKikaZXEEu6qF8L6rh2oRSn5Lvqxe7JoOhEA/MKGsu/BtVJChYlk0h5HVoXcpJCYJostok55JDFqMeIOEWMiClp5wmhnP A9aH7prF dMImJoNLSW9KSChzcBFeePmLlrxEjKFRQPePAj9tXbyqPhHjOweeRtLc5ot91z2q9LVBnXqAupYgPG2igwzYk44dt/bZNYVZbeP6rkVdN/b7Fe+1/2jc1AtIAQFxyt0HW3RGUS88CRlB675CbtrodinnJqvE8QVcWywh3zWLf2uOPZZJzH+/pj4q9tpyPK7UDI9qg77DM39Z2FCBYkDCVVqLk/PgKcsfIfiIsasydYF8Hul1s4d7Y5YG2cnfKV6FeXxUR 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: Iterate over a folio_batch rather than a linked list. This is easier for the CPU to prefetch and has a batch count naturally built in so we don't need to track it. Signed-off-by: Matthew Wilcox (Oracle) --- mm/internal.h | 5 +++-- mm/page_alloc.c | 59 ++++++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 7499b5ea1cf6..5c6a53371aeb 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -441,8 +441,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags); extern int user_min_free_kbytes; -extern void free_unref_page(struct page *page, unsigned int order); -extern void free_unref_page_list(struct list_head *list); +void free_unref_page(struct page *page, unsigned int order); +void free_unref_folios(struct folio_batch *fbatch); +void free_unref_page_list(struct list_head *list); extern void zone_pcp_reset(struct zone *zone); extern void zone_pcp_disable(struct zone *zone); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f1ee96fd9bef..bca5c70b5576 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -2464,57 +2465,51 @@ void free_unref_page(struct page *page, unsigned int order) } /* - * Free a list of 0-order pages + * Free a batch of 0-order pages */ -void free_unref_page_list(struct list_head *list) +void free_unref_folios(struct folio_batch *folios) { unsigned long __maybe_unused UP_flags; - struct folio *folio, *next; struct per_cpu_pages *pcp = NULL; struct zone *locked_zone = NULL; - int batch_count = 0; - int migratetype; + int i, j, migratetype; - /* Prepare pages for freeing */ - list_for_each_entry_safe(folio, next, list, lru) { + /* Prepare folios for freeing */ + 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)) { - list_del(&folio->lru); + if (!free_unref_page_prepare(&folio->page, pfn, 0)) continue; - } /* - * Free isolated pages directly to the allocator, see + * Free isolated folios directly to the allocator, see * comment in free_unref_page. */ migratetype = get_pcppage_migratetype(&folio->page); if (unlikely(is_migrate_isolate(migratetype))) { - list_del(&folio->lru); free_one_page(folio_zone(folio), &folio->page, pfn, 0, migratetype, FPI_NONE); continue; } + if (j != i) + folios->folios[j] = folio; + j++; } + folios->nr = j; - list_for_each_entry_safe(folio, next, list, lru) { + for (i = 0; i < folios->nr; i++) { + struct folio *folio = folios->folios[i]; struct zone *zone = folio_zone(folio); - list_del(&folio->lru); migratetype = get_pcppage_migratetype(&folio->page); - /* - * Either different zone requiring a different pcp lock or - * excessive lock hold times when freeing a large list of - * folios. - */ - if (zone != locked_zone || batch_count == SWAP_CLUSTER_MAX) { + /* Different zone requires a different pcp lock */ + if (zone != locked_zone) { if (pcp) { pcp_spin_unlock(pcp); pcp_trylock_finish(UP_flags); } - batch_count = 0; - /* * trylock is necessary as folios may be getting freed * from IRQ or SoftIRQ context after an IO completion. @@ -2541,13 +2536,31 @@ void free_unref_page_list(struct list_head *list) trace_mm_page_free_batched(&folio->page); free_unref_page_commit(zone, pcp, &folio->page, migratetype, 0); - batch_count++; } if (pcp) { pcp_spin_unlock(pcp); pcp_trylock_finish(UP_flags); } + folios->nr = 0; +} + +void free_unref_page_list(struct list_head *list) +{ + struct folio_batch fbatch; + + folio_batch_init(&fbatch); + while (!list_empty(list)) { + struct folio *folio = list_first_entry(list, struct folio, lru); + + list_del(&folio->lru); + if (folio_batch_add(&fbatch, folio) > 0) + continue; + free_unref_folios(&fbatch); + } + + if (fbatch.nr) + free_unref_folios(&fbatch); } /* -- 2.40.1