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 F2622C433FE for ; Wed, 12 Oct 2022 13:20:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 474986B0071; Wed, 12 Oct 2022 09:20:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4243E6B0073; Wed, 12 Oct 2022 09:20:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C540900002; Wed, 12 Oct 2022 09:20:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1A47A6B0071 for ; Wed, 12 Oct 2022 09:20:00 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E8E011C6981 for ; Wed, 12 Oct 2022 13:19:59 +0000 (UTC) X-FDA: 80012355318.26.9F3BEED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 02643C002E for ; Wed, 12 Oct 2022 13:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665580798; h=from:from: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=GcZ45yRu2GyW+Co6nWRGGRC1Ai53wvLIU4B5zOXWM2E=; b=epTgIoYEcFvmY0T8mcgyoZ8iAhiwvvEzg+Lc+4YoOs5drk0IL333D8amA6WRBRnkTizRFg DG4C7E/rTLporMYGDRGzwcRtCY+p1svqHM9XieHi9dEYmoLuRkyIwPLzMZF4qOKizL5AZ9 iL6m331+Y1QcCuOWYVjfOYp4WMSp3NA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-218-sbiD5b3-M0mfKTYos3RZwA-1; Wed, 12 Oct 2022 09:19:54 -0400 X-MC-Unique: sbiD5b3-M0mfKTYos3RZwA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE48A1C05AF3; Wed, 12 Oct 2022 13:19:53 +0000 (UTC) Received: from [10.22.33.120] (unknown [10.22.33.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788EE492CA2; Wed, 12 Oct 2022 13:19:53 +0000 (UTC) Message-ID: Date: Wed, 12 Oct 2022 09:19:53 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] locking/rwsem: Prevent non-first waiter from spinning in down_write() slowpath Content-Language: en-US To: Hillf Danton , Mukesh Ojha Cc: linux-kernel@vger.kernel.org, john.p.donnelly@oracle.com, linux-mm@kvack.org, Peter Zijlstra , Will Deacon , Boqun Feng , Ingo Molnar References: <20221012040410.403-1-hdanton@sina.com> From: Waiman Long In-Reply-To: <20221012040410.403-1-hdanton@sina.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665580799; 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:dkim-signature; bh=GcZ45yRu2GyW+Co6nWRGGRC1Ai53wvLIU4B5zOXWM2E=; b=w31W/brGVvZDropLVQ+aM8UfjH3KkrYgx0jvXV+lh7Vd1dxPmPLjL5NUJSYs0ocsXLFbHu Zk0AbvD/77BDPIIoil6ASaMLm5n9FgWu7KrM6ksT8lYeqGibhX++CYwgeHcxwNVjivKxne 8CeEj+ymMiB184H8bJZji6AGxRRo+r8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=epTgIoYE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665580799; a=rsa-sha256; cv=none; b=MP9h2ZNmO8rP466VjtFmP74nuB6lcioHVBl7GagqohlP0SgrxUIaaabHGNPZ1re+EJN3ym xoLs43Y/mHDjCf/uEVmW56+hz+RILmKsjRXVQiZSATrZac5qfq7uMTNKMAFihikdvyLow8 JrQjOveN+DPGVYGnG2WfJlwyAhTa7Tw= X-Stat-Signature: q539s76aopkostn4g8w8j9j36h1riate X-Rspamd-Queue-Id: 02643C002E Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=epTgIoYE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1665580798-99114 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 10/12/22 00:04, Hillf Danton wrote: >> you mean, you want to check and change waiter->handoff_set on every run >> rwsem_try_write_lock(). >> > Yes, with RWSEM_FLAG_HANDOFF set, it is too late for non first waiters to > spin, and with both RWSEM_LOCK_MASK and RWSEM_FLAG_HANDOFF set, the rivals > in the RWSEM_LOCK_MASK have an uphand over the first waiter wrt acquiring > the lock, and it is not a bad option for the first waiter to take a step > back off. > > if (count & RWSEM_LOCK_MASK) { > if (has_handoff || (!rt_task(waiter->task) && > !time_after(jiffies, waiter->timeout))) > return false; > > new |= RWSEM_FLAG_HANDOFF; > } else { > >> But does it break optimistic spinning ? @waiman ? > Waiters spin for acquiring lock instead of lockup and your report shows > spinning too much makes trouble. The key is stop spinning neither too > late nor too early. My proposal is a simple one with as few heuristics > added as possible. Yes, too much spinning is bad if we have RT tasks in the mix, otherwise it should be fine. Cheers, Longman