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 99872ECAAD5 for ; Fri, 2 Sep 2022 19:47:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25660800F6; Fri, 2 Sep 2022 15:47:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14538800F9; Fri, 2 Sep 2022 15:47:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9097F800F9; Fri, 2 Sep 2022 15:47:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5FC5C800F7 for ; Fri, 2 Sep 2022 15:47:02 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 48A5B1A0222 for ; Fri, 2 Sep 2022 19:47:02 +0000 (UTC) X-FDA: 79868178684.29.CEEDFCF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 02E7B180077 for ; Fri, 2 Sep 2022 19:47:01 +0000 (UTC) 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=oGSPn8NwOXRP4TYNP3MMOCC5rGBSouXy25gKhFOlJYA=; b=AeDxYZ6YE2uYvhS6quE6GV/iQy bRbSolOaeB6ovSswv9ufUahlo9XxGNxcsEn5AcAy5AL91XOpSeNIfZHnmksLMJyGImMWT0xw4a+VQ QHkyYuGc0tKkntXMUg6qVSSuH/OCwUHywY7cSV5x83KYcxcloTOHbC1ht8s5D7t08PKx8GpLhLh6Z uX9Zh2mWL+Cabv5T3bRgRm3pgJ/TKNoNh3wK4O5LltZYksOo5IfekHT22LGv7osf/Ae63zLLL0Y4+ FiBig999XnZ11KQqDdko+S9KfN1BaU7P5rUqMblrryUvELw7yp6VQ8DJyPJlJXag4SH4I7EJUkzej 1nse1fSw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oUCd0-007Ibv-NS; Fri, 02 Sep 2022 19:46:58 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 10/57] mm/swapfile: Convert try_to_free_swap() to folio_free_swap() Date: Fri, 2 Sep 2022 20:46:06 +0100 Message-Id: <20220902194653.1739778-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220902194653.1739778-1-willy@infradead.org> References: <20220902194653.1739778-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AeDxYZ6Y; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662148022; a=rsa-sha256; cv=none; b=lI88B701axEmPOikIAr2/BYLXwxy57h6+zNr5Nwb+yCnK+GTth+K0Djg9CyignI84/p68x BdhY/RFka1xjJR/86nJK3WsjkoxQg0bkiOehepoGMhYCqEvnAie6LyAOd1g1sK9zQ+zOdW WGoktSMNFSwDE8AoF1xfAvQhw5ZfqhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662148022; 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=oGSPn8NwOXRP4TYNP3MMOCC5rGBSouXy25gKhFOlJYA=; b=SUNLmVaKIr3y71Lp/vM8N6Z6QkGJ027oE4WBCcXPh+/BrAjp8dWsmfzpWO5Ah9dk+X46kn wYeqD4zqRwXsB1BVz/TBkIwxuD4UzJwIfC5W0GeIssvxdwQPneedEmSY9PV1852v/ppCLT pAswh/JNchDH5wunOMaz6zfjEHZDqBU= X-Rspamd-Queue-Id: 02E7B180077 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AeDxYZ6Y; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam09 X-Stat-Signature: xbmtth3jqaecqype3eqn864b9aw9gg8r X-HE-Tag: 1662148021-672562 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: Add kernel-doc for folio_free_swap() and make it return bool. Add a try_to_free_swap() compatibility wrapper. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/swap.h | 6 ++++++ mm/folio-compat.c | 7 +++++++ mm/swapfile.c | 32 ++++++++++++++++++-------------- mm/vmscan.c | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index afcb76bbd141..4595cbc1cb02 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -486,6 +486,7 @@ static inline long get_nr_swap_pages(void) extern void si_swapinfo(struct sysinfo *); swp_entry_t folio_alloc_swap(struct folio *folio); +bool folio_free_swap(struct folio *folio); extern void put_swap_page(struct page *page, swp_entry_t entry); extern swp_entry_t get_swap_page_of_type(int); extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size); @@ -602,6 +603,11 @@ static inline swp_entry_t folio_alloc_swap(struct folio *folio) return entry; } +static inline bool folio_free_swap(struct folio *folio) +{ + return false; +} + static inline int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page, unsigned long nr_pages, sector_t start_block) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index e1e23b4947d7..06d47f00609b 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -146,3 +146,10 @@ void putback_lru_page(struct page *page) { folio_putback_lru(page_folio(page)); } + +#ifdef CONFIG_SWAP +int try_to_free_swap(struct page *page) +{ + return folio_free_swap(page_folio(page)); +} +#endif diff --git a/mm/swapfile.c b/mm/swapfile.c index c042fd71de02..880871f4c6d4 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1563,43 +1563,47 @@ static bool folio_swapped(struct folio *folio) return swap_page_trans_huge_swapped(si, entry); } -/* - * If swap is getting full, or if there are no more mappings of this page, - * then try_to_free_swap is called to free its swap space. +/** + * folio_free_swap() - Free the swap space used for this folio. + * @folio: The folio to remove. + * + * If swap is getting full, or if there are no more mappings of this folio, + * then call folio_free_swap to free its swap space. + * + * Return: true if we were able to release the swap space. */ -int try_to_free_swap(struct page *page) +bool folio_free_swap(struct folio *folio) { - struct folio *folio = page_folio(page); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); if (!folio_test_swapcache(folio)) - return 0; + return false; if (folio_test_writeback(folio)) - return 0; + return false; if (folio_swapped(folio)) - return 0; + return false; /* * Once hibernation has begun to create its image of memory, - * there's a danger that one of the calls to try_to_free_swap() + * there's a danger that one of the calls to folio_free_swap() * - most probably a call from __try_to_reclaim_swap() while * hibernation is allocating its own swap pages for the image, * but conceivably even a call from memory reclaim - will free - * the swap from a page which has already been recorded in the - * image as a clean swapcache page, and then reuse its swap for + * the swap from a folio which has already been recorded in the + * image as a clean swapcache folio, and then reuse its swap for * another page of the image. On waking from hibernation, the - * original page might be freed under memory pressure, then + * original folio might be freed under memory pressure, then * later read back in from swap, now with the wrong data. * * Hibernation suspends storage while it is writing the image * to disk so check that here. */ if (pm_suspended_storage()) - return 0; + return false; delete_from_swap_cache(folio); folio_set_dirty(folio); - return 1; + return true; } /* diff --git a/mm/vmscan.c b/mm/vmscan.c index 93b1087fc969..d3e26712dbc1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2004,7 +2004,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (folio_test_swapcache(folio) && (mem_cgroup_swap_full(&folio->page) || folio_test_mlocked(folio))) - try_to_free_swap(&folio->page); + folio_free_swap(folio); VM_BUG_ON_FOLIO(folio_test_active(folio), folio); if (!folio_test_mlocked(folio)) { int type = folio_is_file_lru(folio); -- 2.35.1