Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp653815rdb; Mon, 29 Jan 2024 13:58:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpu4xZIDU7E5hVE+qHQs38jhcFtBf48aAisALDtm3DOULMB865h5cHP96A+SduID/oraXm X-Received: by 2002:a05:6902:1028:b0:dc2:17b2:f561 with SMTP id x8-20020a056902102800b00dc217b2f561mr6417041ybt.123.1706565506046; Mon, 29 Jan 2024 13:58:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706565506; cv=pass; d=google.com; s=arc-20160816; b=XNp7fiUf0UcUwGVoSlH8bUu4d/gYVkwYZom2VdmtvMto7TTf9SjR79oNccVnXQGGTd MPr5wVcTdpRLWPiv4tO7PJ0Md7My7DTiDq6afIYJUbI6c78YOAa5ZT5DBOGIuPmyhTI3 BpbiPvt1pnZ1iDFIEaNYwsmN0a724J0SeWbFCOhe8e3SiR/qHEkQ4iyFvomTA0ZdTqcW yMMwztAoVY0NsQl23tb/OGg3yPjNYU5H5tU+3Mu48k8ImOjCRsxJb7ofn0NcDHqpNbD8 q2nuTd6W+fVxDXlOXes+MALSj8FSqOZ3lwqgKfGOk3yss0QHO0Wbix+CRV/qM1Vg26ih YiRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=CUG0VAx6fB3sqRZQjRRGH6lMhLjFI7rY91Z4hSbS8UE=; fh=8mKQSjmCL1fSQYQ7QESxzXoyNpbNCglR2/ovsOq34vM=; b=S3DB7IwpO43RogJTq89H6jc6dsVTHZ63Q/Ikkh54Zd2QBNJFb/WvUCVVSV56FEGRJB ER0arlCVxzSfzPdjxmlGVtbspzG29288RZV/A3XRRwWSfA16dnzkA2L8Kb4XEZryR2Su sc8mB5ObdcKN7+bbOvygAoDxM/8wgZMXfYbL1gFTBTOVvUh6kGsL0onjtG9G5bmr10VA mjIQzZ4H6NYZdGi4ii2WFh6gOQezPuW1dGlfdhezShY3fDH9oCWgM2yLJUOBDoj9Vh+1 KRF1KylNXiqxZ6Y76D+7NTBNNVsi5OTgYEsTJDp8mpZTE2MtdvOC8ORHzMFZOP3oXoam GpYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ExZh8qvA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i19-20020ae9ee13000000b007832f29a421si8231791qkg.361.2024.01.29.13.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 13:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ExZh8qvA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-43541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43541-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C91F51C23C05 for ; Mon, 29 Jan 2024 21:58:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94D6F159569; Mon, 29 Jan 2024 21:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ExZh8qvA" Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 2535B158D68 for ; Mon, 29 Jan 2024 21:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706565496; cv=none; b=D/eSbGjUKpy4zk3HYSVi2tojEeBuTaNH3neRkC55Uh/eiFfGyD3GFyNXHHRCj3baQkEKoEOINz/aZpOOc1ZqyoM5hLsM4MAfVF9hp2WvRPljVrxg98tnWy1/FiFO9dLXEAtAgfDuj61y+FXkT9crugTSB56jSBf+6FyOkypzrSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706565496; c=relaxed/simple; bh=yZyZ29p6yMC6LhYj5NL5f97FYixcVCB1YcfCBS49aMw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=nFb3KFousqIUWLjMPuY7t82VP2AH7SKfHP8Vfama5a3xu+/lv3QApUIGNFS71dVywOULVgyqzS2eFysERswHvubGhaEfIyAHoNanEThkg0F3jmX4/jGFzKeK64jmQdDs3vWJHefgr+NbK1/YKtYmAUe86G6yRZnY1Xnsafcjmp0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ExZh8qvA; arc=none smtp.client-ip=209.85.221.45 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=google.com Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33929364bdaso2324281f8f.2 for ; Mon, 29 Jan 2024 13:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706565493; x=1707170293; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CUG0VAx6fB3sqRZQjRRGH6lMhLjFI7rY91Z4hSbS8UE=; b=ExZh8qvAvRoPwP8AmR83NNRM72HpbFMUYcCHAaqEl9UsRSWGu79vyXO6XtWV7iv96n y3GQeXo4qhwt/HwslQbPkbUw12VaMJ+nu7iKb34JyZgHlE78LLN8i7gRg8Ik65x3CHYt t42mcbXvSUyUA8JaNNXVH9fhK4yjrL0H6zsvNdKZHdxRjvAkJM/e9gv6dUV3accM3Slc HHnBQaOpY7mxmu5z3UVSpek3ep63KHjnjICmekrW7ghycb6su1FnkRIP5bKmm9s+jadH ZNBOVgWhhoGv7VW2AWcnJc5V7xZKUkCCaI+RWzUu/YIcr6+LuCv7I2ig/fd1BS7uEcUS T8eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706565493; x=1707170293; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CUG0VAx6fB3sqRZQjRRGH6lMhLjFI7rY91Z4hSbS8UE=; b=GQLGuH64wtbSnjpYMbNHUZc/KPcb1rqPt7uYQY34U9b4izF7n4FKSOKlaMJ8Tcbgm9 rXMKPVzkBnqmyK/pP5I65phUgb/jwTC8FyUsKXTHw07u9FySIUUyR4NjKcJXDVaaIfYm SY8pk2LKONaPePyVnl83O/vT1+ifsxU/rKbBtPuEq4v2QBnbHGBH0ypbDznpRtTOWxAY DzfmFSlPOCGmOu8rcM3gTigWPp28LNYn8R6IVSY2vp1o5teDWYFqz9CEBmFRbCN7Y5nC +W/JY3KLmyUuZVdHskZrrKoCfoa+ndwwNGTmluz2V7eqoLQgJD92XmG//DbCtIPodolB SoNg== X-Gm-Message-State: AOJu0YxdjFvKr5x0p6futjqGRQ4nv1UR7y9WFl+/gNes3RYbl0zWL3QR ZyGAPNXW4FGEy9MX6kjAT4BR+NCLRTEA0k/f47JY+P0aO5VOfm2HbtMikcCd4j8CypPOmfCwFKs pyn3utB/2QT4JNFzPaUMZ5iEgjyrf3KPgwjqW X-Received: by 2002:adf:e44a:0:b0:33a:e5a8:eaed with SMTP id t10-20020adfe44a000000b0033ae5a8eaedmr4230312wrm.14.1706565493189; Mon, 29 Jan 2024 13:58:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240129193512.123145-1-lokeshgidra@google.com> <20240129203904.7dcugltsjajldlea@revolver> In-Reply-To: <20240129203904.7dcugltsjajldlea@revolver> From: Lokesh Gidra Date: Mon, 29 Jan 2024 13:58:00 -0800 Message-ID: Subject: Re: [PATCH v2 0/3] per-vma locks in userfaultfd To: "Liam R. Howlett" , Lokesh Gidra , akpm@linux-foundation.org, 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" Content-Transfer-Encoding: quoted-printable On Mon, Jan 29, 2024 at 12:39=E2=80=AFPM Liam R. Howlett wrote: > > * Lokesh Gidra [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@go= ogle.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 > > > >