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 BB3C3C43334 for ; Fri, 22 Jul 2022 11:55:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D753E6B0072; Fri, 22 Jul 2022 07:55:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D23576B0073; Fri, 22 Jul 2022 07:55:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEA5E6B0074; Fri, 22 Jul 2022 07:55:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AB3E66B0072 for ; Fri, 22 Jul 2022 07:55:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 82A19160BF1 for ; Fri, 22 Jul 2022 11:55:23 +0000 (UTC) X-FDA: 79714580526.03.A77FDBB Received: from mail3-165.sinamail.sina.com.cn (mail3-165.sinamail.sina.com.cn [202.108.3.165]) by imf09.hostedemail.com (Postfix) with SMTP id 5BA8A14009B for ; Fri, 22 Jul 2022 11:55:19 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.59.48]) by sina.com (172.16.97.32) with ESMTP id 62DA900E00008558; Fri, 22 Jul 2022 19:54:56 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 551702629033 From: Hillf Danton To: Doug Anderson Cc: Waiman Long , Peter Zijlstra , Will Deacon , Davidlohr Bueso , MM , LKML Subject: Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent Date: Fri, 22 Jul 2022 19:55:10 +0800 Message-Id: <20220722115510.2101-1-hdanton@sina.com> In-Reply-To: References: <20211116012912.723980-1-longman@redhat.com> <20220719104104.1634-1-hdanton@sina.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658490923; 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=4GJm7yYZWfnHU2lCnxXgbdpSD6pbNa7tiC8HlFQkyK0=; b=DUV7S1wlKEmZi6Y9uYKCnDJ92kHAoAmMCCcgYqcmtiaYX0lJrIbOpYx7WhVcxLq2wQQFrJ gZH2s7lf5d4pr8XAcRLXD0fKdjRVlL/5FXQO9T5e3+I5n3HzIXT90V9MHYxIjH103kaIMQ j23A9t+ZxiYKJmDBgt7HPFo1VyhfKuM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.165 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658490923; a=rsa-sha256; cv=none; b=QDB+XJSj0BeGLaa4ZI+L31dEIjwre3PhiknhoV9TMKN8YtF18SuQF0UonVfY6QzKaedDlI znQGszB1DsVNwDwsiPSbvRavs5scjH1++KI3Ih8/eX3wJI/s4IvFngYBwZrRlWW02+PWUM d7Luc1HFQ+edkw8q1vNiS9cVW//dWpM= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5BA8A14009B X-Stat-Signature: awjzgnqngdsbnk14c57qab4k8ieujtbu X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.165 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none X-HE-Tag: 1658490919-996787 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 Tue, 19 Jul 2022 08:30:02 -0700 Doug Anderson wrote: > > I haven't done any stress testing other than my test case, though, so > I can't speak to whether there might be any other unintended issues. The diff below is prepared for any regressions I can imagine in stress tests by adding changes to both read and write acquirer slow pathes. On the read side, make lock stealing more aggressive; on the other hand, write acquirers try to set HANDOFF after a RWSEM_WAIT_TIMEOUT nap to force the reader acquirers to take the slow path. Hillf --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -992,13 +992,7 @@ rwsem_down_read_slowpath(struct rw_semap struct rwsem_waiter waiter; DEFINE_WAKE_Q(wake_q); - /* - * To prevent a constant stream of readers from starving a sleeping - * waiter, don't attempt optimistic lock stealing if the lock is - * currently owned by readers. - */ - if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) && - (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED)) + if (WARN_ON_ONCE(count & RWSEM_FLAG_READFAIL)) goto queue; /* @@ -1169,7 +1163,11 @@ rwsem_down_write_slowpath(struct rw_sema goto trylock_again; } - schedule(); + if (RWSEM_FLAG_HANDOFF & atomic_long_read(&sem->count)) + schedule(); + else + schedule_timeout(1 + RWSEM_WAIT_TIMEOUT); + lockevent_inc(rwsem_sleep_writer); set_current_state(state); trylock_again: --