From patchwork Wed Apr 2 14:59:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036137 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 24394C36017 for ; Wed, 2 Apr 2025 15:00:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC529280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C5828000A; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 994D6280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) 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 6B069280001 for ; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 810B5BB53E for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.20.A39E830 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 3A98A4000A for ; Wed, 2 Apr 2025 15:00:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="XHNF/9U/"; dmarc=none; spf=none (imf01.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=1743606010; 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=UNBvZu32+wbhgVGJ/9V2hTzAlK5EbvmAK/2hRd+u46M=; b=G4v7YFssMOrZc1IlPiFQM+iuBvs6fMGw795Z62YPaITRyliBG9BO59R76uT6M1KjmiAv8u CzpQ6PEdfpICqpy5J+Ej2p+bBmS3KIHwvwKWnU8yusZsd1znYQwe+7yuwIb+avK3NzdA3Q SSwsyzZeWtoDvUKlDbFZSkKc0zMUh9E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=24D+ZdnkjlK6MZDGd3Ee/LPVbIXP5ScbiqOvJw4/WEL821veGV152y+h4Ux8p/sxKf9jtA o3uz6drpAUOd84nDEG7jsWQSB905qvQGE0D0ya17f1EZZKXV2sZHhuUV2gJq1muWPuk31C qZVqHot0FifoIQrXdSRSJybb0yRuzfU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="XHNF/9U/"; dmarc=none; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org 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=UNBvZu32+wbhgVGJ/9V2hTzAlK5EbvmAK/2hRd+u46M=; b=XHNF/9U/du9de/iK9s+5I0zADe O+pcJekTrVv0miXdwnb2siiLrxPQ27obx126RH95lkiAfLPAAiw5DvsERoraJ1GxJ5zwc0OJN8MLJ mzz6kW7koritqrR8/48YFJXZ8pTDxscVtOMVpcZEwruRJWoZgw7wP6NWFJE+OwtsX98cnjHp30+IB mBwUPemgYHjyVvwXxn6n+4vuYbWzk0y5zi0LnKrLC/Wp2/1dvYNXnRqeKPpFabINxRCSZHqn+ho1y MGDRzGBrEvmxT/3g7p5MVUDU9NOB6UTqSjIzkQtteVdvzD7oY9ZCxp71gpUWpcba7+RjXi61HPi8L 4YWmojyQ==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsH-1u8G; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/9] shmem: Add shmem_writeout() Date: Wed, 2 Apr 2025 15:59:59 +0100 Message-ID: <20250402150005.2309458-6-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3A98A4000A X-Stat-Signature: 6sjs9hz3cs74b4s3swk5y5ws71jdnut3 X-Rspam-User: X-HE-Tag: 1743606008-743506 X-HE-Meta: U2FsdGVkX1+cJPufA5blNQmyPQClnVW65B84VSujoUYNqBH1bPyLAZEaVjfSiJkTlQ6VpozurqLotlc6DMaQgIQ25Yzxl1MDGzM2X1eGIcxtkkAYShkiNCT+mAZF34ERScWzMOuQx5/iB7ocIxgtyimxOCQS1pRZ9jQMBVbut8348B8c4agJFqaEp9pLPcuTvkvhr/5sttxy8FLPhMb9QZAnRWE6O+Yy5lzaQ0x9wtTbwRoL31BAz7H0sohNUKOViRLMUqiWbvLTK2zo6p9+CUFhP6jUh3B2sDB43FwYF5ZIna/p4sUfTBUz94lxiYxBDKVffo+QjgNFo66kUgM4Qn8HkNKtgIVjYCkEC0gPeOjN+p/caCvAEOb2Cu/Me+FZ2oRctSnX5rDanR/MsfLRYCR1wQY4L1EbEhOygp3dc82VhgAlMrBtWfyue/g6UaJsx9gin2aEReWCcti0zCtcBFN+qT7MQelGikYr/Dnob+xgkgUjO5PiUBU35aFIQB5H1l3hmARQ4dhqOs0xj6c6kvSvtFPOdKV1sSFIsxyeBynZc2jt/rPI/wRbISOHyhtuX1ZJ/PhjTDEj4cnr4mfutpNu8KqespG3HS9K37rCb5indTVDfrDnWj2FQtt4awrKKadMu380mIZ486B573QykmrA9A6aJurr02NtVbDyuRn9+/x+wvrnK1U19TMuqg0XbPMbLAXNbow+Jqe/5HL85iW6FJpWaqv4AjCG/rUms7fBgD/VY84hHmYYrW64BGhh5N+FmuEzndKeYAy98j8P89X49EaEFt2uY3yz/rVrlB9vKa4cj11AJlfxYL0c0VBI5l6UWPKGGYLUF/59ErUSTr+Q++FnwErQxp13BAcJHUP2Gv7+jKAH+ISqeIHxNOr3a7xsu2o+IqtAHWrM6j64rtRGvaWlaq6a123+vBZkUDa15SeZeWsGGfkoP3S8drje6Iwy0th17nWpGjolSVO oIqk2Pc9 SNrGspL3GME3bezjN7EVq/3ZoNGggdbIaif+J9qUfdBRCdP8oBfHD0YHOGc44A/ENuDOx5iDdxd4kUA6Mud+7YlMke/vZ370aRhWv/GeK7xmYnWEfVDy8wKl3BULeupbvJZ4aRVOsNaVZjWaHeTf1w9lka40+STq7KQQFzRIYy0wiiPZITU8l4DfTOZqmEtAvCYLUJy+OVROazVqaNDMmtiMhjVo8HRyk+6BWsOI87/4X0gjQnG1iyv65Bg0dtb6frnVLycSrVxWwER4Kp1p1YMRnIkiSpS8rKC48 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: This will be the replacement for shmem_writepage(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/shmem_fs.h | 7 ++++--- mm/shmem.c | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 0b273a7b9f01..5f03a39a26f7 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -104,10 +104,11 @@ static inline bool shmem_mapping(struct address_space *mapping) return false; } #endif /* CONFIG_SHMEM */ -extern void shmem_unlock_mapping(struct address_space *mapping); -extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, +void shmem_unlock_mapping(struct address_space *mapping); +struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp_mask); -extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); +int shmem_writeout(struct folio *folio, struct writeback_control *wbc); +void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); int shmem_unuse(unsigned int type); #ifdef CONFIG_TRANSPARENT_HUGEPAGE diff --git a/mm/shmem.c b/mm/shmem.c index 99327c30507c..7d377ceae035 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1536,12 +1536,20 @@ int shmem_unuse(unsigned int type) return error; } -/* - * Move the page from the page cache to the swap cache. - */ static int shmem_writepage(struct page *page, struct writeback_control *wbc) { - struct folio *folio = page_folio(page); + return shmem_writeout(page_folio(page), wbc); +} + +/** + * shmem_writeout - Write the folio to swap + * @folio: The folio to write + * @wbc: How writeback is to be done + * + * Move the folio from the page cache to the swap cache. + */ +int shmem_writeout(struct folio *folio, struct writeback_control *wbc) +{ struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; struct shmem_inode_info *info = SHMEM_I(inode); @@ -1586,9 +1594,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) try_split: /* Ensure the subpages are still dirty */ folio_test_set_dirty(folio); - if (split_huge_page_to_list_to_order(page, wbc->list, 0)) + if (split_folio_to_list(folio, wbc->list)) goto redirty; - folio = page_folio(page); folio_clear_dirty(folio); } @@ -1660,6 +1667,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_unlock(folio); return 0; } +EXPORT_SYMBOL_GPL(shmem_writeout); #if defined(CONFIG_NUMA) && defined(CONFIG_TMPFS) static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol)