From patchwork Thu Jul 4 11:24:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13723636 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 42ABDC30653 for ; Thu, 4 Jul 2024 11:25:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB7DC6B00DC; Thu, 4 Jul 2024 07:25:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEE846B00DF; Thu, 4 Jul 2024 07:25:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91C9B6B00E0; Thu, 4 Jul 2024 07:25:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 71FC76B00DC for ; Thu, 4 Jul 2024 07:25:21 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EF355C11D4 for ; Thu, 4 Jul 2024 11:25:20 +0000 (UTC) X-FDA: 82301839200.14.B2DD350 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf03.hostedemail.com (Postfix) with ESMTP id D1C1820012 for ; Thu, 4 Jul 2024 11:25:18 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=B7EEJvKz; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720092299; a=rsa-sha256; cv=none; b=cogdPN8mE+QrKjrYr0gxUojSCAwd8VNvQsdNA2vhluN5TlPxPosgVjx5tmlLVXvqnIS7Rk Y2i5X6BVwh1WPk3Hjrk7quG5kM6gYEjoYtE2Ui8gv75xkAYGeZlWAEODX7PV+NjzPup6Mo XEA/SGTkDPQvddy0FtwHbIivHQ2jmxc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=B7EEJvKz; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 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=1720092299; 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=cw7XWKxljyeN4WJVgu0jE9S3cyW8I72GFf5V991lB4Y=; b=ZOYYlX9xvVSOty2pfp6RqR6QtKUFQpwKke8/F7EKox87szpckPgMaO9vqwefE0jzoRgSBg MXpXnMhFj/N6aMl1ZJ36D3cZP1vMzSpY75bTSVRxcPRO+Lu9KbkFBRV89Yrlby8BI7PhKM CTuvqFzcJULwrC9l2g+wBFocUwVmcpc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1720092316; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=cw7XWKxljyeN4WJVgu0jE9S3cyW8I72GFf5V991lB4Y=; b=B7EEJvKz/X883XfMGuFi9jG+UE8TcyudSYkIYIzSCzUj4Prl/bx6hMf3/ErL9rvba1KHDRrX5YPn333FhqxQQWGYSaYs49Gl9f60zGHW1Ak0fQUaL8Ut2xb6N3nF65CfHt4esy3VCbonkJzPDsYblZfuEtfjyLXAOh8QGjrwKuY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033023225041;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W9qjnNh_1720092313; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W9qjnNh_1720092313) by smtp.aliyun-inc.com; Thu, 04 Jul 2024 19:25:14 +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 v3 06/10] mm: shmem: use swap_free_nr() to free shmem swap entries Date: Thu, 4 Jul 2024 19:24:55 +0800 Message-Id: <23ca2d1733c1a4e9f9781312a2dc21c8873b3bd5.1720079976.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D1C1820012 X-Stat-Signature: 8311xj1d36si7kdze6kid96cbj6tf7o5 X-Rspam-User: X-HE-Tag: 1720092318-295901 X-HE-Meta: U2FsdGVkX1+DqjVdxYRQsHtwDWHZC1db2rlZWMV/TSMelW4/Sg1QVgiR3aM0x4uII5Ugl2u9QT5a+tkcpr0orZctTF0zaFc4y0EOZG5Er6V7DCJM7KpIMNtLB2V6qOd6kGRDmkNRCDa2Rsz1ebjait8oIhCxzoMG3Jkbvlg55SE7fv+ZI+zqRtEbjCBDjuRtYHNYPPXs9E46oD9HekWvvMfPlCGHm5MmDLukqHymNh4+WZWno45uerj85Xjpnnvh2GrU9qiKMX/ozii5kd5zNegOkO0f3Z+KsQ8+0TiSj4cSXXKKF95C3TFk6N0+dELM83bKLgcPeh9EPbiMu9K9bNx55ICCDgoJqQvg/pXUP8dwxLtuXiZzPknJOQ97O6RjyWqJEwGUDLQflo5QlffvQM7bFkzmclmqQ2Oel5+hdJx4hmLYhfA8/dcpl9piJ6Mpvlbc/jBbF4A88s0L3VM5bMzL+OEA5HHPgY0uPbYIkubC4xaNmojePAPjSZHiOp9v+oNwTn8sDUjPYfWu+fkemlY7icGqe6eRHPbt1HDkarSxIwMZVo0G30FVOhwogEonKz1uHRHepDZR8PnM/b/SbVz9KMteLPMcIEfbyGxhYRexCx6DN6qsqSKSKrdHH8Nsuk1fxymo8TJWkvKOoCWPLugCecwWgFWrRlf2w7eQcgfs45m6tOjRjC8tXdGvhJwlAWzwz6eIdApL/vhjn6zULufx2V0A0Oc04XgnL//Fd7W2Lm3lyv3txOeGKdnHmQe0kEG0MsJlnx/yaOcPosMw9389Nb/JyULKy2HyDq6phpWNEg5yNH7FzQYmixeWBsCzzYesU9B5qMKv9tPHfIkZqHCDs/HvikMrKilgnSFdBwjk792Jata8lG/M0EvHTVmQFvxrpX243Rqiqkk94Arv9ObIuyUCNrPOE89enBTAkTYiNxfIWizXom27fUAL4sSzXggQVXTDJNNcdDrXboH 14cUiV0e ERE9XPjUxW/zJtDifxIS9ECzk44nE5tyf4cTuyxM3LD8nYvD1rpPNPYTkq3XOt3EnfmWVBnKV48X/e6equb2CBItJvQ4q1g8x1/2dW+1gRCP/VdU20Sm3wEs65nJI8wxY+ln112KMGmoC7SqU9AG/hyxP1Qy5wbPsK3G2k5QCtTM8eemHj/TeI3eQrmityea6iXvxALezbVOXzWPUbrdQqu6tpXsfjFLPh8QyGzCn45gsexIwmHP9S17bHwrYSIOib0PU8VvUU1sWQWuwOlLssaI96+Jy+ztEPA8T 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 5159d60456ed..c1b6cdc61619 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;