Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4904786ooa; Tue, 14 Aug 2018 12:15:18 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwRs++CsQ5oQ/1dIZTi1fM+d1dT0L+Q9YuH3VdIRdoGTaD+xWqOiRPSsoHnvsinFzAqt3M9 X-Received: by 2002:a62:49cf:: with SMTP id r76-v6mr24136375pfi.235.1534274118855; Tue, 14 Aug 2018 12:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534274118; cv=none; d=google.com; s=arc-20160816; b=T5Bhd6KDYMqT9KK8MTpTUBMXLiDFCRbX+bodRu5CaiMp/CmOzg9F8v9RsrHCpsNpHU Mtylvvf5Vkb0wj0iWdUzHlDojZtlYzWuOsbap8E4A/SmY0wKjTUkQU7BTRhYqm0dfqAU YxukBd3OpXS3QnbcTNyVZKmLPEQIYVCORvvQCZV+YseRY6nUrXp4UfaiVEi/m6nXDcXi UCLN6C4gKFKpb3t7w90GNEIf91yVD3TdgcupQWENklBq57cayJjuF1IkMlqkiQYJks0I 2n7oVbrmmDSjYAdg8VLm+t/q1PThSsaOvXUUHT5R6+SvKAXqL/XfhO4B3OMK6sKMWzNH dpYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=wqdi/YFxfYFm3hnpxXVRdrEVMsjRwSDSFZnD86Wqb3c=; b=YV+hpCFbmgDEQC106L/ZZiuRpwo9tVLAQLlURiCTw3DPldXfDD0aiw8PJcsC+yvIgu 8JMOOEQfs79vu+E5YlvjMIZ3QH8oDgMjQI5JB1KVgpVamc8zaJzMi++ASZw13HTnqbBQ cJtpIzjyeSItKxxayPkOBgOhFGxV15r9pYDOwCELMb0opriHsgf9mw0PW+5Fbry6yg9j bhOLysvkx1UA5X/S3DC6QTxXR5V1gNmJZ9InmkyG9Ar8wr5+BpI+NVjG1x0ZWizMknNX gpkIUZVEh3esoKii3yanCdJYLTNZk8pnaJM9pwQo42RMlWmTz/CxeDw3sfBtF2Zyce45 1vtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bJ9rs1aH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7-v6si17890346plt.327.2018.08.14.12.15.03; Tue, 14 Aug 2018 12:15:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bJ9rs1aH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728504AbeHNWBL (ORCPT + 99 others); Tue, 14 Aug 2018 18:01:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbeHNWBL (ORCPT ); Tue, 14 Aug 2018 18:01:11 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E734F21717; Tue, 14 Aug 2018 19:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534273953; bh=9vhuO+FsWeTDPLcMHzOd3kBiADJxFey5m1rKRTH+Xz0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bJ9rs1aHUPEOxkHY4aLL11k9gp2Q+NL6Q11qfQO33jONOUIu1iuxyY6ZmUput2Fk/ i+K1vnTZRRe5iNxgQ1M5GrrNZplzQdXWpyBM8BC2126iKzHbRiCSv55U8L8Qo0VrLq dUqT97dSiF0tHpATfIfthxF9DhAQwb5m0ajWh8nA= Message-ID: <4afedd921922253224fd54d1e88acb3f40da4ef7.camel@kernel.org> Subject: Re: [PATCH 0/5 v2] locks: avoid thundering-herd wake-ups From: Jeff Layton To: "J. Bruce Fields" , NeilBrown Cc: Alexander Viro , Martin Wilck , linux-fsdevel@vger.kernel.org, Frank Filz , linux-kernel@vger.kernel.org Date: Tue, 14 Aug 2018 15:12:31 -0400 In-Reply-To: <20180814184146.GM7906@fieldses.org> References: <153421852728.24426.2111161640156686201.stgit@noble> <20180814184146.GM7906@fieldses.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-08-14 at 14:41 -0400, J. Bruce Fields wrote: > This version looks correct to me, and simpler. I'll be curious to hear > whatever you learn from testing! > > --b. > Agreed. I'll go ahead and put this in linux-next with an eye toward merging in v4.20 if we don't hit any major problems with it. Thanks again and nice work, Neil! > On Tue, Aug 14, 2018 at 01:56:51PM +1000, NeilBrown wrote: > > > > V2, which added wake_non_conflicts() was more broken than V1 - as > > Bruce explained there is no transitivity in the blocking relation > > between locks. > > So this series takes a simpler approach. > > It still attached waiters between other waiters as necessary to ensure > > that: > > - a waiter is blocked by it's parent (fl->blocker) and all further > > ancestors, and > > - the list of waiters on fl_blocked are mutually non-conflicting. > > > > When a lock (the root of a tree of requests) is released, only its > > immediate children (fl_blocked) are woken. > > When any lock is woken (either because its fl_blocker was released > > to due to a signal or similar) it with either: > > - be granted > > - be aborted > > - be re-queued beneath some other lock. > > > > In the first case tree of blocked locks is moved across to the newly > > created lock, and the invariants still hold. > > In the order two cases, the tree or blocked waiters are all detached > > and woken. > > > > Note that this series has not received much testing yet. > > > > Original description: > > If you have a many-core machine, and have many threads all wanting to > > briefly lock a give file (udev is known to do this), you can get quite > > poor performance. > > > > When one thread releases a lock, it wakes up all other threads that > > are waiting (classic thundering-herd) - one will get the lock and the > > others go to sleep. > > When you have few cores, this is not very noticeable: by the time the > > 4th or 5th thread gets enough CPU time to try to claim the lock, the > > earlier threads have claimed it, done what was needed, and released. > > With 50+ cores, the contention can easily be measured. > > > > This patchset creates a tree of pending lock request in which siblings > > don't conflict and each lock request does conflict with its parent. > > When a lock is released, only requests which don't conflict with each > > other a woken. > > > > Testing shows that lock-acquisitions-per-second is now fairly stable even > > as number of contending process goes to 1000. Without this patch, > > locks-per-second drops off steeply after a few 10s of processes. > > > > There is a small cost to this extra complexity. > > At 20 processes running a particular test on 72 cores, the lock > > acquisitions per second drops from 1.8 million to 1.4 million with > > this patch. For 100 processes, this patch still provides 1.4 million > > while without this patch there are about 700,000. > > > > NeilBrown > > > > --- > > > > NeilBrown (5): > > fs/locks: rename some lists and pointers. > > fs/locks: split out __locks_wake_up_blocks(). > > fs/locks: allow a lock request to block other requests. > > fs/locks: change all *_conflict() functions to return bool. > > fs/locks: create a tree of dependent requests. > > > > > > fs/cifs/file.c | 2 - > > fs/locks.c | 156 ++++++++++++++++++++++++++------------- > > include/linux/fs.h | 7 +- > > include/trace/events/filelock.h | 16 ++-- > > 4 files changed, 119 insertions(+), 62 deletions(-) > > > > -- > > Signature -- Jeff Layton