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 5410ACD3420 for ; Tue, 3 Sep 2024 11:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDFD36B030E; Tue, 3 Sep 2024 07:01:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B68D16B0310; Tue, 3 Sep 2024 07:01:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D2A6B030F; Tue, 3 Sep 2024 07:01:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 769BC6B030B for ; Tue, 3 Sep 2024 07:01:32 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0875B1404B0 for ; Tue, 3 Sep 2024 11:01:32 +0000 (UTC) X-FDA: 82523136024.03.5DFB98B Received: from smtp134-32.sina.com.cn (smtp134-32.sina.com.cn [180.149.134.32]) by imf05.hostedemail.com (Postfix) with ESMTP id 2BCF6100018 for ; Tue, 3 Sep 2024 11:01:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of hdanton@sina.com designates 180.149.134.32 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725361243; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=16LlSat50bt9avGkXWiW45atf8IshQvWwwfK2Qc5fnw=; b=wutFlDthJDnkkykUW+YQXhAeR+eiWzpSJC2zZbsV6OMWVbatT/QR+bQ5MQjMr+NL5anqji UBa+s9FyQzCAl4Xms7oaXfHp99mcOD5tj8FVl3/jAELGqHSIZJpyIMUnEIjkC8ojSekzZL s5eHBOi+ulLOKqh679w5n7nzBW2XiZk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of hdanton@sina.com designates 180.149.134.32 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725361243; a=rsa-sha256; cv=none; b=V8QwWe6XYV7dZkTXO44150QpqnHlJApWYehVcEgLvT6bpY+9mTfVbh30TV1xXvLRbigsI3 HQIY3y5LF8RlvJtv76ZpFsBZrXaisphTg5MEkHXdxJLUR3MdfbQm9dLM85QKjkb8vu9g5u zFwxZ0873M1UGBmef2fxp9V0ey+9/i8= X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([113.118.71.172]) by sina.com (10.185.250.21) with ESMTP id 66D6EC7F00005088; Tue, 3 Sep 2024 19:01:22 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 1103633408533 X-SMAIL-UIID: 7CAF2982F7F24C768F9BEBA86CFD2D41-20240903-190122-1 From: Hillf Danton To: Barry Song <21cnbao@gmail.com> Cc: Greg Kroah-Hartman , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Barry Song" , "Carlos Llamas" , "Suren Baghdasaryan" , Michal Hocko , "Tangquan Zheng" Subject: Re: [PATCH] binder_alloc: Move alloc_page() out of mmap_rwsem to reduce the lock duration Date: Tue, 3 Sep 2024 19:01:09 +0800 Message-Id: <20240903110109.1696-1-hdanton@sina.com> In-Reply-To: <20240902225009.34576-1-21cnbao@gmail.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 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3y5HE+kmcOsds3IV2CRAbksTTjLckd/GGR I3p+Wt6j GBqEqvYRcVVRb3l9fV4tbZLyWxH/KbxPMxZCiI3MQStSn0dg7DJxZ24wNOgHSXq5QWWvRyHyq7G4IvLubmkh27V2ZgFBUwfQIVAtwApCrO8G5WZ+uBX1K3k4KgLssJMw+vOYaph9bivdba5npdLqI+hyWzUlGA6XBbDc+NHxp9ThEG4MbbOVZ98F+MUEYUhc0E29+fzFTQq+8d8/mCZfOpjpcmHEEYBBe4cHJ 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: On Tue, Sep 03, 2024 at 10:50:09AM +1200, Barry Song wrote: > From: Barry Song > > The mmap_write_lock() can block all access to the VMAs, for example page > faults. Performing memory allocation while holding this lock may trigger > direct reclamation, leading to others being queued in the rwsem for an > extended period. > We've observed that the allocation can sometimes take more than 300ms, > significantly blocking other threads. The user interface sometimes > becomes less responsive as a result. To prevent this, let's move the > allocation outside of the write lock. I suspect concurrent allocators make things better wrt response, cutting alloc latency down to 10ms for instance in your scenario. Feel free to show figures given Tangquan's 48-hour profiling. > A potential side effect could be an extra alloc_page() for the second > thread executing binder_install_single_page() while the first thread > has done it earlier. However, according to Tangquan's 48-hour profiling > using monkey, the likelihood of this occurring is minimal, with a ratio > of only 1 in 2400. Compared to the significantly costly rwsem, this is > negligible. > On the other hand, holding a write lock without making any VMA > modifications appears questionable and likely incorrect. While this > patch focuses on reducing the lock duration, future updates may aim > to eliminate the write lock entirely. If spin, better not before taking a look at vm_insert_page().