From patchwork Fri Sep 15 09:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386770 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40229EE644C for ; Fri, 15 Sep 2023 09:55:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234083AbjIOJzm (ORCPT ); Fri, 15 Sep 2023 05:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbjIOJzl (ORCPT ); Fri, 15 Sep 2023 05:55:41 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 427733592 for ; Fri, 15 Sep 2023 02:53:12 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095134euoutp0195c735f76156be19292a91b8fa00f5fe~FCbHVZ9600696306963euoutp01F for ; Fri, 15 Sep 2023 09:51:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230915095134euoutp0195c735f76156be19292a91b8fa00f5fe~FCbHVZ9600696306963euoutp01F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771494; bh=nTKXGiIiML3QQW/w2E+mOtcZhHyvpI4/kPyFKr8+glQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=KI2kOdoS2yg7Vh86md6sPK4vwrtx1rr8lkcPGelzTYN+V1wDwjhXbTPHfi1ayADmq SnuX6aSN1YRX5kU7TmhzwLcmfDlEAs/J/VhdqKM/lMU1vn2PXUcHsE0QM7qAuv739c MwIfQURAnIrUaVFqn6+icPbpvOOlVSZ/rhM39T1M= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230915095133eucas1p1fc05405567bd735c07ff213d3dff3c85~FCbG_4jQF2007620076eucas1p1T; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 63.AA.42423.52924056; Fri, 15 Sep 2023 10:51:33 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f~FCbGdpbh00862308623eucas1p2c; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095133eusmtrp2540609b9602d103cb0a1998aeeb2d1b1~FCbGc8gqX1712217122eusmtrp2_; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-26-65042925ea5e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 5B.3B.10549.52924056; Fri, 15 Sep 2023 10:51:33 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230915095133eusmtip145b39d48e2d4c2b2f0f476f141a1971f~FCbGQl2U92594625946eusmtip1i; Fri, 15 Sep 2023 09:51:33 +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; Fri, 15 Sep 2023 10:51:32 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:32 +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: [PATCH 6/6] shmem: add large folios support to the write path Thread-Topic: [PATCH 6/6] shmem: add large folios support to the write path Thread-Index: AQHZ57o0gOj42/h7V0WVSDdaHJaWqA== Date: Fri, 15 Sep 2023 09:51:31 +0000 Message-ID: <20230915095042.1320180-7-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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+NgFjrKKsWRmVeSWpSXmKPExsWy7djP87qqmiypBpfmq1vMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6M/d1mBbuEKv5se8bWwHiar4uRg0NCwETia5tOFyMXh5DACkaJncsWMkM4Xxgl9t9b xgLhfGaUeNZ6mxWmY94rFYj4ckaJoy1b2eCKfmyeDeWcYZRY8vYn1KyVjBLbZr0EmsXJwSag KbHv5CZ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ws9IxNLPUNj81grI1MlfTublNSczLLUIn27BL2M/d1mBbuEKv5se8bW wHiar4uRg0NCwERi3iuVLkYuDiGBpYwSRx/fZOti5ASKy0hs/HKVFcIWlvhzrYsNougjo8S3 ta9ZQBJCAmcYJfo+VkMkVjJKHGvcBZZgE9CU2HdyEztIQkRgNqvE4cUdjCAJZoE6iTXPZgEV sXMIC7hJrNEHiYoIeEu82LmEDcLWk3h/6A1YNYuAqsTnXT/ZQQ7lFbCWWH8rG8QUAjJnTfcC MTkFbCTe/ygHKWYUkJV4tPIXO8QacYlbT+YzQVwvILFkz3lmCFtU4uXjf1Bf6Uicvf6EEcI2 kNi6dB8LhK0k8adjIdS5ehI3pk5hg7C1JZYtfA02h1dAUOLkzCcsExilZyFZNwtJyywkLbOQ tCxgZFnFKJJaWpybnltsqFecmFtcmpeul5yfu4kRmJK2Hfu5eQfjvFcf9Q4xMnEwHmKU4GBW EuFls2VKFeJNSaysSi3Kjy8qzUktPsRoCgygicxSosn5wKSYVxJvaGZgamhiZmlgamlmrCTO 61nQkSgkkJ5YkpqdmlqQWgTTx8TBKdXAFGb97Euc/wHZOwe2H2d42C6wT9inRO7LFrv2jz5P F+jw6Pd+rmiR+vWiN6yJcdZj/UWebt99mZZpm3FUc8u9iHs94eG6jMblr2Q0rq9tOuBysvnq HqNDv/XmeUz9sMmm9fl6u4v7WCZt+nauo1l/yR1BpU1qlornQqTCTdjnZiWU1r2rlODnvbzW y/y5mNgqoQcvG6a8O3E48N3Ed//ZoxIdvsRvEP6t4OX9WH7C2uygo9XeTnlK3J69P5QXenPc YjKPy5Hg+z9xZ/CXbD2xu1ucfZzSnzWK+9ucKK07vLfk5Url5KaYKNUCptfdS40XvdXc07yx feHuG8fPJVYcFP399u7Tmcvfdkzx73g/VYmlOCPRUIu5qDgRACdVhs7SAwAA X-CMS-MailID: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f X-Msg-Generator: CA X-RootMTR: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add large folio support for shmem write path matching the same high order preference mechanism used for iomap buffered IO path as used in __filemap_get_folio(). Use the __folio_get_max_order to get a hint for the order of the folio based on file size which takes care of the mapping requirements. Swap does not support high order folios for now, so make it order 0 in case swap is enabled. Signed-off-by: Daniel Gomez --- mm/shmem.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index adff74751065..26ca555b1669 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1683,13 +1683,19 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, } static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, - pgoff_t index, bool huge, unsigned int *order) + pgoff_t index, bool huge, unsigned int *order, + struct shmem_sb_info *sbinfo) { struct shmem_inode_info *info = SHMEM_I(inode); struct folio *folio; int nr; int err; + if (!sbinfo->noswap) + *order = 0; + else + *order = (*order == 1) ? 0 : *order; + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) huge = false; nr = huge ? HPAGE_PMD_NR : 1U << *order; @@ -2032,6 +2038,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return 0; } + order = mapping_size_order(inode->i_mapping, index, len); + if (!shmem_is_huge(inode, index, false, vma ? vma->vm_mm : NULL, vma ? vma->vm_flags : 0)) goto alloc_nohuge; @@ -2039,11 +2047,11 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, huge_gfp = vma_thp_gfp_mask(vma); huge_gfp = limit_gfp_mask(huge_gfp, gfp); folio = shmem_alloc_and_acct_folio(huge_gfp, inode, index, true, - &order); + &order, sbinfo); if (IS_ERR(folio)) { alloc_nohuge: folio = shmem_alloc_and_acct_folio(gfp, inode, index, false, - &order); + &order, sbinfo); } if (IS_ERR(folio)) { int retry = 5; @@ -2147,6 +2155,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, if (folio_test_large(folio)) { folio_unlock(folio); folio_put(folio); + if (order > 0) + order--; goto alloc_nohuge; } unlock: