From mboxrd@z Thu Jan 1 00:00:00 1970 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 62364C433EF for ; Wed, 1 Jun 2022 03:21:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EC516B0071; Tue, 31 May 2022 23:21:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 899A56B0073; Tue, 31 May 2022 23:21:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 787036B0074; Tue, 31 May 2022 23:21:36 -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 66E256B0071 for ; Tue, 31 May 2022 23:21:36 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 30DE13427F for ; Wed, 1 Jun 2022 03:21:36 +0000 (UTC) X-FDA: 79528216992.13.1DABD82 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf16.hostedemail.com (Postfix) with ESMTP id 1E7A7180009 for ; Wed, 1 Jun 2022 03:21:13 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LCZBp0nJzz1K95m; Wed, 1 Jun 2022 11:19:46 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 1 Jun 2022 11:21:24 +0800 Subject: Re: [PATCH v4 1/4] mm: reduce the rcu lock duration To: Matthew Wilcox CC: , , , , , , , , , , , , References: <20220530113016.16663-1-linmiaohe@huawei.com> <20220530113016.16663-2-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Wed, 1 Jun 2022 11:21:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Stat-Signature: 7918u4c5fquu3ugu77w7wras9hgpa7dh X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1E7A7180009 X-HE-Tag: 1654053673-203271 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: On 2022/5/31 21:05, Matthew Wilcox wrote: > On Tue, May 31, 2022 at 01:58:31PM +0100, Matthew Wilcox wrote: >> On Mon, May 30, 2022 at 07:30:13PM +0800, Miaohe Lin wrote: >>> Commit 3268c63eded4 ("mm: fix move/migrate_pages() race on task struct") >>> extends the period of the rcu_read_lock until after the permissions checks >>> are done to prevent the task pointed to from changing from under us. But >>> the task_struct refcount is also taken at that time, the reference to task >>> is guaranteed to be stable. So it's unnecessary to extend the period of >>> the rcu_read_lock. Release the rcu lock after task refcount is successfully >>> grabbed to reduce the rcu holding time. >> >> But why bother? You know the RCU read lock isn't a "real" lock, right? > > Looking over this code some more, I think this may harm performance. > ptrace_may_access() itself takes the rcu_read_lock(). So we currently > have: > > rcu_read_lock() > rcu_read_lock(); > rcu_read_unlock(); > rcu_read_unlock(); More precisely, we currently have: rcu_read_lock() task_lock() rcu_read_lock(); rcu_read_unlock(); task_unlock() rcu_read_unlock(); > > In at least one RCU configuration, rcu_read_lock() maps to > preempt_disable(). Nested preempt_disable() just bump a counter, while > that counter reaching zero incurs some actual work. So nested > rcu_read_lock() can be better than sequential lock/unlock/lock/unlock. In this case, I agree with you. But when task_lock is heavily contented, it might take a long time. So in this case, I think it's better to do the sequential rcu_lock+unlock to avoid long rcu lock duration. Or am I miss something? > > This needs far better justification. Thanks! > > . >