From patchwork Sat Oct 28 21:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439577 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 2A2FAC04A95 for ; Sat, 28 Oct 2023 21:15:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 252B76B0313; Sat, 28 Oct 2023 17:15:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D9256B0317; Sat, 28 Oct 2023 17:15:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 004416B031B; Sat, 28 Oct 2023 17:15:47 -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 DA8136B0313 for ; Sat, 28 Oct 2023 17:15:47 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BDA21A038E for ; Sat, 28 Oct 2023 21:15:47 +0000 (UTC) X-FDA: 81396127134.18.1F4797D Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf10.hostedemail.com (Postfix) with ESMTP id CF885C0003 for ; Sat, 28 Oct 2023 21:15:44 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=VYigV6I+; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf10.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698527745; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8ofABjUQrTp1kzdTCcGf7BUaZhuxx/1pi/TdtpYF5D0=; b=bp0ClbJtrNGOqIhv8FS8oYjgxVmz/3HOoidPzNgYIeg00th2hj/a/XAEVjkqGrkEeL05ob Tiq8o7mkXCsI3+0OiJaXxQOA8uR9O7TqAyd40Xiw1+PjnNFp7gsB+152TW3PMTuINi0gPO 3DRwohrhRI4iYqeIBHseX+vW97U2hnc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=VYigV6I+; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf10.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698527745; a=rsa-sha256; cv=none; b=nK5OPMLlqz2NK+8yMksDoVLfQKuURkwwzqZWVvqRe9rlm5832Hx+bySCXADiuHh3bZ2bjh p2uDwsj7WdKYHFqDpAZqeYpqeJpTmYe0r+rqQfW301/Iuyr+nSxTm9kHjwqSpRsV+LtLPk 9plcniyhtzGcF4P4ICJIC9fh506jrew= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211543euoutp02d8a62e552e322107cf5216f0d52ee92c~SYfu7t1aY0890208902euoutp02C for ; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211543euoutp02d8a62e552e322107cf5216f0d52ee92c~SYfu7t1aY0890208902euoutp02C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527743; bh=8ofABjUQrTp1kzdTCcGf7BUaZhuxx/1pi/TdtpYF5D0=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=VYigV6I+Xlg2f6kz+xnces7qO2f0nE5tR01Ol4rTD112qHEJhBXjL2IHc3c+wZLc0 4J5CPLxTCXq6Ef4vaHJ1aZ336J5ZiBJuzTVHj3DUHIMh8LafS+j7OlzIeMZQm0qVAT WE449o7Hrm2ASSKGptRHfU9DYe+D1wjPkqA1i5Rs= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211542eucas1p241e7ab5f2da4fdfc2cba9e250271dcbc~SYfuALImE1087910879eucas1p2E; Sat, 28 Oct 2023 21:15:42 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A1.20.11320.EF97D356; Sat, 28 Oct 2023 22:15:42 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f~SYftgbGJH1224812248eucas1p26; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231028211541eusmtrp14898d07da8c7cf9ca684d016181d49c0~SYftf57WW0755507555eusmtrp1Z; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-85-653d79fec53a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D1.52.10549.DF97D356; Sat, 28 Oct 2023 22:15:41 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211541eusmtip17d9fe4ecde792d45fb6ab59803d2f652~SYftVSUg60467404674eusmtip1K; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:41 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:40 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 04/11] shmem: return number of pages beeing freed in shmem_free_swap Thread-Topic: [RFC PATCH 04/11] shmem: return number of pages beeing freed in shmem_free_swap Thread-Index: AQHaCePnyXBbRf49wEefJYEMRSVIWA== Date: Sat, 28 Oct 2023 21:15:40 +0000 Message-ID: <20231028211518.3424020-5-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFKsWRmVeSWpSXmKPExsWy7djPc7r/Km1TDU6/4LCYs34Nm8Xqu/1s Fpef8Fk8/dTHYrH3lrbFnr0nWSwu75rDZnFvzX9Wi11/drBb3JjwlNFi2df37Ba7Ny5is/j9 Yw6bA6/H7IaLLB4LNpV6bF6h5XH5bKnHplWdbB6bPk1i9zg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GU5r+sVqZ49rt4lbXhhhMdbSvOqj3N330w1vbT/trU /+EGZfWKps5m5+wP2Kdt0K769dNqyx8lluKMREMt5qLiRAAYunQX1gMAAA== X-CMS-MailID: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f X-Msg-Generator: CA X-RootMTR: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> X-Rspamd-Queue-Id: CF885C0003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: u9h4w94dw6sgz1f9yhrddkcyj4mzd15q X-HE-Tag: 1698527744-156409 X-HE-Meta: U2FsdGVkX1+sG+SvmbYvlemLkofR5BUMnJ6b9HnDDcGMOz21RElH+MY/p6fhXV9Zn/WbHJLheq8AW8Kz3zZl1KFl0rWduLouKRMdHqB7YPJBRpucfaJx+xkQvls0KN5xCJYV5Qak4kRbRViKC7CXGnVq8c7K67wS+TXdlOcqQ+Ca42d/Y/CTLOHdXRihqiosJb8uRkf5kyhyBYn9WNEqdV6N3x+8SU/Ehs6wQAOgsCu1pbrQiLDCoWHlWd/18X1W/DKcQg+feF7d9fysg2UuyisJPww2nkLDCxUxL0q0Bk3bF8C9V/UVukp3fYvska6apluxp11JNCz+lF7DQzwSF6xBal1CImzKq+FVQuD/bAwD2GvPbGlmB5MOm+MzPkuULIYeHJBiqHleUUGOf58FOMViCZ/Zg5y1KTYD2EIbIazmFIHdvXyQj24yc8wLD/Hn+xSD5OdthkXvrMXDYybukQrjY6LXpQ1BwY3vlHwaBUVarZFe9DwiaTuSXtjSnvxS8LEZsO9AjQqPcss9KivuPAo0M+LchWaRhvIJ1+zKQ7queyoXNGEqgUbIDVt2Q5x1sMtjvC5/dtRvpXPqTbawvG2uD3NPs/ToN5wx2hghhmS7A2mfk4SleyBokSdKmzC1jb8fVm3MkqRpFyUmYrDpHzIZoQZkCCWYlS18XL5p3wCdyGOLzxangRj0+YTJzkVDj8IDmHe7tdddV778AuWGWP5sQjKfHpI+KCB/OBCZlI3P0EKrpgKxGK7iI9ma4Hoa/fWWg7Cyqv4fFTY6BBmWVcILGvGhwx1OAhsMAMAng8KnZ1DivQGw6IMD25Qf6jl0QhgxUUxb/8XMhYkQ21bEaX1yK7OfLMdJh8+LU3QhfAnRIqGQ9hiJWeD9zelHoSu0Bqi6Eot9r6OQNaIXAQKfS1R9Qm3ciyCJPZXDzPCdycz8jZ7I5h/e4sDMU1OaG7PjiGecoJxSUTGWMayzxJw P8JPo0L0 NSPWjUxVdvSL99DImQpGINQbag00WO3Njtj//9k+6XK1Ca70dRl77uPsWi0xXCWenv/INTrx9hTUnceZJwjY8Vo3nx5SitYlRPK3llwt4fULKdQrRojpKJZOwjyZ5hkodCZTn6w6hdPAeF8isBvPyKj3tFHF9ZNM7WBppi+8AVN1U8e0lTYWQN+urZaA/wCv/gZ1eYSZDUhgL3rASr4m8zrmtaQ== 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: 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. Suggested-by: Matthew Wilcox Signed-off-by: Daniel Gomez Reviewed-by: Luis Chamberlain --- mm/shmem.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a2ac425b97ea..9f4c9b9286e5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -827,18 +827,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, +static long shmem_free_swap(struct address_space *mapping, pgoff_t index, void *radswap) { void *old; + long swaps_freed = 1UL << xa_get_order(&mapping->i_pages, index); old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); if (old != radswap) - return -ENOENT; + return 0; free_swap_and_cache(radix_to_swp_entry(radswap)); - return 0; + + return swaps_freed; } /* @@ -990,7 +994,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; } @@ -1057,14 +1061,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; }