Message ID | 20240129193512.123145-1-lokeshgidra@google.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp789461dyb; Mon, 29 Jan 2024 11:35:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGu2SYf9pC456DpPddb3ah+DDJiLTpuSyo8Ix0OzHMpEHVnW4dCtUK+oj6FANo5P21PX6MW X-Received: by 2002:a05:6a21:7892:b0:19c:6a60:b433 with SMTP id bf18-20020a056a21789200b0019c6a60b433mr3781879pzc.3.1706556953679; Mon, 29 Jan 2024 11:35:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706556953; cv=pass; d=google.com; s=arc-20160816; b=pqTRuH+H0j8X5A/qYJvZzMacerQ7lnd/M22i6BHgPDZn2A3OcqlezDf8BehOP0i//m 8npRdF9hukHELLpKyozSBr3FAZFUEbpsK0nhrDGJvnOJcBkbTze/8D98wGLCBCZjNw/S X9hpYSnPhx6MichOxn9HhwPbWppBY6PRgx5nBydYf9qps5SCRe2lw6yrHU8iPBhGT1VT BKpQLrMgIrBzplif2NXzmK0nf+UcTLJLh5VFeoSSsO88oX47hdozva0fRrXa+++KmSoH NGPKN2Ni+Rq6fHrwzQwXgl78Ae0KuHNDAEe8y2+jm0YrHGR/5ucMfj9OULf6EeVCP4dU zVvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; fh=YpYg+AMOLH4GRgVOvnwFLenCYLn09uoxMCo5ibUfZzo=; b=o+AFBfEarsQHfZwp5uzHMRAHUOOME2wQruaM03kE+CLCRFutHVPNAL//mwdLsTLrdJ iv5WWYM91FKyVKaocwy4HOsfrgW+bqCUglwXcGsWS1fVgLJ00VGDz5EPsXug00gYbGwR 9ST5xbIh6sEeWA/GvXxrJOavH8w9b63Rz6hBqKx+LjPIbXnhBr3qOglQ1wdaRhPffUvt 3MvTvhiwTtcp0sb5cErUqROeVPwiS9FhqjbgRSzB+8pPd7v8YZFNpFHtfSE15hBLQgoO wB3iGXrd8kmmz1kwXtMSlaBhtc7lF7QIgtwLPkUbmjeOw4TcuksTb5gq6Jx1lgsKk89u 4ZLQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fmdf6gNZ; arc=pass (i=1 spf=pass spfdomain=flex--lokeshgidra.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g1-20020a170902740100b001d77cbcf413si1483571pll.328.2024.01.29.11.35.53 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 11:35:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fmdf6gNZ; arc=pass (i=1 spf=pass spfdomain=flex--lokeshgidra.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43417-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 73E46282216 for <ouuuleilei@gmail.com>; Mon, 29 Jan 2024 19:35:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7355376053; Mon, 29 Jan 2024 19:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fmdf6gNZ" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DDC45644E for <linux-kernel@vger.kernel.org>; Mon, 29 Jan 2024 19:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706556923; cv=none; b=QA8TryDHYcF+s2WCpJkfGFVQCCkf8GiEQnp/Q5zhWpIGilsDKvNfZORnVKgWmSZYvi6X7Lt9BO+2kTTNE7ux1nvK6ImGgsuEPSyou85amy2Do42AZKR33Jd3PT8VFnkwMm1pNBYjzJQeAGDBYqaRUJoAicgud0NcbvCiCq4+WWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706556923; c=relaxed/simple; bh=q+KxZnv5oof9XIDGvhACsh+/6ErV1CKpfDTSXHD8Zwg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=kQZcjDx3LjPSPXQ4V+9jX0A8rIux8A18a/1ts1RRnqBNpY/a6iE+0i03Pm1ZB+sH6nL2DVSPSb83BfkCUwUrNXHGk6+BT81Nkh4KcNBIGdvkor9nZxEWx19kLVg19MgTxwKPaSR9qh+MAsOScugeluHJJ1uN/QP2OAIbkuAU8Vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--lokeshgidra.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fmdf6gNZ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lokeshgidra.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso5057090276.0 for <linux-kernel@vger.kernel.org>; Mon, 29 Jan 2024 11:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706556920; x=1707161720; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; b=fmdf6gNZHX7z0Kc7CKU6VCNGXOPXl47CUTZNGuw7r3jdBbxiLAjYQ6vf1qNqOoby4v QRuvEZyIJELteL5xl01G8+KvfBmjBwwDFEDDaIiIzzHiWXrsQcvBxnWaJb0TbW4/+5EO a3ZbEoDvUUPYJwv/7YBSjzLUoTRlbh9EV9bQBN0xTkhV85qH2oAp44AO9awf+QkCR6Sf MZPW8D12Wml+WUe6hSv3Wcm9loIg2d2rgQ6jzXZ/iegS6Dy/c4gSNIW/yQIfzXulSylw pQr6X/mN3md9LmPX8RwXkfepcYbpcr17HrMCh/wt2Rldy18fIyKre1q+osPcQG+ZuL56 +LFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706556920; x=1707161720; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; b=tGTz2uBhxpAByStzNQM0H1AvjWJvLCe7X8NKFw3pBzh3UTArA2lDxfhl7ETyJeV50Q 03vKed6l0Px5AyXaVeqsNzQLbvZ45JeukvLdlCgZRz3l1IcNrKQ8WjKd0qrnQy94ooJQ eq6u58AO00W6JgMgPbcmVGVBTrZIZf5xZ/1+Wpfiior2v7fyKId+xYQAmK/aafdidLHT rZV0C4lE54k5xUGv83Hk1AgTjwkeYsIVfuURdUvFTblzsM4NEh4TJaYnk8BIMpY+z03W 5YV1uhg0l6Gx+SYRmim6s8CrESJRNJj1ctjystzi9U+w4pfHtwuU3EWcGeABaU1CI/At GqCQ== X-Gm-Message-State: AOJu0YyFu8GKllyEJkp5Wwof1ugYklBMupdm4QNl0tyVflCx0mTmb4/3 ci20gRM8fzf24wteVrgzF7Q7fyzwsvNLkcaio6irPvH2sdiyOvwyQ/CAePYDM4lT/1y+ivCkrC3 OaArRx/wFVJJ9z+Sgu/slrg== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:9b1d:f1ee:f750:93f1]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:2604:b0:dc2:23db:1bc8 with SMTP id dw4-20020a056902260400b00dc223db1bc8mr443578ybb.3.1706556920762; Mon, 29 Jan 2024 11:35:20 -0800 (PST) Date: Mon, 29 Jan 2024 11:35:09 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129193512.123145-1-lokeshgidra@google.com> Subject: [PATCH v2 0/3] per-vma locks in userfaultfd From: Lokesh Gidra <lokeshgidra@google.com> To: akpm@linux-foundation.org Cc: lokeshgidra@google.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, surenb@google.com, kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com, david@redhat.com, axelrasmussen@google.com, bgeffon@google.com, willy@infradead.org, jannh@google.com, kaleshsingh@google.com, ngeoffray@google.com, timmurray@google.com, rppt@kernel.org Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789454664579492859 X-GMAIL-MSGID: 1789454664579492859 |
Series | per-vma locks in userfaultfd | |
Message
Lokesh Gidra
Jan. 29, 2024, 7:35 p.m. UTC
Performing userfaultfd operations (like copy/move etc.) in critical section of mmap_lock (read-mode) causes significant contention on the lock when operations requiring the lock in write-mode are taking place concurrently. We can use per-vma locks instead to significantly reduce the contention issue. Changes since v1 [1]: - rebase patches on 'mm-unstable' branch [1] https://lore.kernel.org/all/20240126182647.2748949-1-lokeshgidra@google.com/ Lokesh Gidra (3): userfaultfd: move userfaultfd_ctx struct to header file userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx userfaultfd: use per-vma locks in userfaultfd operations fs/userfaultfd.c | 86 ++++--------- include/linux/userfaultfd_k.h | 75 ++++++++--- mm/userfaultfd.c | 229 ++++++++++++++++++++++------------ 3 files changed, 229 insertions(+), 161 deletions(-)
Comments
* Lokesh Gidra <lokeshgidra@google.com> [240129 14:35]: > Performing userfaultfd operations (like copy/move etc.) in critical > section of mmap_lock (read-mode) causes significant contention on the > lock when operations requiring the lock in write-mode are taking place > concurrently. We can use per-vma locks instead to significantly reduce > the contention issue. Is this really an issue? I'm surprised so much userfaultfd work is happening to create contention. Can you share some numbers and how your patch set changes the performance? > > Changes since v1 [1]: > - rebase patches on 'mm-unstable' branch > > [1] https://lore.kernel.org/all/20240126182647.2748949-1-lokeshgidra@google.com/ > > Lokesh Gidra (3): > userfaultfd: move userfaultfd_ctx struct to header file > userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx > userfaultfd: use per-vma locks in userfaultfd operations > > fs/userfaultfd.c | 86 ++++--------- > include/linux/userfaultfd_k.h | 75 ++++++++--- > mm/userfaultfd.c | 229 ++++++++++++++++++++++------------ > 3 files changed, 229 insertions(+), 161 deletions(-) > > -- > 2.43.0.429.g432eaa2c6b-goog > >
On Mon, Jan 29, 2024 at 12:39 PM Liam R. Howlett <Liam.Howlett@oracle.com> wrote: > > * Lokesh Gidra <lokeshgidra@google.com> [240129 14:35]: > > Performing userfaultfd operations (like copy/move etc.) in critical > > section of mmap_lock (read-mode) causes significant contention on the > > lock when operations requiring the lock in write-mode are taking place > > concurrently. We can use per-vma locks instead to significantly reduce > > the contention issue. > > Is this really an issue? I'm surprised so much userfaultfd work is > happening to create contention. Can you share some numbers and how your > patch set changes the performance? > In Android we are using userfaultfd for Android Runtime's GC compaction. mmap-lock (write-mode) operations like mmap/munmap/mlock happening simultaneously elsewhere in the process caused significant contention. Of course, this doesn't happen during every compaction, but whenever it does it leads to a jittery experience for the user. During one such reproducible scenario, we observed the following improvements with this patch-set: - Wall clock time of compaction phase came down from ~3s to less than 500ms - Uninterruptible sleep time (across all threads in the process) was ~10ms (none was in mmap_lock) during compaction, instead of >20s I will add these numbers in the cover letter in the next version of this patchset. > > > > Changes since v1 [1]: > > - rebase patches on 'mm-unstable' branch > > > > [1] https://lore.kernel.org/all/20240126182647.2748949-1-lokeshgidra@google.com/ > > > > Lokesh Gidra (3): > > userfaultfd: move userfaultfd_ctx struct to header file > > userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx > > userfaultfd: use per-vma locks in userfaultfd operations > > > > fs/userfaultfd.c | 86 ++++--------- > > include/linux/userfaultfd_k.h | 75 ++++++++--- > > mm/userfaultfd.c | 229 ++++++++++++++++++++++------------ > > 3 files changed, 229 insertions(+), 161 deletions(-) > > > > -- > > 2.43.0.429.g432eaa2c6b-goog > > > >