From patchwork Wed Nov 20 00:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13880637 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 93927D6C2B9 for ; Wed, 20 Nov 2024 00:08:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 264CD6B0082; Tue, 19 Nov 2024 19:08:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 214E06B0085; Tue, 19 Nov 2024 19:08:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DCEA6B0088; Tue, 19 Nov 2024 19:08:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E6D896B0082 for ; Tue, 19 Nov 2024 19:08:33 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7A8AFADB24 for ; Wed, 20 Nov 2024 00:08:33 +0000 (UTC) X-FDA: 82804533336.17.7C43B66 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf20.hostedemail.com (Postfix) with ESMTP id 4FD191C000C for ; Wed, 20 Nov 2024 00:07:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=U3iYK4yu; spf=pass (imf20.hostedemail.com: domain of 3fig9ZwYKCAUxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3fig9ZwYKCAUxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732061067; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=HhkVFKaKFpcTeqNIviXTm8CkZrPqzcwTU1/BoH3xVxg=; b=i2bMrO+v+VI1sI87DB9t4ZI+HGJ6ksZ/AWS/fk2SlY8FF5Rm+qNGswC+YzHkp8oj7TSJHb ut/jcYZ1EsbaYrFIE2SH54KwuTMEY3R6tzXgtv6XiiNAmlPiAw7RmYSxsxn1eAcVSotGB2 9CgvLfJAfhxgRsqdme/tGWNeSf1UBgA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=U3iYK4yu; spf=pass (imf20.hostedemail.com: domain of 3fig9ZwYKCAUxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3fig9ZwYKCAUxzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732061067; a=rsa-sha256; cv=none; b=7uI1LVP8adTby63s83niNFMJxHloBCZM34I28T3RoEP62vM98khcxk/NqcYtN2/N21NLDY 2mbJnmf3NjfZ0E8nYzyKj9IczSJ+QvQUmk/n3xM8+WDUkp2a0RtmdrHBBl1sGWX2XCyXTy 9j3XG3rVgxgbJiAmATm7Pm4fHRihZb4= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ee6c2b65b9so30050717b3.0 for ; Tue, 19 Nov 2024 16:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732061311; x=1732666111; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=HhkVFKaKFpcTeqNIviXTm8CkZrPqzcwTU1/BoH3xVxg=; b=U3iYK4yuvZ7MGd6pkC9gxiwjNLvqdnRWlilJY8nl0fS1fwZrEvb5sYGeJkj+qfSZmn W5+62MemGzlKCxgQNz3QQuoY2g9VoBBv2pufXa1K9J9rJ3NgFrcCTMtiPj274I3QySAw zQEENE/h4ymXKpyFS5N789Nm75f2aJTr+d7gBQ646+mW3xC0neoZ4UImGnA5BJUNXpJs g/oRBcFmo2amM8dQG+5WR/h3nBBLXNeUCfehiFD04MptBkIt3NxR3ctPUJgyC+P7tov4 uT4m3+d8tcMNunSGXOac8E8nsjYLSCeWppWUssDFL0jl2ERp9NCKr8kZmSezgZiyNjDs 22IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732061311; x=1732666111; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HhkVFKaKFpcTeqNIviXTm8CkZrPqzcwTU1/BoH3xVxg=; b=hsK4wIbRtL+U4u8fDFwkXWEQN7RRJ+Av6XCek1zJT40l+Z2x4r0bfqmLuVDaGHxV+r Tc25OEsOHRdHa6trL+RQybpP/ZBr+90xTe+uOG99sUJRfjpgZrW+jV+AziZvBeQylJZs sZ2MslQH7rUrUpwaIOqTIQl1sqHmewaJ2XL+7oaPk0qJ8WRz5ddn0Uro+7+YFqcXKIGr uEjNMyyk+Qh7on5diSN67rofVRbLPqou/yUYB0cejnH7uYXZyBUDzmZlsRnX28UEOy0W A9A302KvsPnjjrAY7K8Xcf4U98IVyDecryWUWve9X0o+ynzqX+MdyGGe5x3U7U9re0SE gdIQ== X-Forwarded-Encrypted: i=1; AJvYcCUqBooxV+qO8hBPxk5WVfVjdKe+UnhS8bUnGqxoPWIS7LEOeDpdqfYrjyT+YfzLoXX2r8qGLVFWww==@kvack.org X-Gm-Message-State: AOJu0YwYM6bnkdIC6gif/dHedOAInVfDKo1TWzzZ3uf1L9xURZZ/EUHX gPOY1zofvQBBDVhPIvhnYT4zE4n9E0NQJPs6+8p9dZdU6mR32kMIgjc1K6pmL0sOxMiMe1/oVti QFA== X-Google-Smtp-Source: AGHT+IFYtV6elF80k+BXreudN05LyJlyHTc3YJNvvK+QdV7SDD9vZ+RL+IezB0evCebjjGetlGWDr+ddLDI= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:af45:bbc1:fc75:e695]) (user=surenb job=sendgmr) by 2002:a05:690c:209f:b0:6e2:12e5:356f with SMTP id 00721157ae682-6eebd2b6dbamr4027b3.3.1732061310472; Tue, 19 Nov 2024 16:08:30 -0800 (PST) Date: Tue, 19 Nov 2024 16:08:21 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241120000826.335387-1-surenb@google.com> Subject: [PATCH v4 0/5] move per-vma lock into vm_area_struct From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4FD191C000C X-Stat-Signature: hc547iufnn1mn79o8ejhrkwifgdd91et X-Rspam-User: X-HE-Tag: 1732061248-192869 X-HE-Meta: U2FsdGVkX1/tuRA6VGMuCNEC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bEq2OJGOu4kvVW9zxhKedoaQL+wXDUdqKvQnKY6bxgTM7j8x9Kjux7HKyLczJMiDUcS+UCr6hPW9GVkPQLocUUiGe7J8cJU2umOCSkp2wLKJdiCHDXRssVRGJIPXI85+9ab2xdR8NFmnVbE6sv6lxkzE9oL1pP5c0Q6/KY6yK4/ymykC41LBfItgDEW/Rgja/tbk/etigTkci3tSouhMqyI/PrecjIOgjSPUCvxfKH9N8tCrn8iJjtgXrABawvYbnF7Zu2FWisIaFlI/HPmjLPk3oiZPaQnQ1h/sGcmA37S4vbA1FW0D8W/AGgxSBnK3laMrcoSB9r+bqDnpPi+CAROx0jxPfs1psKY1Jbedj+j4eh6K/GMblmB+jojV303iB2YwVUvJjSHzqBnTCjLv6T3iRPQtzm+XJV2jLvqlJNt61vexQMbAyVI0fRkffUvCMQ6EZbdpSLLnJFhf+NWQRJDs+1O7x0q1PqL2ZaPy5iSQ5W6RtgFdjbgov0PFXhMuZhBElJd37Pw6PsBULkknRFy 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: List-Subscribe: List-Unsubscribe: Back when per-vma locks were introduces, vm_lock was moved out of vm_area_struct in [1] because of the performance regression caused by false cacheline sharing. Recent investigation [2] revealed that the regressions is limited to a rather old Broadwell microarchitecture and even there it can be mitigated by disabling adjacent cacheline prefetching, see [3]. Splitting single logical structure into multiple ones leads to more complicated management, extra pointer dereferences and overall less maintainable code. When that split-away part is a lock, it complicates things even further. With no performance benefits, there are no reasons for this split. Merging the vm_lock back into vm_area_struct also allows vm_area_struct to use SLAB_TYPESAFE_BY_RCU later in this patchset. This patchset: 1. moves vm_lock back into vm_area_struct, aligning it at the cacheline boundary and changing the cache to be cacheline-aligned to minimize cacheline sharing; 2. changes vm_area_struct initialization to mark new vma as detached until it is inserted into vma tree; 3. changes vm_area_struct cache to SLAB_TYPESAFE_BY_RCU to allow for their reuse and to minimize call_rcu() calls. Pagefault microbenchmarks do not show noticeable performance change. Changes since v3 [4] - Added SOBs, per Lorenzo Stoakes and Davidlohr Bueso; - Replaced vma write-locking in vma_mark_attached() with memory barriers to order accesses to vma->detached vs vm_mm/vm_start/vm_end Patch applies over mm-unstable [1] https://lore.kernel.org/all/20230227173632.3292573-34-surenb@google.com/ [2] https://lore.kernel.org/all/ZsQyI%2F087V34JoIt@xsang-OptiPlex-9020/ [3] https://lore.kernel.org/all/CAJuCfpEisU8Lfe96AYJDZ+OM4NoPmnw9bP53cT_kbfP_pR+-2g@mail.gmail.com/ [4] https://lore.kernel.org/all/20241117080931.600731-1-surenb@google.com/ Suren Baghdasaryan (5): mm: introduce vma_start_read_locked{_nested} helpers mm: move per-vma lock into vm_area_struct mm: mark vma as detached until it's added into vma tree mm: make vma cache SLAB_TYPESAFE_BY_RCU docs/mm: document latest changes to vm_lock Documentation/mm/process_addrs.rst | 10 ++- include/linux/mm.h | 129 ++++++++++++++++++++++++----- include/linux/mm_types.h | 19 ++--- kernel/fork.c | 88 +++++++------------- mm/memory.c | 17 ++-- mm/userfaultfd.c | 22 ++--- mm/vma.c | 8 +- mm/vma.h | 2 + tools/testing/vma/vma_internal.h | 55 +++++------- 9 files changed, 198 insertions(+), 152 deletions(-) base-commit: 5a7056135bb69da2ce0a42eb8c07968c1331777b