Message ID | 20240206010919.1109005-1-lokeshgidra@google.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-54139-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1249802dyb; Mon, 5 Feb 2024 17:09:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHehx5A/S5e1pjBRdaR75rPEsrqtN3CrMZpx9RStknKTukPfHT/9Y/c9haatFcDT71btvuS X-Received: by 2002:a17:903:94e:b0:1d9:b27b:1b66 with SMTP id ma14-20020a170903094e00b001d9b27b1b66mr232105plb.7.1707181794722; Mon, 05 Feb 2024 17:09:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707181794; cv=pass; d=google.com; s=arc-20160816; b=Fw2WYPUhkmaYdRFwqVNFPVO8C8nna4ln9oKKUI6osnSlZD1OdbTD70/gRs294miXBB u754agUb6J9hzLYYR6IJuHHUO2UyI7WDv9sEPMYDsiQHT9A0C1ufn1PyEfgR8ScrhI4I n3hZEAQaimhysEbfFkjQyZGKg+KTGs5e6ATSSo9/dIEGE9Y32ScVLilNwIXpI/QPfu6E +iEMx9kWLMwJ6Vg7jxuNL7L0y1yfuR4UuEIZgRVnaBSKfTeYdJpnes/X2Uwv6+gBqKRF RTY5dLx2xJ/265tWQhiA6xvX/B9P0y7C/hSoiDEuYPz3AmtKjD6lFALl9VmIdVJ8MTCT HN+A== 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=zFHBvxcNZW2HfjsGIsVhZk87PaG1v642sbVGsClWfxY=; fh=JV0Tlv4hGrexckco33o59fVx2i8EqExbHNxdyu0+66w=; b=A7PkZ+KGTkY+6xDzCOej4Gh1jpin3WFjL/mZOhRNXwf/7Nte9qyGlBcS1SKA7ymCIW jochko93ZkAdZvccN+105ffdzaEpn8AOQz8RWhiwx3+SMwVYjUvQkxfLoRM2K/S61mLN 3BI2i+PzRDVJzzGE603iGEbJa/ej1nU1YnkxLo4RA/frBoZgptKJsT6RiyTMRZJVU2nn mKwGsNxyitlELbSngaZsidesm+/OAjieROzfqn6LGc8XbgKtJY/mqdfvtgrE4iwRTiiA /penF1C+fspKdRa0jEJ12yeeYHi+88OTQE6f10CMBSLuJCg9V+28at+/mRNnLcnNEQNR sS/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vuBnNS2D; 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-54139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54139-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWaMvppJRAxYRMthIE5L3y6S9AtOglbjav8c+zJf9Lltd0NVywr3A2wXRpmuFQ6ciAy32ZvZ9+1m/11cQ70tDOx7u206w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jh9-20020a170903328900b001d72907f487si716720plb.56.2024.02.05.17.09.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 17:09:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vuBnNS2D; 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-54139-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54139-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 7DFF6288523 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 01:09:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F76E15A4; Tue, 6 Feb 2024 01:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vuBnNS2D" 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 29B474A06 for <linux-kernel@vger.kernel.org>; Tue, 6 Feb 2024 01:09:32 +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=1707181774; cv=none; b=oh5n7D06UmQwT/tFDWsP85AUMKvvi1qbL0Bg29HPNqSoXYzmfAlluM1jiGMWxd2VaYxHxkXZUknY9T5Z1bpxrRGzxQOwo3Rp4GeD5DRNwEDaeH5j7kXekEGVnyypALZQl25ViXFfGxJdrG33pYx0q+l0pjF5MpIYU6IR8qcmWLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707181774; c=relaxed/simple; bh=GdHdniQnbMOXtlmLfBAIzFnjtasDR34ui/wEy9tYr8s=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=VguWZVE5xi/y81Ud5BQ0LlWU3rbDPdSxGEEnTFGK9AlTEVPlY15I3U6N3Vwq8IoliXH0uw58OuVcj2UTqHWPRk0HZBkcELTWsAmFBQTXjhhSBd1GR2YI5Qj3K2G0RSgykr1tgrTLOWoBzMkuh12gua0ISF1IY2qdUSuaF5XrHQQ= 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=vuBnNS2D; 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-dc6b26845cdso8490240276.3 for <linux-kernel@vger.kernel.org>; Mon, 05 Feb 2024 17:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707181772; x=1707786572; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zFHBvxcNZW2HfjsGIsVhZk87PaG1v642sbVGsClWfxY=; b=vuBnNS2DuUXlqVJ15g75711OjVR9EqNrUnrFoy4+vDmz1KxfJipACqokd3EEMtYFOB M5L949iLtPgfaTpdv/s6ybOCrPn63NCdgkj+WRLJwKB1WYaDFtJVdmnuW8WH/t7BMv5v wDARcLSIRKiiZCCUo0BDJP0mRe44kv9PWKi4BGvd6K4KqOQhZ82UYdHzRG0iuabDfHsN qDbk7B4YVgqfffm2iYoqbngLvu94GKcw5lBcHffBzaeJlO4ciKgs9QkrsC5nuWPnBIif j1JrnSnQXzTU1ugBJx5Qr5QQdONZPI7M0+q5M47CrT8bVd3raBNa6NGigsEyaXNmo5B9 SyAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707181772; x=1707786572; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zFHBvxcNZW2HfjsGIsVhZk87PaG1v642sbVGsClWfxY=; b=d7nAMFe9l03YvgyIkuraTuLwWY38miAte5fjyQDfV+i+mqC7ep4BlE8w7LAUHIMEV8 lZuu7DdmAz2wx7WMdPZvcNWx4GcWdck2YPJ+FaE86aWGsds2rhAVAs8Y/iAC7o6qbY+W YxOj+sCeYl2+4hT2UgT7J3k0wcVHWZmd6pTWrRpszM9UjNMrC7tpWD4ffcSMJkMe85fn hwoidDqlahRJhOkMub0VmO0MUmsCjMXYgDlt89z8223yHsYRYgZKdVAVzVCbFOH0x4Nm 9veM8V0vRjbQWvOY4G3Gbm9aJ6eEbffbJ/qSV7Es6HFfFFySfYemqpyKyCz7FRrahjA6 /sfg== X-Gm-Message-State: AOJu0YwF6423712JKREl7P2W4rswDH/LOPl8E/99PhB+vVLrsTbDiPqy /e0Wds68qrItwpfZU43Nlx6tNXJS+fXtQj1g2bmBfOPVohg4ciCXKnbUXdw4kkwKCv39KAhekaV 0inxIahMsYe0COrpPj691mA== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:713:bb2c:e0e8:becb]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:2842:b0:dc6:519b:5425 with SMTP id ee2-20020a056902284200b00dc6519b5425mr38783ybb.11.1707181772174; Mon, 05 Feb 2024 17:09:32 -0800 (PST) Date: Mon, 5 Feb 2024 17:09:16 -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.594.gd9cf4e227d-goog Message-ID: <20240206010919.1109005-1-lokeshgidra@google.com> Subject: [PATCH v3 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, Liam.Howlett@oracle.com Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790109857415928656 X-GMAIL-MSGID: 1790109857415928656 |
Series | per-vma locks in userfaultfd | |
Message
Lokesh Gidra
Feb. 6, 2024, 1:09 a.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. Android runtime's Garbage Collector uses userfaultfd for concurrent compaction. mmap-lock contention during compaction potentially causes 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 <500ms - Uninterruptible sleep time (across all threads in the process) was ~10ms (none in mmap_lock) during compaction, instead of >20s Changes since v2 [2]: - Implement and use lock_vma() which uses mmap_lock critical section to lock the VMA using per-vma lock if lock_vma_under_rcu() fails, per Liam R. Howlett. This helps simplify the code and also avoids performing the entire userfaultfd operation under mmap_lock. Changes since v1 [1]: - rebase patches on 'mm-unstable' branch [1] https://lore.kernel.org/all/20240126182647.2748949-1-lokeshgidra@google.com/ [2] https://lore.kernel.org/all/20240129193512.123145-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/mm.h | 16 ++ include/linux/userfaultfd_k.h | 75 +++++++-- mm/memory.c | 48 ++++++ mm/userfaultfd.c | 300 +++++++++++++++++++++------------- 5 files changed, 331 insertions(+), 194 deletions(-)