From patchwork Tue Feb 27 17:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13574197 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 201F6C54798 for ; Tue, 27 Feb 2024 17:43:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AA7A6B00EA; Tue, 27 Feb 2024 12:43:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24CAC6B0093; 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 02B2C6B00E8; Tue, 27 Feb 2024 12:43:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DD6476B0085 for ; Tue, 27 Feb 2024 12:43:03 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9BCED1A0905 for ; Tue, 27 Feb 2024 17:43:03 +0000 (UTC) X-FDA: 81838304646.05.3AD6EC3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 3606E4000F for ; Tue, 27 Feb 2024 17:43:00 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ljcg3YSj; dmarc=none; spf=none (imf07.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=R3goVY0LruHLbvMFj7bnimSm59kHXIfZY+DKSTKrvLI=; b=VeusWnwBDDeVfqu/9KvB3dLqr/RkbM2v36Z7MH6iX4gYrLBNqpnJBLs3IfGJCqXpGUPL+T +7XoBLKey6FZwsUcSObLdysETPlXU+S7mtA22wvgJxASPyb7NHsmNc1E6mq1SRJk0HpfCs 0i1x7xP8xaByV6CpjH08CedawJ4lLuo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ljcg3YSj; dmarc=none; spf=none (imf07.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=xerul7YoHMMBV62qHNYrIh3e0YlK9jfrQtB4unLyqOOAi3yjTjokz3Vi2K7Pl6o8/vTSj2 0r5PANhlRd2GrvZlNf8zyxXQsFZS5n2b5FV72vEqZpzX4zCBPtDvL7scGjU9JZ9wsovJCC lAKXKXhrAkEpP20apXaKWM1zKwbcgf8= 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=R3goVY0LruHLbvMFj7bnimSm59kHXIfZY+DKSTKrvLI=; b=Ljcg3YSjPx01EbKbyb1zd1vg3e GTWnm5lsNfgpU8I0kgy23UQ9eRiq4hjyT0HrkStJ1w7NdxxMFqCYz2dbyNVc7t/0Gmnhvo2UjNKlo NDGXofldXg8rs9Ks8MAXmsqdTcqGLd4HIIyUdAoYzcRw5lh/tLBsKP2uBDAnihGf/AL0fNdPgYxe7 tk7mYsLP7E50j3dpAdXqvS1ujAhes0ZxjQIf99rOPDUbddCuMrHzUQmMESL/F3UONH6ZHJ5/nHjU2 ewJl4TYn8uhibLqtt4eLDvXJuBiw7QxC92Cjhzkhy1Cmc6/9B11Q9IfwdiLADnk3YYLIZqX7lFc6v bKgfXPWQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rf1Tn-00000002ysG-2sUt; Tue, 27 Feb 2024 17:42:59 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v3 16/18] mm: Convert free_pages_and_swap_cache() to use folios_put() Date: Tue, 27 Feb 2024 17:42:50 +0000 Message-ID: <20240227174254.710559-17-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-Rspamd-Queue-Id: 3606E4000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: g6inx4r5m9k8rc6y4w3qqyeu5jds6r7d X-HE-Tag: 1709055780-123412 X-HE-Meta: U2FsdGVkX18bWMPmD1PmMEiaZ0LVY5GwKEmMjeaKRJfKqCT17rH21nzuBrHruMyb29QhpYcg8WqcmR79+UZbhDkpyAG5BW7uwipjw8JmBxBkAI022TG8akY1jJWnBkvUZV8zZHInQtW7yhVrgtvYCNjcl2W07+KXD7abQJasWwrjT19Ab4ULW/DMNuZOXW5DVuvbk9leZCNUBzgBfd4eyhuLHJj444z+4qukVs5x5uCotUPFqnQzP8+WdLHmtEZVx30yECCW2Tr4fV0TkKcfBpfcAbY1VD5/euTfZdHyqf2rkH2SpFuQ5qySUzTLBamElcPNlIsppxBxWF5tTWkxUHgSWyKshtH5USI7lcHF8OW4CmmomvKyy9x6e0XnreTJZCbN3UomwZYNETyVV9QuVeaASwCuV90DAV6c8p1bJWnJh88numBnBzegWB6leLaUa3Q1r85Fyrbt18MkmyF7TcY+PrB0VwgQOeGjFUSo2P1qdtd42bPepAie/blPr2ms0nnasYK6XFuDZQV4+9pHRtRfZ3B4IbRSlZXCbcT/vgExPf2hDXuAuT7inxYY2VAaFA2DuEEtXjwj4rgtdo7DH1sm1Ev0zy8DBlRonnUpA3CUR5yh0fxyp4cuXvXIDsdB49ogcBzYbL1sYMKytev+nTNcoMGZIOXaAPIq9g59JYMJ+vf70fbkF/LzXp/LkpJAuVgWPqc7Z7TA0hPmV5qvMIQrvG5WJPJ7+tBDmGgCG42lhHIv/quEzqIGWT8mSD+5MVktKXUGMLd+GvAMpZQaIEF815wLalfd89Iy9+H+ml6LIKsoAX6H3B5K2LoAN5LIDIngvV+hAOq0RtUI4SizzRszv183h3VHr8vtvCUUvNOVkH/h8/gt5r2bvEG4pXltUVL9KU2QixB7e2A8hZbuK1hovz2ujIY8 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: Process the pages in batch-sized quantities instead of all-at-once. Signed-off-by: Matthew Wilcox (Oracle) --- mm/swap_state.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 2f540748f7c0..2a73d3bc5d48 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -310,21 +311,25 @@ 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; + unsigned int refs[PAGEVEC_SIZE]; + lru_add_drain(); + folio_batch_init(&folios); for (int i = 0; i < nr; i++) { - struct page *page = encoded_page_ptr(pages[i]); + struct folio *folio = page_folio(encoded_page_ptr(pages[i])); - /* - * Skip over the "nr_pages" entry. It's sufficient to call - * free_swap_cache() only once per folio. - */ + free_swap_cache(&folio->page); + refs[folios.nr] = 1; if (unlikely(encoded_page_flags(pages[i]) & ENCODED_PAGE_BIT_NR_PAGES_NEXT)) - i++; - - free_swap_cache(page); + refs[folios.nr] = encoded_nr_pages(pages[++i]); + + if (folio_batch_add(&folios, folio) == 0) + folios_put_refs(&folios, refs); } - release_pages(pages, nr); + if (folios.nr) + folios_put_refs(&folios, refs); } static inline bool swap_use_vma_readahead(void)