From patchwork Tue May 21 11:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13669307 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 578E2C25B7A for ; Tue, 21 May 2024 11:03:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D60E86B00A1; Tue, 21 May 2024 07:03:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE9C26B00A2; Tue, 21 May 2024 07:03:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3C2D6B00A3; Tue, 21 May 2024 07:03:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8E6046B00A1 for ; Tue, 21 May 2024 07:03:48 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 45A1B1A0341 for ; Tue, 21 May 2024 11:03:48 +0000 (UTC) X-FDA: 82142117736.10.F8A3C25 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf03.hostedemail.com (Postfix) with ESMTP id 345B420013 for ; Tue, 21 May 2024 11:03:45 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=OTpGakiC; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716289426; a=rsa-sha256; cv=none; b=g/MbnOBeQbjTQNoi3gFKSo2l1Rn6n4SmGt6TZX6xWIe+MN6OTxlZ5wlWNgy/9CV60DZcMj uBfzgimILy4M757t+nZ9DigcLRcsxotIU6neyDWXOQs+v8Qe96Ko3ChOKDXeEZCyO1UHtz zdU9ZWKj2rZMBFVguqaHZ6cJ/vRYb7o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=OTpGakiC; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716289426; 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=/V3DnBye2LjO7u5ouBgBU8nPrUqi/2Egdsz3zKACdwM=; b=hY+zVneU0yds3NZjYl3c6AP5BUvhxmlO+LAjk5nbedMFQg/nDkBLY/F94OLA44ivSKG04J 6i5BMEWamw52n2erRvSPqfaTJOieG/cXXYkLqGMNh4NHjitNKMn/2Rm/6cB+2wxZGGre9o 4IED5otOnAapMJdutB2U/oESOZOiVvw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716289422; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=/V3DnBye2LjO7u5ouBgBU8nPrUqi/2Egdsz3zKACdwM=; b=OTpGakiC/UZJlMSyaFPQo432K8mpDsxrkIxOwJ8KJl6PCC9YC+3JbgAzLxJ+9sgngjaeWGiexkJRw3XTAxbMy4mawf/SKY4oW+MOxf5K3HAI5DIczcK73cuo7rVvh4zE825OhgSvsQQ7APsv4RzeElpcFn0MplmhGe/vX+IXW2k= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W6xl985_1716289419; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6xl985_1716289419) by smtp.aliyun-inc.com; Tue, 21 May 2024 19:03:41 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, hrisl@kernel.org, p.raghav@samsung.com, da.gomez@samsung.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/8] mm: shmem: use swap_free_nr() to free shmem swap entries Date: Tue, 21 May 2024 19:03:17 +0800 Message-Id: <90fda314a9e966374fe837ae3ebd74708380479d.1716285099.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 345B420013 X-Stat-Signature: ukgc8p6xq35g6wbazj9gghnjo3szgirc X-HE-Tag: 1716289425-363609 X-HE-Meta: U2FsdGVkX18cP6/ZZzXEM6gcgyKlsAH9JPRnuuKxyn1tx9YLlzRBaEFNteCSRYtsS1yoiChAbKVBhP2ybo/Wnedptx6MeLPtLurEp3Cw9xasa7m0vACDb1Z3b7d3z6RkTpot6Kaji2+gD36BU+MUr1yyFuN6MBa00TIWNavsYplixfY/RYg3tRQrHkmcBQ3/OF6SIsctKb7+s+YR9za5YSE0yP8FhvRj647uGUj5NI03Cdpb9rBe2XQKPi09Nbuh2gJH2eWXvDx+zCW8OWES72F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ulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: As a preparation for supporting shmem large folio swapout, use swap_free_nr() to free some continuous swap entries of the shmem large folio when the large folio was swapped in from the swap cache. Signed-off-by: Baolin Wang --- mm/shmem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b3e39d9cf42c..fdc71e14916c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1962,6 +1962,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, struct address_space *mapping = inode->i_mapping; swp_entry_t swapin_error; void *old; + int nr_pages; swapin_error = make_poisoned_swp_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1970,6 +1971,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, if (old != swp_to_radix_entry(swap)) return; + nr_pages = folio_nr_pages(folio); folio_wait_writeback(folio); delete_from_swap_cache(folio); /* @@ -1977,8 +1979,8 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, * won't be 0 when inode is released and thus trigger WARN_ON(i_blocks) * in shmem_evict_inode(). */ - shmem_recalc_inode(inode, -1, -1); - swap_free(swap); + shmem_recalc_inode(inode, -nr_pages, -nr_pages); + swap_free_nr(swap, nr_pages); } /* @@ -1997,7 +1999,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, struct swap_info_struct *si; struct folio *folio = NULL; swp_entry_t swap; - int error; + int error, nr_pages; VM_BUG_ON(!*foliop || !xa_is_value(*foliop)); swap = radix_to_swp_entry(*foliop); @@ -2044,6 +2046,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, goto failed; } folio_wait_writeback(folio); + nr_pages = folio_nr_pages(folio); /* * Some architectures may have to restore extra metadata to the @@ -2062,14 +2065,14 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, if (error) goto failed; - shmem_recalc_inode(inode, 0, -1); + shmem_recalc_inode(inode, 0, -nr_pages); if (sgp == SGP_WRITE) folio_mark_accessed(folio); delete_from_swap_cache(folio); folio_mark_dirty(folio); - swap_free(swap); + swap_free_nr(swap, nr_pages); put_swap_device(si); *foliop = folio;