From patchwork Thu Jul 4 11:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13723640 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 4E90CC30653 for ; Thu, 4 Jul 2024 11:25:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 155836B008C; Thu, 4 Jul 2024 07:25:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 106B86B00E5; Thu, 4 Jul 2024 07:25:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E09AD6B00E7; Thu, 4 Jul 2024 07:25:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AFA9F6B00E6 for ; Thu, 4 Jul 2024 07:25:25 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5EE87A3DD5 for ; Thu, 4 Jul 2024 11:25:25 +0000 (UTC) X-FDA: 82301839410.08.AF723DC Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf17.hostedemail.com (Postfix) with ESMTP id 7F8F34002A for ; Thu, 4 Jul 2024 11:25:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=AunEbIZ1; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1720092298; 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=EpkaKZeif3DR2KNud0UcpLjPquN1O7r8iKvlNR8OHHc=; b=qHcVUG4i6OmvU+SG6vxopwx1L8Jsk8AA8RNnu9NK3Jdx6NAJLQUWFcEPhm7eB5LvRpfUoM Jpj9C+/yqltyyMu0zrTT7EMcu7BO6Mlvh+u2FdYmC+a7f66z4g6PpgoqtI0tQa73P6EWT0 pemMkyLCdteZHHO84PZmIHAzjO2f5S0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720092298; a=rsa-sha256; cv=none; b=Him9sVytmcxZ62VaAi07MQVs0YzHiP67JHi9nYKEkyhet1b+I2KtZ1dBX2EaGb4YqOoMpY 1M35mt01MxgCw4kkJF6JBpAqqsucU6VUb+/3KzEj9w3OID+mkTUtJINzmzJ8Ad12FNJzk7 ecYe4o4GfD35yEGJTtb36j5hpxytqZg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=AunEbIZ1; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1720092312; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EpkaKZeif3DR2KNud0UcpLjPquN1O7r8iKvlNR8OHHc=; b=AunEbIZ1LHcy+89V68+o9NsXGHt8gVXfXQ9YNakBzzfXE9boyWYpLhbZHcI0P5RQpTAZ6yiGyso2Qee6/G68gi6Og83zjuYEUoQQ7NK0Tmr3V9xBMG2hpvms4EYz0fdHdYnrTr4t6gwSqCA6EHevW5CyQlwFX7qfUzxMDs9Uqxw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067111;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W9qjOxX_1720092311; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W9qjOxX_1720092311) by smtp.aliyun-inc.com; Thu, 04 Jul 2024 19:25:11 +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 04/10] mm: shmem: return number of pages beeing freed in shmem_free_swap Date: Thu, 4 Jul 2024 19:24:53 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: npweqtabds17hyxcrk3xgq9uabomf4tw X-Rspamd-Queue-Id: 7F8F34002A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720092321-195437 X-HE-Meta: U2FsdGVkX1+/sS/52/3MoeiPXBN0FcpUymXlIqjdpD9tdR/rbxc5+naF2ScscqNENAC/6VGnlFXyaebNIF+a2eyPj/zsQuRH/ABqzV41VQRVrElMksCYAMVSiIQFOKGD3o3Po1Cn5IUtE8WirTWS24zDJVKyRwJDDHllpltFXDYXhI8Brum91xB6mMJCIl52relFl4pmIlGdxtuaJ5Qh/iNQVk3jEtSFEo+kQX+ivbEpWb3XXUf9Kmu70nW5jPhV7j5JaFsukjnfdFnQcP5bSm2TgVGqja7oFS3YfheqpR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ogosity: 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: From: Daniel Gomez Both shmem_free_swap callers expect the number of pages being freed. In the large folios context, this needs to support larger values other than 0 (used as 1 page being freed) and -ENOENT (used as 0 pages being freed). In preparation for large folios adoption, make shmem_free_swap routine return the number of pages being freed. So, returning 0 in this context, means 0 pages being freed. While we are at it, changing to use free_swap_and_cache_nr() to free large order swap entry by Baolin Wang. Suggested-by: Matthew Wilcox Signed-off-by: Daniel Gomez Signed-off-by: Baolin Wang --- mm/shmem.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 42bf3176fa6c..5159d60456ed 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -847,18 +847,22 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) } /* - * Remove swap entry from page cache, free the swap and its page cache. + * Remove swap entry from page cache, free the swap and its page cache. Returns + * the number of pages being freed. 0 means entry not found in XArray (0 pages + * being freed). */ -static int shmem_free_swap(struct address_space *mapping, - pgoff_t index, void *radswap) +static long shmem_free_swap(struct address_space *mapping, + pgoff_t index, void *radswap) { + int order = xa_get_order(&mapping->i_pages, index); void *old; old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); if (old != radswap) - return -ENOENT; - free_swap_and_cache(radix_to_swp_entry(radswap)); - return 0; + return 0; + free_swap_and_cache_nr(radix_to_swp_entry(radswap), 1 << order); + + return 1 << order; } /* @@ -1010,7 +1014,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (xa_is_value(folio)) { if (unfalloc) continue; - nr_swaps_freed += !shmem_free_swap(mapping, + nr_swaps_freed += shmem_free_swap(mapping, indices[i], folio); continue; } @@ -1077,14 +1081,17 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed; + if (unfalloc) continue; - if (shmem_free_swap(mapping, indices[i], folio)) { + swaps_freed = shmem_free_swap(mapping, indices[i], folio); + if (!swaps_freed) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + nr_swaps_freed += swaps_freed; continue; }