From patchwork Mon Aug 26 07:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13777237 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 F159DC5321E for ; Mon, 26 Aug 2024 07:02:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 020D46B034D; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEA758D0029; Mon, 26 Aug 2024 03:02:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D15E26B0351; Mon, 26 Aug 2024 03:02:47 -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 B06EC6B034D for ; Mon, 26 Aug 2024 03:02:47 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 69496A90D4 for ; Mon, 26 Aug 2024 07:02:47 +0000 (UTC) X-FDA: 82493503974.24.C0DCEC6 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf03.hostedemail.com (Postfix) with ESMTP id 3CA852000C for ; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=lizetao1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655702; a=rsa-sha256; cv=none; b=ZZzKcIO5cIKY/r0ZSCuRWC8foKiXmDzFqIzWvNuxJkgLqQNmxm26X09BuL3FKGH04agZSN WHek8+wSQheHxGu8v+ZexlQKO7dm4/5oNqeF1LVt35FOrumGOBGECLxNN92H+HWWjh6l1v XzJ8sjEMJ2lY0Tv9dSyroIP0TbjKq54= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=lizetao1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724655702; 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; bh=g8KB/rvBQQHioUECx2RXIz278sZny2ahR9UOpdiuK0E=; b=TIqCY5Tv17hzKgJs6IvvPbQtqcDvoozOft3GK0Wwl4CB9/dICi4eAbBAOnFuSLP5h9OE6o Sn+XG7JV1PABo4c4zML92N6oCulKABWJk8alm4/10qwyztzXMQWIcOuo085Wlgd4UhpuPQ KMz+JXKR9YEb/NpQolDuqdzVUK/ijAc= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WshSn3FMHz1j7JH; Mon, 26 Aug 2024 15:02:33 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C6C851A0188; Mon, 26 Aug 2024 15:02:41 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 26 Aug 2024 15:02:41 +0800 From: Li Zetao To: , , , , CC: , , , Subject: [RFC PATCH -next 1/3] mm: Support scope-based resource management for folio_lock/unlock Date: Mon, 26 Aug 2024 15:10:34 +0800 Message-ID: <20240826071036.2445717-2-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826071036.2445717-1-lizetao1@huawei.com> References: <20240826071036.2445717-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) X-Rspamd-Queue-Id: 3CA852000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7q65raxzbqnrs988opijxyn7j53aok7n X-HE-Tag: 1724655764-222353 X-HE-Meta: U2FsdGVkX1/II6PtsVKCQ235DkHfa9EmauENF4Qli1IPmbm8ekw3m0d8lIm1WDc1A67JoMdGG5SsrSXlC94EXSbWOzDIOSEr2Y24xDcp2HBvEY/yQkeatzBsNqalFitMFOKoKn3aa4HA1BWq+aiFzymIQBXQv9GYYozOlRONBE6sEi3JjfSUfA87lbVun/QjCCx8hYqWtQUQfWvk2H1ETh4QRCO805BRsGGHHyifV0z3exBq0j1xTp/IRbJo34KvF3ZfU8dG/O5w0h7ULVueI9tZIBzZRP1Rh3Sin78OVW3SxEKKCUDOr8xwaUMQSimLVWv36fMWs0X4hjNuXRirsasx5Oy9q4+At0SCoukzWe75wbo3/SssBPiXrBQ9aS/bQLye01Gqoz3l4TmzCpBXQqKFWBcGyiVhpSTM6dtV/vDNB7KSORTFQOUQzG1UAhNLMZ0hwoi6eII5EGUqdGyqCEs8oRK9VJHjtMV5Is+YAiPgjpPzfTY4EBJrg+tbgbEPsliB1qLo9erquJgKyn1mXnepCjxh6Q39ZJCJMaS5fa5ASfva07PEa1VE7iJuQwjTUV6o+d9sS1i8O3WPM9fK8SIjnBKEQw3nrp2R9VtgW1bWy1vbyBSJlCSDfnqrEHS5ln7lSjyy6WaPwJ8w0MUsrf53fH1i+5MScImxGmoRseBWIJEdMsq+cZqHcmji3CCxzHE5JQHCx9qcgivD+jwnpO7s/7y7W1pSR15ocXuSUJw9oalP0QgQUsigGmSTchvWgxwJ/Hx/t9l/ins5MjtQmf9K9VvQUa+cRKHUx0l+fuiPF+IvA1MzyVKIS8e+FXcuxkm+eEIWmm0/hnnBiffAhTJWuSDj6OaAjqhFceQ3daLZowT0TSzq9h2jbBRYB6VqxfESdWZIkmblgmm9ol7juQWxdaoDWiqWhkfQHP0aYmP52HfFGMAdw49ZjGKAco4nYrFIbN9CnWsiPqnA8Bm nDMjWxWp kS4aO9EYFkTZSK/bU611eIRu9G/lC4csgyNutFtyrWUqhaCIDK6M5ynrrb2G7ZmlWpQEWquqqZScYi4Ms4mnS84tDZa2T/i3+xXiPRg9nLgkqrm1EAFXW9xI6zJp5XStEOXO6lkN/bGiqFzgf0EBFjU4720/MnEuE1pUDXsJhI88QahOz1zZVOqHX57g0s6qcWCL/ 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: By introducing the DEFINE_LOCK_GUARD_1 definition, it is possible to lock and unlock of folio's lock based on scope. At the same time, the use of folio_trylock is also supported. Signed-off-by: Li Zetao --- include/linux/pagemap.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d9c7edb6422b..ed1831c115cc 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1537,4 +1537,8 @@ unsigned int i_blocks_per_folio(struct inode *inode, struct folio *folio) { return folio_size(folio) >> inode->i_blkbits; } + +DEFINE_LOCK_GUARD_1(folio, struct folio, folio_lock(_T->lock), folio_unlock(_T->lock)) +DEFINE_LOCK_GUARD_1_COND(folio, _try, folio_trylock(_T->lock)) + #endif /* _LINUX_PAGEMAP_H */ From patchwork Mon Aug 26 07:10:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13777254 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 06CDCC5472D for ; Mon, 26 Aug 2024 07:02:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E29636B0196; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB22B6B019C; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C04066B019A; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 93F9A6B0183 for ; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4D635A90D4 for ; Mon, 26 Aug 2024 07:02:48 +0000 (UTC) X-FDA: 82493504016.28.27D5647 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf16.hostedemail.com (Postfix) with ESMTP id 3CDF418000E for ; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=lizetao1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724655723; 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; bh=IdYck1qNecS5dQgVKhiAyjVtc+jOS4S+Yl68bl7Ucxo=; b=7h2t/ZyXEke5tFg5rPQNYX/9QLb7+Js9jXARdmq+K/E+zOnnePGcaPJ9+y90lRAUMGSgub qD8ZRlWzUmCwt/XUtd+4RU1OBf5vBczWul7qrnTmWVpqjbaVRV3WXyZVzVEXTYZweJBhuW omex6jjQ6vg9kwtormlFWI9liTBL3JA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=lizetao1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655723; a=rsa-sha256; cv=none; b=k8tlb7MtnStFtwSckjUCb+x+Wf/zqnmyMVb7R/hgIZQ/Nk9qGQw+ggqKXcSyckIOxhaXzl PhDkStMqpfq0r6CSMBHm9nqt2HsB4f05eUFA0410s0oRVoUdV9g0xsDYEw2uGMRXwRqYrh 5vRUCvmAK9/OpOWuL3wnEW1ndjFpDDI= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WshR33d8NzpTNf; Mon, 26 Aug 2024 15:01:03 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 3E8061401F0; Mon, 26 Aug 2024 15:02:42 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 26 Aug 2024 15:02:41 +0800 From: Li Zetao To: , , , , CC: , , , Subject: [RFC PATCH -next 2/3] buffer: Using scope-based resource instead of folio_lock/unlock Date: Mon, 26 Aug 2024 15:10:35 +0800 Message-ID: <20240826071036.2445717-3-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826071036.2445717-1-lizetao1@huawei.com> References: <20240826071036.2445717-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3CDF418000E X-Stat-Signature: x1j5gu3r7y48gjw5i1d6xdheorxtzayo X-HE-Tag: 1724655764-209843 X-HE-Meta: U2FsdGVkX1+7wGbXhs9V9LSN+BOUQQyyNJTYj+DwLtYawhdTkfbQE9RY00cyAIK3BG4Avth6c0mK/LSk0tIoH7Q22cTGJ/COwKlCeq+GQcg0oXqwdpHmUScsGOkYFk6ttaemFZhbsRKTmMiJAHvaVWUbmzkPIhgWfK8JHmFvCDPeCcGFV3YBeCWKGQzNzKZJ+3wCWmCS5WcZBBV6b/O1J/mIKXVXbICKY5ahrlp2SGMexPPDgz2BTkSfKlnF5/qz+EQ+2kETNo6CjX1h/FqyeqkSGnjNdJQbO7FjNz68v54BJfJEuzuFc0LhPQ7rq2e/hPeR6osKTB9S6fE/qtBMvIAFKJoC4keJRQgwQFjaUYI0Inz//aAKJjjGlZP2TvlMY5a5NErtTxUtcKj2coIx/cPeBD1RAGUMxXpqNKTZbmoWYUNPvKt+sXqJZRhoVMYF28YObBdmml3BtiYNUmjF8xX8XlTr8BeIzTy2CNMsNUX0sHGP7lvvED60sy94D4Tfk3c6kjKZG3+HfHvxlSipOQpoVBgLjvUClWxltxdEZq5tSPjYLpa1N/tvr5ra2IaSK3T2J8iH7C1LULZtjNsSqnL0WQdpxAID9MMJiIeG//BTmQqmkDLeFWofrx+0QteKWAelTl0qwPb3tL3IZ9SHmULbMFggU/mKw+eh1qHNfk8dgz3vAGXk3E6WqG4hCZvYyxQSSElgeMUHX5OSf9CPSwJt2mx5H6aCzh25c5FAWe3YcGbnsPyi+gKtH7rdAsGQ2tIz+ptWAzjHdY6w+7tpisn1dZnkwiuRkrNl9FOcqYbufWR/vQ/nelid1OdfegoXBVOOC8f52Iw/EbrhY4B2pyqmWqbe/kvd2uyQaj0Fs+npcoSYu3z8yh5jzR2VaZvWg50al+C4xvYWYprmFCEZBaiYUiVS2vc1TYW//Aqt4lC7ct/CND/AO1KqLm8+jg18kc6HlFMvKMniY7oS5GD AX4eYVsD GiEKtJ7Cy+jVk151FmpB4IGTGura58CUEua6V2rt/Vj/UW0Ns6LqLVJXq6lWYa/+c45KWQ0ekb7sMReiKXzjPECb4+7uVPMr1c1yn8x+72nrQeEhc+L+YFtxI8TQBjavSsQeX4/uI9lpJafkAVoM4eQtgOahcwOw1Nl43l1Bf9DkOZkt0o5KiVq0cLB6WIo04oKmEoPIOVOhewL1G7uz8spn3rdGR9i6wUwA8 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: Use guard() to manage locking and unlocking a folio, thus avoiding the use of goto unlock code. Remove the unlock_page label, and return directly when an error occurs, allowing the compiler to release the folio's lock. Signed-off-by: Li Zetao --- fs/buffer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 45eb06cb1a4e..77ab93531a33 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1740,11 +1740,11 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) * to pin buffers here since we can afford to sleep and * it scales better than a global spinlock lock. */ - folio_lock(folio); + guard(folio)(folio); /* Recheck when the folio is locked which pins bhs */ head = folio_buffers(folio); if (!head) - goto unlock_page; + continue; bh = head; do { if (!buffer_mapped(bh) || (bh->b_blocknr < block)) @@ -1757,8 +1757,6 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) next: bh = bh->b_this_page; } while (bh != head); -unlock_page: - folio_unlock(folio); } folio_batch_release(&fbatch); cond_resched(); From patchwork Mon Aug 26 07:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13777253 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 8009FC54732 for ; Mon, 26 Aug 2024 07:02:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 613386B0138; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5766E6B0183; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 293286B0184; Mon, 26 Aug 2024 03:02:48 -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 051E26B0138 for ; Mon, 26 Aug 2024 03:02:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 72BF5120C2A for ; Mon, 26 Aug 2024 07:02:47 +0000 (UTC) X-FDA: 82493503974.20.6741BC0 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id 4B3691C0007 for ; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=lizetao1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724655681; 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; bh=JUX32vWtEN47faa/ptZN6HFUlLvoC/tlNsERX+PbF6A=; b=y64X4/9F+XOTQTG4SRhDcRsb8nu0OQ82ceG4HjWufTGGIK+mVhCfFl53Tip8FBG49l3fYP xemLSY4WFC919mkOybDEE9cVfJZ+kh876KhtnibkAJcypES0AhmLWVxBmj9VbSbP6VX7nj XLC5hXSMn3VACUICgPXlOWlhqIi+qOQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655681; a=rsa-sha256; cv=none; b=0AEFPL6S7aixyQNAhacGBKKmUXUtc9wT7l8PEGhCUnSbHERyDPo5TL7DHDtY/5Z/PL/4sU Os8NR7SmVZR+ylDoDt2xnPtFGL1uVj0kbuUk6XoAmL2v8j7ZQSnwhqjLMKWqkR70WobxjZ RDzD50yTSe8yto23OS8wtOhXroIYyDs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=lizetao1@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WshS52JC7z14G6b; Mon, 26 Aug 2024 15:01:57 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id A0B5F1401F0; Mon, 26 Aug 2024 15:02:42 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 26 Aug 2024 15:02:42 +0800 From: Li Zetao To: , , , , CC: , , , Subject: [RFC PATCH -next 3/3] splice: Using scope-based resource instead of folio_lock/unlock Date: Mon, 26 Aug 2024 15:10:36 +0800 Message-ID: <20240826071036.2445717-4-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826071036.2445717-1-lizetao1@huawei.com> References: <20240826071036.2445717-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) X-Rspamd-Queue-Id: 4B3691C0007 X-Stat-Signature: ymgundhbi6wijg8j8ifb3rrb9tw8w66y X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724655764-920289 X-HE-Meta: U2FsdGVkX1+L9uEDWPBqBjK1ut/BJQrmIsrCVoqctCPpRYXWFByBQPa05pu0Vzzc6s9QEaGw20ZIaN9g6Vhp1GIz2UPzwZjUA9Lnnc9796ZjVCO9p7dSThKiAs2sfjlvnApOyueqNVkZLo4nuSmtocufAuRZZC5wSs5nXoNwsolOSjp2vtMXWZpxWUebniVQoyofitYkA0TOubGbUqa6uyAGmE3oDIMCVscGPXR9BBiRTKcoy+lUzxJgjTZ+5s3qCtnNm0o/vB1pBEf0AwZh88xPQM4tgRL6c/02mNi0z8GSRmUAHh/ikiJu1kd+rr43Crm4qG3FNYqTnuvgR0IKQs6DXGhpIo+BvA4cNq4BLieLErZe6sMi9lQxET78uv+nwGJeRuS2IyvA0toVwYP5tsSnKOJojoQ0J2ETU71xKqv9bsNC79ksk5fAon+rX3TsWXE5NaFxgNJAt8VV5guSRYD7uPvslcyelLE5sfzT6Yc4OpNnAob+wOcV2POa7E85Y+IhXYrHjF/2mfUWHtdaax6dM4+SQeEZF7WnXh81oqeLgw3jmA4Z0/ZX0s65XYR944jhKUI1j3ANOMaejZuLcuRzeLF9kvrwAtO4eTOdJrprQzyRgSxCUPucinn36DhXl72yUSYO4RQFsjdDXhO19ucqUKkVdY0HXRrB+eMcjJNelKj+fIKokZCi26rifVKMKSxSLxK9Ft2smnlX08w5QtLDrZeOlTNa0YUFJbfItDGfhVXG1v3Tri3qqC8BsMox7fxsNjF8NM3tPJahHGEuhwdp++nTqqEptBgNaVTqZ9ohU6nsz1HI2IpWTQaseIKq9fQGQVxucxur5XaxLXpxuderMKo0UsRYLOOlB+IntQ63gkwUklDC563P0HSpDpA1vE3UriEooH1ewEWqVTBD+Oxl7J06Tt+73YRIDMUAo+E12eZ5ryrduBMcOjRCTnkRmreZJG36kGSVxKnHQ0w 9epYVVNh OKTjoty5GHM7/hUbA5VF5m3ANpYe47zNmarXqUtLH8Sl81jAIMzr2pH+gq45nDEQMBMaqls+E5LMwrgFrAg/dyWaY5Nkl3+iydrrHf2KrOhoMKe3yqFVkwgVQafJKtOH7k21N23B5U1ockejxv/vIXEU+AKnkMRnrVOofKKBKPHeXC8QyYlNN+jRkGT0XXAO7anvC 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: Use guard() to manage locking and unlocking a folio, thus avoiding the use of goto unlock code. Remove the out_unlock and error label, and return directly when an error occurs, allowing the compiler to release the folio's lock. Signed-off-by: Li Zetao --- fs/splice.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 06232d7e505f..bf976f2edfc1 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -120,36 +120,25 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { struct folio *folio = page_folio(buf->page); - int err; if (!folio_test_uptodate(folio)) { - folio_lock(folio); + guard(folio)(folio); /* * Folio got truncated/unhashed. This will cause a 0-byte * splice, if this is the first page. */ - if (!folio->mapping) { - err = -ENODATA; - goto error; - } + if (!folio->mapping) + return -ENODATA; /* * Uh oh, read-error from disk. */ - if (!folio_test_uptodate(folio)) { - err = -EIO; - goto error; - } - - /* Folio is ok after all, we are done */ - folio_unlock(folio); + if (!folio_test_uptodate(folio)) + return -EIO; } return 0; -error: - folio_unlock(folio); - return err; } const struct pipe_buf_operations page_cache_pipe_buf_ops = {