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: 13777249 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 326753FE4; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655766; cv=none; b=MS9Nw5YLCwSG0ZGow/rF7PZy4aJAqtOliQ406ZkHNdgGrk3VtIWnNmjXQ+53iLQGJ4tusf0Bu1NJpi2Mi28RcdlEw3aZLhYJkoj0ZUuSLcwae/T1+3rMnzOBuimdkR4iMdG9HNK+SFY659297idnB3VNbW0me3DmqpeQM95ELug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655766; c=relaxed/simple; bh=B52qPwd50bZUm3igmSPbTUZbrwC2pA0lHykJcf+RZcE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fz2vfZAQbPTQgnazeE9xsq8fAJiuOVJvpx20tTQljSZyXmyrrfk0O5KDu7oe7YvZjzbRIbjkt+rAY6b0z/4bMk+M5TH16tYTbphfQgT8+jCT2Q22/XYdO4d0qkB44yynE1+owHpBx8otH1xSRo4SAESa4b8S8XPmVrSxrnSEYsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com 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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) 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: 13777251 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B58FC376E6; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655767; cv=none; b=Bk/oenfDV5VXPxib+E5cIrAWf9zIQcphe5XZNL4NUTwzZx94WWy1oJxXQCIQD4ovQoZwEzgqHwkhIhbUEWYoSqtLF2YQnb1vAhplz+jM8Yle/lfvzYk6QqFFp1ZVtmzmhwis6PaLdn04IARvleIYnZjo/LEHDu90Uc/EHKvXYDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655767; c=relaxed/simple; bh=RtsuMEmYLvVLNNihKGcq7/xNuJEMDw9RX/dosPOT34I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XAYZG/ganwwfwcSWxCf3fgzehCyFnMsRmG7lpsbzyVCJLv/JcKg9Pjpppy7OkyvOkIuUgx8tjmfQhr8LEEvbW8Y2N480FFtu5Qm3ZE2qI7BBHsiWKiRtXaGwiXjCy7pU0HecW+xYdZUbwoX8gw9CPEl7/gA52OZGi2zdlZHR/XQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com 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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) 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: 13777252 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC0F857CBA; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655768; cv=none; b=FDJTRVD7Ll/7oYrrBxgaQV2gcYRQ/CAoLPJWiftr6BJw6p9PBSiuzny4bADBYtgKz16xZMgjg5Tyc4w4vb1iL/qW8jBlJmUki74IWDq7qVcEj90/pXAqpdEtmnnRg+8gTzCZndAbfpPhaPMred4o5Ukck5cc0iIQgx+RUZFRdUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724655768; c=relaxed/simple; bh=WFHhsIkRmkdGK2QWMeAh5kJ20knoPvV2uJ+PkYCQu1A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gHokE/xPxG/fQc80dqA0IZr3m5dhIitzRv7YWB4/LVExb/IaB/zapi+KfROc1EVkvRTT50MO3fJMDklDa8O5DMxRkoj7R/PLrU3I0Cmoim6e/GgbBvLjCn0Gp4AHnqfbiCnWJqnh1NGBUZozqtk6Db9JV6hwxYe34+uFSS9rYjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) 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 = {