From patchwork Mon Aug 12 07:42:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13760271 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 83D41C52D7C for ; Mon, 12 Aug 2024 07:42:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A0CD6B00A2; Mon, 12 Aug 2024 03:42:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7683F6B00A5; Mon, 12 Aug 2024 03:42:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51DB06B00A7; Mon, 12 Aug 2024 03:42:29 -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 189666B00A4 for ; Mon, 12 Aug 2024 03:42:29 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BE6AA80872 for ; Mon, 12 Aug 2024 07:42:28 +0000 (UTC) X-FDA: 82442800776.09.9240A89 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf13.hostedemail.com (Postfix) with ESMTP id C229B20010 for ; Mon, 12 Aug 2024 07:42:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=YqK8RcEK; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723448536; a=rsa-sha256; cv=none; b=02BTXJ1T3vZ4BddFMD+urubJ60N2aeEzKreHEJFGvm/TtQhYIo/KoMjcN83CsflFCVIDxN NymkEpEM8lK9GBDYEb71KHwV51TDR+sRfg8VLI5Wm1alQAGgIKcE55BTiTgY1StYVZviYx NRF4A8DT0Ehhc46akcWP2oyp/NykzXc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=YqK8RcEK; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723448536; 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=CJ17mJWuqe6d52h6IBrZyk6CffbeYGvkfB1+lwHpEl4=; b=Cpy4ljjDBM+hfz4lTXTDhc3wFUdwn5BLuDOGBnsfiv7bAvsAbWXzbz3pTk3qQKadY4A2rj w73ZUd99XjnP4zOuYkg9gQlZt6Mgb6P+rd3z2cHwUOt/xcqSrhgXCHzVuXn5BztIZ4QlM5 4Zy2BjeFZf2hHsvE4AV95dlVh3D4wBI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723448544; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=CJ17mJWuqe6d52h6IBrZyk6CffbeYGvkfB1+lwHpEl4=; b=YqK8RcEK97o5sDSbuo9hOYNwKT1ZNBSWmLzGGWQ/3gW5BMP0VeNaVm+JTvPKTW2kvy8bEd3E4BTfs20QEyMLlPNq0pHOa2uMbyMn27noS/F1426h8BidOfpHz4RfF3Uj60a0twx+9TGfLLtL+jPcU9cL/+2j+5kZaGdywgwvDNI= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCazOiu_1723448542) by smtp.aliyun-inc.com; Mon, 12 Aug 2024 15:42:23 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, chrisl@kernel.org, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 5/9] mm: shmem: use swap_free_nr() to free shmem swap entries Date: Mon, 12 Aug 2024 15:42:06 +0800 Message-Id: <342207fa679fc88a447dac2e101ad79e6050fe79.1723434324.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-Queue-Id: C229B20010 X-Rspamd-Server: rspam01 X-Stat-Signature: q6aem8ihz9hkkic156f3mk1fkdoqwc5a X-HE-Tag: 1723448546-509845 X-HE-Meta: U2FsdGVkX19AOX+tPGSf/Ad8RMbG/hRE7NoPOJoF/mpoDUMpowVAXKAPmozCwgsZypTsZaUBg2E+F4byWqMhb3V7vBJFiDOT7HNYZd159HgxLTeaOOhLKB+VWrKmikMpSM9gZNS8/dZX63zgErrB49mEqIBDTgjqUy7jg1VqP+TaAclCwZ2aVvkL7cPj6ZwrpCHl9k2SgtSjq33+cPgj0El7qV6P4tTBe5FYLO96gFogyZ+paC11mqeBbCt3zbUjFTEIA9c54olEhdkVx9HNJYA7xg46lUfdvcahhGbBOvyTqWRbi/+TE31whwghkYEmwYvoJesGRRbGPL64AvV8U4uTmrJGT+K7HyRBqTI0MUjKJE0YJPAqapPe6GF4NFE/OWI7sHruDwsuTQuS/vjdK36non9jt3Put3lT9s+7eZEH0D9uKSo+mH/t1xK2Hc7IPh/73V6rrKiAztAlToxr2Sto63mnZvLU1SC3Y6yDHWPFVXAsuahW7CRtreWinUtpjndAryR/25/+3qVsf6aAvsuO5obVIft1xqG3tCjYItoR7PfH2mDh4yRwooFDfYsEx0wYDILkDkVorS2XL3Rii3agvcFz/JRJU0XzafzQMQjO1RT6K55/9P4JRHtEJogm7O8qVJ8UEd7b7tJSK5aY7O1uB/q3wYiTf3uYUHJ+BJeNdW5jCOdxWkFbbxfJXi/9psnTLcdACcBDrEZsEY4AYrGcxaG+HrxJKJ+0wIqumvV+PlIa0Rs1Wacewb8n7+5A1Kwfh3mLyQiSgMgDO2uJB6YGHiCmxNbdeFIwkmK80aD/wINUL3CvjTiK9smw5/iv/gtanxQzj6wxlVfRU9SF1V+OnS1M0aY+f0gOsiY2UwcOYgffdjV48xVH13AXAD5QvNAB6iuWeUjgUWaujlfsn1tFoO/W2Rw+gA8QsMuoxfJRaOII4EVaoyg6zcsRdnhrRsXMQDZY8Ivm4xa+jGn WA4XXD1o uGyddXcaKazE+HZMSEs4uveY0bGU617Ieg23czMtnu117xpuMUOJs0HcMFkkNcalxNIKEfrXV1emuwBZYPouBCnpjGkBN753lIueet/mIHcVKxNbe/yPCK7eEzvr2ZM7dOMzVKWy5bvi47rDx3im/2Fp32kpleF6jJUFaIQEC/irD3/PA6UARubhZVjJwRT58ljBNUqoRnsfc9rdTWoLPOQai7pCikeMaaj1c8O6QvD8dbWA4t/rq4Wogtw== 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: 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. In addition, the index should also be round down to the number of pages when adding the swapin folio into the pagecache. Signed-off-by: Baolin Wang --- mm/shmem.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d0d54939da48..f6bab42180ea 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1961,6 +1961,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, @@ -1969,6 +1970,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); /* @@ -1976,8 +1978,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); } /* @@ -1996,7 +1998,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); @@ -2043,6 +2045,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 @@ -2056,19 +2059,20 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, goto failed; } - error = shmem_add_to_page_cache(folio, mapping, index, + error = shmem_add_to_page_cache(folio, mapping, + round_down(index, nr_pages), swp_to_radix_entry(swap), gfp); 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;