From patchwork Mon Aug 12 07:42:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13760268 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 B056AC531DA for ; Mon, 12 Aug 2024 07:42:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71C6A6B00A0; Mon, 12 Aug 2024 03:42:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB786B00A2; Mon, 12 Aug 2024 03:42:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 592806B00A3; Mon, 12 Aug 2024 03:42:28 -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 390B36B00A0 for ; Mon, 12 Aug 2024 03:42:28 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 87F2116127D for ; Mon, 12 Aug 2024 07:42:27 +0000 (UTC) X-FDA: 82442800734.04.A831DDD Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf06.hostedemail.com (Postfix) with ESMTP id 6B1D918000F for ; Mon, 12 Aug 2024 07:42:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tU8ArFSW; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 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=1723448511; 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=71u6PF0T766CyIr04AjwEpJvSI8v+1Ntw3LK3owxVuQ=; b=QETa1ru/JqroSTflm5FS7CDTDaRMqw0VvSiHYy5jbRsi9TnrrPrzY58kIFF2cVPxdA6zZ1 AxZEgOQ8no3JHLvW60avZdHXk3ANnBr3QATXjHTrdEIEZnVmJJm5Evm+m1tzPojifwP5fS s5vcwP3M/QOjUqfzdJSlV1JLksH+aew= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tU8ArFSW; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 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=1723448511; a=rsa-sha256; cv=none; b=VaNINW6sYye4DPnSkdDFGNrJwSBjyVeQkkQTCBkph0+xs4tgNLjw/rThgwLvwbsdS+y648 hrxrI+8AilsuZcB7Ol8PkSaYvLhCoyXvjGlVf/eiFJNBFh4mA7oYP7VMoT4pnQ7StgzF8p 5GDQRYEWT/PO/29jheN+Hk9Mq6VtrAA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723448542; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=71u6PF0T766CyIr04AjwEpJvSI8v+1Ntw3LK3owxVuQ=; b=tU8ArFSWaw0R/n1rHBU30YyW2KKq4GhtVbV10IOgZ6nenZ0Q4CYRtGJpd/VYSErwu6tVLLA2Vp7fuCq0zFgwAWp5iOE0xYl/fkB2WB92SYf9Mg4VzpRd41rmQU8+6PyZMzm2dk+jllh5GViOiIWE2FlT1+m4yrJx6qTF/bsq8e8= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCbAKOu_1723448540) by smtp.aliyun-inc.com; Mon, 12 Aug 2024 15:42:21 +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 3/9] mm: shmem: return number of pages beeing freed in shmem_free_swap Date: Mon, 12 Aug 2024 15:42:04 +0800 Message-Id: <9623e863c83d749d5ab407f6fdf0a8e5a3bdf052.1723434324.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: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 6B1D918000F X-Stat-Signature: 8onjpfuntbmudrnutuk69r76i3g4eftg X-HE-Tag: 1723448545-936321 X-HE-Meta: U2FsdGVkX1/mqd41QKfcfh60XgPhbUw4YHkDTuwrTsCSl02dNOL9iko5m02BxTw0TDiwrBmoJ6kjQ4Z8QswoSQvAd+iXYA6sy6nvgo2X5/67xMDYTQAPWntNSQcIiNRSqmO69OsJrkR2DczoLG7kVIAWk9sNI1SXdTsuwJrUIP0nANO3Hqa1Yy/bowaMjpRb5I0RiX3aKo2E5+dODn3UDme5bKFJRNApENLweSw2xZX32bdrfS2Cr5fJppTt7uag3QZDjk9VflfNHqPQeiYUJLM8n8YiivJ5HlLARFnl6QlUHchbqMi+IFPZ59GoLYo9GPt01AJTB7/pZNGuV2Iw67fcBvVkth/IfK4uRlJOlISJnh2bl5DPY5HKBx1yectUA01f8MZ7VLKbZHymw8rBTEUcAxOun3cwLuXsew+CI1q9IPgzh4Zy4lSA8grqEX57G1zzwvlwoilU4uhDKtRV71Eh1W7YKZ2YwFwJPYBDpzigFdXA276NeKjChj1wJ8sJqkePQGdOII2jlQJUIXzF6Xm0QXv7XR50TBAoj1a1dqHiw70akdjNpYvWsElkaMJlkFi1Y9yxTYXJ29Ibuz+xTtV1Dk6lLwmuIXFG9UYlI9gN4jyuFMuBskHOM7tZzdrGW+vGlEsa48BloOgE3flmEqLe+XUpsrYmGrwWAwntEiAi7gaiCppLbFEp7etpWrj1gRhexiA7pPKFnUV2Xk/xwJ4MUOyDjyMje4scGvYtzk0LwP6uEzt+GAJOoZ1lT/UrthwDb9F6fQLEg+mQ436hjXWlALxlc9iEGBOCp3lfGdm2iPM3pJuSfgFtFk56PYk95vqndMrshTW9sYqUaFP2sDAW3PLY6XvDDq0z7PcB9eLg/WeTGb+VO20ZFfyTE2XulMqvTR+/xkGLTuysKga5eaA8XcxrunSz4sIfXN/oh9zs0LbRWEcBs7a6/JI1YTxBC7fgD7KqlscylkQVVY7 dUkVmdIV wNFUebPNpP7i8OiG6YPB2ChLZKOoJMXumKq5ZqQ6tIi2q0IehrKhMXMw5xNEiEKI7eylUBo/MIMmObAYnZbJCd1k2TX16Fajg36o0+pFSVvVtQ9AF2ERc4VdoJ73qrbOJyGmrz2aNNSQAmknf0oHbGqhexFegc60DRBDe70YaK9I8MZDdejeoFOMVZfAY3/yuig/Y06XXrdrQrPOQGYMdCIPTs2PQS/iRbRyOX1CJFcY48m3IGRLaYaDcFxEjy7RjMMjUQUSbBMbwsIyuKePw4C0TUpf8mIddhZo1aGDkxvVKOhU5F6JkhBI8l+1GkMrh430GkHbCFIPF2jeehdDXu/JuKnI4c7GP6MALJ48VC8Ts/mg= 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: 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 02fb188d627f..d0d54939da48 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -856,18 +856,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; } /* @@ -1019,7 +1023,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; } @@ -1086,14 +1090,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; }