From patchwork Wed Aug 30 18:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13370637 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 E0DF5C83F17 for ; Wed, 30 Aug 2023 18:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E383440180; Wed, 30 Aug 2023 14:50:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96BC2440178; Wed, 30 Aug 2023 14:50:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BD04440180; Wed, 30 Aug 2023 14:50:52 -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 5F935440178 for ; Wed, 30 Aug 2023 14:50:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1BBAE80368 for ; Wed, 30 Aug 2023 18:50:52 +0000 (UTC) X-FDA: 81181662744.09.34F11ED Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 748C0C0025 for ; Wed, 30 Aug 2023 18:50:50 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RkUUtf2n; dmarc=none; spf=none (imf10.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=1693421450; a=rsa-sha256; cv=none; b=tXnr37uzJ7MOI5frjnKvzlaViI05uT5thqxIFnyuEYlX+A/37zTcxm6qm9GFrfQQXidfHp r9d8Ahae6rGWvmceFchr7UrH2tpXoMxhUSyTP6LzCyc+uZAwbSzumqrQkzQq4DzeFJ2//1 zP7SUbFbrVT8mdxTpRTaBpKaWiz1Ml8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RkUUtf2n; dmarc=none; spf=none (imf10.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=1693421450; 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=7ZjXrp9mEKX41BRmyGl7l73x/r4SiJJJz5MiqUGm6og=; b=QrrA9kLj5Ws9MTVn+azBTD7mwwohzfxahQePYLmvVagIN3aj7oDZLHfXVh9oKxyY6X7s5S Qvs8SohkiE/n0az9X4AKqTyHWtZlvbPTBk2nVZWDFMBhc/mHxi7VAgDKOEW5NkMKlDOteq 5fSMNJPVkrAECJ7GBns4Mo7Hvy6K66Y= 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=7ZjXrp9mEKX41BRmyGl7l73x/r4SiJJJz5MiqUGm6og=; b=RkUUtf2nd9Fdmf0xmO2wp9xQW1 gdb6MnIk0m7hwPxCu6+AgwgUWpDXJiXU7ZPdnCvi9HinXLwWc2Sw3KWnNkXdwFER7TxyirXB5MU+C zOp4cAytg4X2ubcNJlSG2j22Ymu9WN9i1p7UnDZanPqqoruJ7n2skQGYhBr7g3buHWr85h6XudekH bgBvUUKvIvIuEaezMlC704RpwJldjYyKswDKKCMNIqXlOAUlEs0XDOBUMVxq8za/f45X9Wf4IiDrf 7Mx2BQq8AXZOe548yNG/2t3LGUuy9YeSA6VouaBNAvFulw5Rebr7JJ9jPcWjpSz1+pH8nnGcJKHEp /QurJKjg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qbQH6-00ENfU-U8; Wed, 30 Aug 2023 18:50:44 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Ryan Roberts Subject: [RFC PATCH 15/18] mm: Convert free_pages_and_swap_cache() to use folios_put() Date: Wed, 30 Aug 2023 19:50:38 +0100 Message-Id: <20230830185041.3427464-1-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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 748C0C0025 X-Stat-Signature: 5zunkz71xy4t9y5zi6du3199pxyiknf3 X-HE-Tag: 1693421450-828471 X-HE-Meta: U2FsdGVkX1/4wmuxmp6VlDss0OOvEC1t7YzDWBUy/09Uif0srNozeo2cNTvJsFh4GEdabX+kQzxmZzaDKmsP1ymzU9AZKEwlZwWyJXoRKfbYqxi8zUG6MgZtTNlbfm5Cdy1IJNS6zkMc+g0SLq+FsVzOIWiAyhIn75ZT5I8rkEDGuM+DKsVQW8+a45aV2zwRto7TFu16ZiGBpHgLH7p3BV4jZSQeIfhvCKhQ7jOdpdZw4ds4CtzJzgv3cV+d02AHL160x4m4eqHOEWb8ofx1ZR//TpZxLArGUSu+Q0iiouAs48yiA4HEInJAsdYmNRzykNzMI8V6mrku4ar9t/Y6qTi2MyKPnWPDCWexOsdJCtw5zY5z7hjuGL3w1iTAhCRB0Q4/zmIrsnNdukGY8lQCHYB310or2KRQ1mRDhfW1PEpzBJ70QGkzHzYjwN0tF/vQe80ZxhYCIajJChGVRJRUrQ2iNeRRQytzCQi2Vnlr1igkcHRcrzY7vkB3d/cpzBR8wUW/SmGpZyF2Z2YyR5I43Yp/owiQ8kaoofmucsJaHeDM9OUz//V4jCCSB3ZG89JtC9B80DoDMRpCCXYcrut9qJySJ5og1X8ja621WCs3eltZ+ReG+cOVaJU5oG9MmvG+oSZxZUhxG6/eFYQzxbUSpeEqfedNdX0BuL6icK6oGSZU2k5KQdOGHUEp9Ze3ba7TmkbGKuxQk2Kz/Auy/SPo7VBxcwVMWmAwSuFf4+NrId21sh7KlkPgkp+pPuQLQ5PKZDVKICBl8/GKXlmFr9ZWZ+oneMjv9SYTY0k6WAR2/d7yEz9768PvouH6wNKIyoz4BqwtCI6sXVBepiIY82ZUj0trGguzGyGmLSOfm1yqN7ZNrr6TJL9eknfPG7CtEUM8rtH1m8QuCVuBp2jkzlkvZe9oE8DbIDrg2Gr1AbBVPESIZynDzomDgH6ur8Tig/sgaxgMAEL+5MYCrGFD1vA CvRI58px q6A5GC7aPAZA42MdSBpu/wX8ZggvVvBekstJTCHtB8Asrn3xkJgl5kLhUAqNBtmwVW4jR2UazCuSCnMGRF2a99Q7rH6eqQnBwiLjZLbkl8CJAYCKT9c8b849ibBdnbWjUGiFXtQvHxiS4dCGIBBcGOo+/ga+F5ziIk+4LihnVPHyeaqHC+fu8+jn0GZIWXXALo5wSbKC6n0R0KQOd96+xu3Aks6jkIY5PWP02 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: Process the pages in batch-sized quantities instead of all-at-once. Signed-off-by: Matthew Wilcox (Oracle) --- mm/swap_state.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index b3b14bd0dd64..f68ddeb93698 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -309,10 +310,18 @@ void free_page_and_swap_cache(struct page *page) */ void free_pages_and_swap_cache(struct encoded_page **pages, int nr) { + struct folio_batch folios; + lru_add_drain(); - for (int i = 0; i < nr; i++) - free_swap_cache(encoded_page_ptr(pages[i])); - release_pages(pages, nr); + folio_batch_init(&folios); + for (int i = 0; i < nr; i++) { + struct folio *folio = page_folio(encoded_page_ptr(pages[i])); + free_swap_cache(&folio->page); + if (folio_batch_add(&folios, folio) == 0) + folios_put(&folios); + } + if (folios.nr) + folios_put(&folios); } static inline bool swap_use_vma_readahead(void)