From patchwork Sat Oct 28 21:15:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439576 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 17125C0018A for ; Sat, 28 Oct 2023 21:15:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13ECC6B0317; Sat, 28 Oct 2023 17:15:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C8166B031B; Sat, 28 Oct 2023 17:15:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97916B031E; Sat, 28 Oct 2023 17:15:49 -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 BE9BC6B0317 for ; Sat, 28 Oct 2023 17:15:49 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 99BAC1603E2 for ; Sat, 28 Oct 2023 21:15:49 +0000 (UTC) X-FDA: 81396127218.04.D54575D Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf05.hostedemail.com (Postfix) with ESMTP id A80AE10000A for ; Sat, 28 Oct 2023 21:15:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=d0BEWt0N; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf05.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 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=1698527746; 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=/CvASZfCabc/Ew9WG/OE+/8Wt2GCjn+VDx2yMe2ZiFk=; b=qFiJ+c+VDeOkE5kSUyoH+1UInDEqEczJNivKTWHgRaFM9uHas1mv2dbbZzAJwP+n2fLEMj buL7HHg9FqDRrE6BfwImaXrX/y0/ekDl0GwrvCjAWBnYYvEcdbrfogfnoVKZeTzFyKvW0Q EkOvm6/F0ud4Y32sXswqWbmXuIo3rVc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=d0BEWt0N; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf05.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698527746; a=rsa-sha256; cv=none; b=pWzfyfTG59bpxmx19ZIIozIXIhJip1+FIEnOvrHOaAN8+jG3eE1ZTq6lVdn0U8itABof6S D5Zu9fNgrhMhE3eAz92ti5+v0O0BOzVihgKpPnl9dTCIFkhKOocsphws/+xFpfsCbFNf4f c+Ne1C7iPJWzxfY3e95aT1FdhDRV+Og= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211545euoutp012ad5eba8cbeb8f04ded11836d7ae4761~SYfwvhHRd2663226632euoutp01C for ; Sat, 28 Oct 2023 21:15:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211545euoutp012ad5eba8cbeb8f04ded11836d7ae4761~SYfwvhHRd2663226632euoutp01C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527745; bh=/CvASZfCabc/Ew9WG/OE+/8Wt2GCjn+VDx2yMe2ZiFk=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=d0BEWt0NRJ+q9fKwIT9WCJmLwnptxbJk8cHMt4E1+uBYIQAsZ8HmB0fV81C9HGMNh eplHCmHGAfK9UKuEM3ZkMU9SC9sskXWwIUvxl9OaeWtjnzZO7Uztce5QNGgW6Ll1S3 V0XCcJJ7oPcp//iGDSuKTptzJTpA26oYwVacTJPc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211544eucas1p2dd80d12755f4916b3ddb921b0f269b68~SYfwUtLgi1224812248eucas1p27; Sat, 28 Oct 2023 21:15:44 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FB.57.37758.00A7D356; Sat, 28 Oct 2023 22:15:44 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7~SYfvYfPTw1090610906eucas1p2I; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211543eusmtrp23d56e547237e332334313cc821183188~SYfvX96w-1141411414eusmtrp2c; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-ff-653d7a00f0a9 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DD.F0.25043.FF97D356; Sat, 28 Oct 2023 22:15:43 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211543eusmtip1c2729878b21b7ae72b87f193ecb7dc7d~SYfvKXDWf0467404674eusmtip1M; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:42 +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:42 +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 05/11] shmem: account for large order folios Thread-Topic: [RFC PATCH 05/11] shmem: account for large order folios Thread-Index: AQHaCePog3tlS7SbBUi1hq/vgcoYwQ== Date: Sat, 28 Oct 2023 21:15:42 +0000 Message-ID: <20231028211518.3424020-6-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+NgFjrOKsWRmVeSWpSXmKPExsWy7djPc7oMVbapBvtfaVrMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/Mmu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fqbj6/QTS+Lzf2kG89xbIbi/VvGGbLfajIem O2xv3Pd+fUjos8EHluizHJv9WW7Mkbp08RhbgLUSS3FGoqEWc1FxIgDmdKNI1gMAAA== X-CMS-MailID: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 X-Msg-Generator: CA X-RootMTR: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A80AE10000A X-Stat-Signature: x8nk944wu7dn4bcz716ci8q7jyw4ankz X-Rspam-User: X-HE-Tag: 1698527746-530764 X-HE-Meta: U2FsdGVkX18YHXHyqKIRuYDdOMyMPKKNZp9IN5Lb/3H/oUxbxlStAj54mOaOXgt0c3j84GxsUZx10fQvv2HrJAFKVMCrIsTBFbXcXE+E0w6LwO271zvl+30CNmtBiOhbuHTXpVTd9Zo609QRkcAoIueo/owm89ig0GG3XXu6yLGoKt/9ijHkJgSoViQFSrRAWqn9PyyO/ETA5zyd8U+32rnT3m74Of/iahQEnJLJcig7vw0ZgNAbra2wWrCSraCxSS1VZCFcdWV350PxmO1Vexeq55q2exSoTNDnG8rroCbQWQZ+J9F0356s9eLY2vyfUZl4+SNcH3IuExbiakUf5pOVrbu/hNQuGzmJ2dUcpPt3mMLOg8HtE2b5tGsO0dX4c60Lgv223E+n1npzgptHgAzZKvhGBH3yABk9fdtPjcJX52EPKAS1NDTbNPLjwIT39jwAFhxC3JBgiBEmH098qJ/tHqa2lmnNSRQ8ch+4bofwi7za+HqbcJqRmEZcWniF3LnuutSgr30dCNIPinFZrc2wXcS3cYVryecBF9IwR3TOU2LN6Y2EKEI6UkDdKx1fEvyFKc36+9DXbgtRkeokxXled5gGQ7PzUVgyQc+Tbjm1bqS1bpMkk5UpmgY8pA6tpoUu2AFD1rwswk2VEmN75Ssve966Ydbq3yqLUoGSUcsKeiowbm3o/K5rI5+1zzBm0XOj8GjX6J8CVnxzxNSqwevB9Y7Xcp1smJAq917696gYrJ9Z5IdhOo96kbIil9mGybXCCIPeMeSP6xnvFVK9dTEDLIsF8ZriAc9jHA/9nCu9DuHsEczpiCwVASypxgK75cnNiF4RceFiItZ5NiJmWGTUqa+N51WfoHPSWjX2JP65sZK17r5pw1mSlyNRrbQ0y+1uAYaTjYQgyIPFjyUeCYGVY/WPQcYNUto0kr+vxRw4L4rVmo8sgr6YYSsTUlJMIw2OmISv/Vqh9FT90rY +d4GZUpn IyWdr+kAGwmf8JXvdUaMrFFDoyTKVwbwXEN0knPWgPi0IIipLA9njgcfbXvyGRoU9kAN1aHqx4uJvKzneSnVd/MkQZY3LQOo5DGL3qc51fxLNxXsRK4W1UPFMC/tDZUfh5HQSlbnoPJRBN/4DUahnimpfMkwad6JWtZKz 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: Luis Chamberlain shmem uses the shem_info_inode alloced, swapped to account for allocated pages and swapped pages. In preparation for large order folios adjust the accounting to use folio_nr_pages(). This should produce no functional changes yet as larger order folios are not yet used or supported in shmem. Signed-off-by: Luis Chamberlain Signed-off-by: Daniel Gomez --- mm/shmem.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 9f4c9b9286e5..ab31d2880e5d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -856,16 +856,16 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, pgoff_t start, pgoff_t end) { XA_STATE(xas, &mapping->i_pages, start); - struct page *page; + struct folio *folio; unsigned long swapped = 0; unsigned long max = end - 1; rcu_read_lock(); - xas_for_each(&xas, page, max) { - if (xas_retry(&xas, page)) + xas_for_each(&xas, folio, max) { + if (xas_retry(&xas, folio)) continue; - if (xa_is_value(page)) - swapped++; + if (xa_is_value(folio)) + swapped += folio_nr_pages(folio); if (xas.xa_index == max) break; if (need_resched()) { @@ -1514,7 +1514,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (add_to_swap_cache(folio, swap, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, NULL) == 0) { - shmem_recalc_inode(inode, 0, 1); + shmem_recalc_inode(inode, 0, folio_nr_pages(folio)); swap_shmem_alloc(swap); shmem_delete_from_page_cache(folio, swp_to_radix_entry(swap)); @@ -1828,6 +1828,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; + long num_swap_pages; swapin_error = make_poisoned_swp_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1837,13 +1838,14 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, return; folio_wait_writeback(folio); + num_swap_pages = folio_nr_pages(folio); delete_from_swap_cache(folio); /* * Don't treat swapin error folio as alloced. Otherwise inode->i_blocks * 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); + shmem_recalc_inode(inode, -num_swap_pages, -num_swap_pages); swap_free(swap); } @@ -1928,7 +1930,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, if (error) goto failed; - shmem_recalc_inode(inode, 0, -1); + shmem_recalc_inode(inode, 0, -folio_nr_pages(folio)); if (sgp == SGP_WRITE) folio_mark_accessed(folio); @@ -2684,7 +2686,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, if (ret) goto out_delete_from_cache; - shmem_recalc_inode(inode, 1, 0); + shmem_recalc_inode(inode, folio_nr_pages(folio), 0); folio_unlock(folio); return 0; out_delete_from_cache: