From patchwork Thu Feb 13 22:46:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13974130 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 4F9A7C021A0 for ; Thu, 13 Feb 2025 22:47:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1790280006; Thu, 13 Feb 2025 17:47:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D50F5280001; Thu, 13 Feb 2025 17:47:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5561280006; Thu, 13 Feb 2025 17:47:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8A427280001 for ; Thu, 13 Feb 2025 17:47:07 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0C8EE1A174E for ; Thu, 13 Feb 2025 22:47:07 +0000 (UTC) X-FDA: 83116408494.25.ED6BBA4 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf05.hostedemail.com (Postfix) with ESMTP id 325A910000D for ; Thu, 13 Feb 2025 22:47:05 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=B8z894AU; spf=pass (imf05.hostedemail.com: domain of 3Z3auZwYKCFICEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3Z3auZwYKCFICEBy7v08805y.w86527EH-664Fuw4.8B0@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=1739486825; 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:in-reply-to:references:references:dkim-signature; bh=nixUczrejX4FKBcz+HGm8JxV/4Rz6UEjTIeiIS536Tg=; b=ypiVGzS0r4U1kW4z1ykw9n7n857/AIMmrmeDEMifDA1+t8JpxLckIc56snRlYCtxaQXMJI gS5hSawTWaNPuJwFHnCne/ZoASjOEsA3QDsa65XeyofQHdkXcpYME26l3VX1ylyCxrBXp8 RvRidxEJcgcB90iiI+RmlD1cTV47yso= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=B8z894AU; spf=pass (imf05.hostedemail.com: domain of 3Z3auZwYKCFICEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3Z3auZwYKCFICEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739486825; a=rsa-sha256; cv=none; b=qu3q+mFAKAzmFJ6agkQegesFbSSHuv2+q5CPuqiOouu0zU5VMk5os6w3kD9OGqdR2GsQAn xtzcNEpF3quOqKRF0VKocXf/+KuUAHyrzxvna/QjxSAcqmuyGEZPmDfHEM1kIEnlalEwf2 d3C9fXLobtUYy1ENME0rKq3yQeSTsxw= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-21a7cbe3b56so23867445ad.0 for ; Thu, 13 Feb 2025 14:47:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739486824; x=1740091624; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nixUczrejX4FKBcz+HGm8JxV/4Rz6UEjTIeiIS536Tg=; b=B8z894AUSbbV61fwvLK0Q3EZqVQqzwoQlbOY94OLrfztJ0mq1uX3IKe0vA4Gw4julA HBWVkpGUPxQnD3TnuWCG8PkmO7MJWm/WBYJCGe+1dyWPNIO5PRwuY283ZsMa7g/m/dkB jOVEcp4b4MIZlX+x6JeLmBGbnkQaHUMqvnoA595eRwKNbnzsN1Nv27HpKD4qDZKzV5xg PLSfE9rz4RtjPU4c5YiFb/BdObCs6Ix3CoNIrQTi775LX9G+WU+DYJhkicx8UHLm3vC6 d3Ji3nDWytKc5Bfsx0BHAOzmmk+aMoklKTGCnN/EhIBkWbF7wmjJS3cZMWX8aZpZML/x B59w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739486824; x=1740091624; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nixUczrejX4FKBcz+HGm8JxV/4Rz6UEjTIeiIS536Tg=; b=K0EZ1SOB9/I4QsZOkg3jVJbTG63UbYUONN7T1fYjVbwVGBDMapgBPKzPImtj67ZLi8 65pPWQNffULTI6SJn+ls1VY6ZiMIjVRt5/VeaSi8yxsmt2vS44D5AIz1JJlcSzCqzSyM 7V5IfcFiAJyb1glbOmsCaI4ZyjDflJ5p+ybmTMHE80XkyuZgY2EhN5IrCjvNukWKJq1b J4vZzXhcd1SPJac8J/+TF02Wm36JHKiQCZfKLO3GnJG8Ev7z/SNn9hiUjIU+LT9tbYN/ wh+2KQ5iuLszjnLQKgaDirBPk3nWi7IPfJq4Dnlla5e6TmWDu32bfDx1n7ZcaXG17tYJ jIoA== X-Forwarded-Encrypted: i=1; AJvYcCWG80cFDyO1ZLLsaph5r/cLhqxm+Qk3+sEy7FGJc60P17H/vlnkvUrUfgT4Hg6HxaF3KCUWui+5SQ==@kvack.org X-Gm-Message-State: AOJu0Yx8FQUMAj6dUkA3el7jWIfxQ0DzFB++l5wW3mhffdr1BOdswD8q FeI5Hm89aqrIIesBH/EZI4fc0MJxtoY2YMJhdOTdlaxxMvnRDGIihVyotg83a25XtwzeRFPYqUj uhw== X-Google-Smtp-Source: AGHT+IHexWPTyEo/ZnzJkqYLOzvXPZYi2c9eLV49bS4E26ucZsJK7lHyl46qKggig4vIRb/FsPaNzCiwY30= X-Received: from pgjp13.prod.google.com ([2002:a63:e64d:0:b0:ad8:73cf:4390]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c998:b0:1ee:1e05:206d with SMTP id adf61e73a8af0-1ee5e5b7c8amr15452640637.21.1739486823384; Thu, 13 Feb 2025 14:47:03 -0800 (PST) Date: Thu, 13 Feb 2025 14:46:39 -0800 In-Reply-To: <20250213224655.1680278-1-surenb@google.com> Mime-Version: 1.0 References: <20250213224655.1680278-1-surenb@google.com> X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250213224655.1680278-3-surenb@google.com> Subject: [PATCH v10 02/18] mm: move per-vma lock into vm_area_struct From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: peterz@infradead.org, willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, david.laight.linux@gmail.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, lokeshgidra@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, klarasmodin@gmail.com, richard.weiyang@gmail.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, "Liam R. Howlett" X-Rspamd-Queue-Id: 325A910000D X-Stat-Signature: kaeicw6rk3nhjjre5b4cu4x1re5ko8em X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1739486825-639567 X-HE-Meta: U2FsdGVkX1+RM15k5almYJgl+G0G3+SINKehfFdSdufmYphcPdNwmHNW3eYycmp7vrZcvDohROxydMfdCcSZJH/P0q9QGRzTsqgKTaAjWfj30h/mN4DCXYFdT4i1dg8ScmeHABha4IbHYBtbzHykP4Vzp5QUnQILZi8wajxlJmPawBFUGjgbRWTa6LY5Al47k5Fj0Il9zpiqNOdPS503GC0h8fs5AZ3w/+CS5/klaOcNhwB+cWpr6AfyeTRnUWcjssR/7NGK+kwWciyNJasfonciFioVeXDbMRu+AbPzZ/kVM6YOTbwP/Us3iddifYRC0LHF+Xzbd0VGs56eMHxdVFDueIuz3mvEgwc+eF7iTXPsTXsEuGProSgbrJr2x6iwZKQJUMKN8yeKLzQPgEkFslyutQWjyEpi2ZFrUNlkWqgypOhPtP/0A/meAJNJK8CESo7ola5W9KnRfNsyRnLLpggr3d2pYLWk7RBoloqTpXQxJ9FTh5hkspFBVb8kJtS/U7sL0qZO1u6AN/dhIMrXxruLB3IzyMS2RotcIseaMxO+qzMswmmiW4RI5gbC4d5ibFp5G/eqh/00gSM9pBP/a0jEOtSXI4cSdLlLcdYX5Ax6FBSCxbWLCfHi+ExLV9Ni659yg6cCLDNuzXbFcZeUsvEnT3ILWZP1dgIyzoLo5NHrWFTylC/AWsvvnR/S38lVr6U4Mk0QUIuZsOHxXDqJB5AdaWICKg6J3mC5lA9mCSbXwVvMR8MRku3NJeniFlkK4DctMmb4MLv0skHOjFPuDYk13nZctUOX0sSXvs//mJqH3BUk+L4bphPkqTuhDZZza18YB+sHcZUwOGnxQ23eUj55DJGBte5m4tonMIkU+Rvik3T1s2x9fD4BmMcEpxXcH4DLE8LoYA1FFYzrOqWSJlwiVJafGQdOM0oN6052KkYonAu3NKGEUULizJjAXKO+pF9CBifeH5Iw5+0y7B9 h8poJBuS Trxjd14Tj1o17ExLGb6OM3LtVBhgO8/0JoTUpcXrLH5CbfdojmkjAequow8TQ2z4qcR+wDjAc9h80JPUe9gNYs8ZIkL2/m+oCnmWytR5mrGFY+eQ6eGniyDiZGIWgNWR/5NFiuKlJYQ5cLw7VXIBQ1x7xQ1QasaeHfbEXVA8basC6EW1AbTWmqOwO/QEdV3UOk/Ml21Bcr5DcGHrlI71/9BpPrpZDDGARJdXwDtPZhBT85HBuZj7A3LQyQJhsyhpflUQdmLW6SjsGPtxKQ2K45SLW0zfgu7N0jvp4TEcGr4zwSP2DjMICXK8WLt5lAVIbkGcVIecsgLfjftWe+IPGo5tYxn0tTCI0O+92TPzOWCvcDQsOTPhYW4+rjshyLOxDC/oJ1ucfgNp5RFhCtN1zJwh2LDTWSMHK3KyfeA0lw1ol31xk1Fps6pvaEmR6sKB+1QGQ7vr4Az6IKuJvf9Ef/onitKytjNnFDWMCgFvAi9p+a/GSv0iLBKhxiOMiyeU9mdgcZgSB5XV8qhTlvmq8O/PoHTy01UcKzvkCWU1A3LFbYZfx4TTxtwV/68PP5FSF0aTPTT/Utw/WCzJO8SJgv/FZViVpUXjLnMa7TSOrGYS7mE7YgETjeOCpC4FygBnXCgabguggYmGWVA+ZKZPZWnvUYrDzRXA/5Yt5P+OKASxYc1XZcvrQB7uQqK4WK0jBNy3UcaZcmSg7ljSCANm1vC9m+PwGTufJNOaS 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. Move vm_lock back into vm_area_struct, aligning it at the cacheline boundary and changing the cache to be cacheline-aligned as well. With kernel compiled using defconfig, this causes VMA memory consumption to grow from 160 (vm_area_struct) + 40 (vm_lock) bytes to 256 bytes: slabinfo before: ... : ... vma_lock ... 40 102 1 : ... vm_area_struct ... 160 51 2 : ... slabinfo after moving vm_lock: ... : ... vm_area_struct ... 256 32 2 : ... Aggregate VMA memory consumption per 1000 VMAs grows from 50 to 64 pages, which is 5.5MB per 100000 VMAs. Note that the size of this structure is dependent on the kernel configuration and typically the original size is higher than 160 bytes. Therefore these calculations are close to the worst case scenario. A more realistic vm_area_struct usage before this change is: ... : ... vma_lock ... 40 102 1 : ... vm_area_struct ... 176 46 2 : ... Aggregate VMA memory consumption per 1000 VMAs grows from 54 to 64 pages, which is 3.9MB per 100000 VMAs. This memory consumption growth can be addressed later by optimizing the vm_lock. [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/ Signed-off-by: Suren Baghdasaryan Reviewed-by: Lorenzo Stoakes Reviewed-by: Shakeel Butt Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett --- include/linux/mm.h | 28 ++++++++++-------- include/linux/mm_types.h | 6 ++-- kernel/fork.c | 49 ++++---------------------------- tools/testing/vma/vma_internal.h | 33 +++++---------------- 4 files changed, 32 insertions(+), 84 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 16b3cd3de29a..e75fae95b48d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -697,6 +697,12 @@ static inline void vma_numab_state_free(struct vm_area_struct *vma) {} #endif /* CONFIG_NUMA_BALANCING */ #ifdef CONFIG_PER_VMA_LOCK +static inline void vma_lock_init(struct vm_area_struct *vma) +{ + init_rwsem(&vma->vm_lock.lock); + vma->vm_lock_seq = UINT_MAX; +} + /* * Try to read-lock a vma. The function is allowed to occasionally yield false * locked result to avoid performance overhead, in which case we fall back to @@ -714,7 +720,7 @@ static inline bool vma_start_read(struct vm_area_struct *vma) if (READ_ONCE(vma->vm_lock_seq) == READ_ONCE(vma->vm_mm->mm_lock_seq.sequence)) return false; - if (unlikely(down_read_trylock(&vma->vm_lock->lock) == 0)) + if (unlikely(down_read_trylock(&vma->vm_lock.lock) == 0)) return false; /* @@ -729,7 +735,7 @@ static inline bool vma_start_read(struct vm_area_struct *vma) * This pairs with RELEASE semantics in vma_end_write_all(). */ if (unlikely(vma->vm_lock_seq == raw_read_seqcount(&vma->vm_mm->mm_lock_seq))) { - up_read(&vma->vm_lock->lock); + up_read(&vma->vm_lock.lock); return false; } return true; @@ -744,7 +750,7 @@ static inline bool vma_start_read(struct vm_area_struct *vma) static inline void vma_start_read_locked_nested(struct vm_area_struct *vma, int subclass) { mmap_assert_locked(vma->vm_mm); - down_read_nested(&vma->vm_lock->lock, subclass); + down_read_nested(&vma->vm_lock.lock, subclass); } /* @@ -756,13 +762,13 @@ static inline void vma_start_read_locked_nested(struct vm_area_struct *vma, int static inline void vma_start_read_locked(struct vm_area_struct *vma) { mmap_assert_locked(vma->vm_mm); - down_read(&vma->vm_lock->lock); + down_read(&vma->vm_lock.lock); } static inline void vma_end_read(struct vm_area_struct *vma) { rcu_read_lock(); /* keeps vma alive till the end of up_read */ - up_read(&vma->vm_lock->lock); + up_read(&vma->vm_lock.lock); rcu_read_unlock(); } @@ -791,7 +797,7 @@ static inline void vma_start_write(struct vm_area_struct *vma) if (__is_vma_write_locked(vma, &mm_lock_seq)) return; - down_write(&vma->vm_lock->lock); + down_write(&vma->vm_lock.lock); /* * We should use WRITE_ONCE() here because we can have concurrent reads * from the early lockless pessimistic check in vma_start_read(). @@ -799,7 +805,7 @@ static inline void vma_start_write(struct vm_area_struct *vma) * we should use WRITE_ONCE() for cleanliness and to keep KCSAN happy. */ WRITE_ONCE(vma->vm_lock_seq, mm_lock_seq); - up_write(&vma->vm_lock->lock); + up_write(&vma->vm_lock.lock); } static inline void vma_assert_write_locked(struct vm_area_struct *vma) @@ -811,7 +817,7 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma) static inline void vma_assert_locked(struct vm_area_struct *vma) { - if (!rwsem_is_locked(&vma->vm_lock->lock)) + if (!rwsem_is_locked(&vma->vm_lock.lock)) vma_assert_write_locked(vma); } @@ -844,6 +850,7 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, #else /* CONFIG_PER_VMA_LOCK */ +static inline void vma_lock_init(struct vm_area_struct *vma) {} static inline bool vma_start_read(struct vm_area_struct *vma) { return false; } static inline void vma_end_read(struct vm_area_struct *vma) {} @@ -878,10 +885,6 @@ static inline void assert_fault_locked(struct vm_fault *vmf) extern const struct vm_operations_struct vma_dummy_vm_ops; -/* - * WARNING: vma_init does not initialize vma->vm_lock. - * Use vm_area_alloc()/vm_area_free() if vma needs locking. - */ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) { memset(vma, 0, sizeof(*vma)); @@ -890,6 +893,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) INIT_LIST_HEAD(&vma->anon_vma_chain); vma_mark_detached(vma, false); vma_numab_state_init(vma); + vma_lock_init(vma); } /* Use when VMA is not part of the VMA tree and needs no locking */ diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8efafef4637e..8a645bcb2b31 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -740,8 +740,6 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; - /* Unstable RCU readers are allowed to read this. */ - struct vma_lock *vm_lock; #endif /* @@ -794,6 +792,10 @@ struct vm_area_struct { struct vma_numab_state *numab_state; /* NUMA Balancing state */ #endif struct vm_userfaultfd_ctx vm_userfaultfd_ctx; +#ifdef CONFIG_PER_VMA_LOCK + /* Unstable RCU readers are allowed to read this. */ + struct vma_lock vm_lock ____cacheline_aligned_in_smp; +#endif } __randomize_layout; #ifdef CONFIG_NUMA diff --git a/kernel/fork.c b/kernel/fork.c index 735405a9c5f3..bdbabe73fb29 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -436,35 +436,6 @@ static struct kmem_cache *vm_area_cachep; /* SLAB cache for mm_struct structures (tsk->mm) */ static struct kmem_cache *mm_cachep; -#ifdef CONFIG_PER_VMA_LOCK - -/* SLAB cache for vm_area_struct.lock */ -static struct kmem_cache *vma_lock_cachep; - -static bool vma_lock_alloc(struct vm_area_struct *vma) -{ - vma->vm_lock = kmem_cache_alloc(vma_lock_cachep, GFP_KERNEL); - if (!vma->vm_lock) - return false; - - init_rwsem(&vma->vm_lock->lock); - vma->vm_lock_seq = UINT_MAX; - - return true; -} - -static inline void vma_lock_free(struct vm_area_struct *vma) -{ - kmem_cache_free(vma_lock_cachep, vma->vm_lock); -} - -#else /* CONFIG_PER_VMA_LOCK */ - -static inline bool vma_lock_alloc(struct vm_area_struct *vma) { return true; } -static inline void vma_lock_free(struct vm_area_struct *vma) {} - -#endif /* CONFIG_PER_VMA_LOCK */ - struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) { struct vm_area_struct *vma; @@ -474,10 +445,6 @@ struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) return NULL; vma_init(vma, mm); - if (!vma_lock_alloc(vma)) { - kmem_cache_free(vm_area_cachep, vma); - return NULL; - } return vma; } @@ -496,10 +463,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) * will be reinitialized. */ data_race(memcpy(new, orig, sizeof(*new))); - if (!vma_lock_alloc(new)) { - kmem_cache_free(vm_area_cachep, new); - return NULL; - } + vma_lock_init(new); INIT_LIST_HEAD(&new->anon_vma_chain); vma_numab_state_init(new); dup_anon_vma_name(orig, new); @@ -511,7 +475,6 @@ void __vm_area_free(struct vm_area_struct *vma) { vma_numab_state_free(vma); free_anon_vma_name(vma); - vma_lock_free(vma); kmem_cache_free(vm_area_cachep, vma); } @@ -522,7 +485,7 @@ static void vm_area_free_rcu_cb(struct rcu_head *head) vm_rcu); /* The vma should not be locked while being destroyed. */ - VM_BUG_ON_VMA(rwsem_is_locked(&vma->vm_lock->lock), vma); + VM_BUG_ON_VMA(rwsem_is_locked(&vma->vm_lock.lock), vma); __vm_area_free(vma); } #endif @@ -3200,11 +3163,9 @@ void __init proc_caches_init(void) sizeof(struct fs_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); - - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT); -#ifdef CONFIG_PER_VMA_LOCK - vma_lock_cachep = KMEM_CACHE(vma_lock, SLAB_PANIC|SLAB_ACCOUNT); -#endif + vm_area_cachep = KMEM_CACHE(vm_area_struct, + SLAB_HWCACHE_ALIGN|SLAB_NO_MERGE|SLAB_PANIC| + SLAB_ACCOUNT); mmap_init(); nsproxy_cache_init(); } diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index bb273927af0f..4506e6fb3c6f 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -275,10 +275,10 @@ struct vm_area_struct { /* * Can only be written (using WRITE_ONCE()) while holding both: * - mmap_lock (in write mode) - * - vm_lock->lock (in write mode) + * - vm_lock.lock (in write mode) * Can be read reliably while holding one of: * - mmap_lock (in read or write mode) - * - vm_lock->lock (in read or write mode) + * - vm_lock.lock (in read or write mode) * Can be read unreliably (using READ_ONCE()) for pessimistic bailout * while holding nothing (except RCU to keep the VMA struct allocated). * @@ -287,7 +287,7 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; - struct vma_lock *vm_lock; + struct vma_lock vm_lock; #endif /* @@ -464,17 +464,10 @@ static inline struct vm_area_struct *vma_next(struct vma_iterator *vmi) return mas_find(&vmi->mas, ULONG_MAX); } -static inline bool vma_lock_alloc(struct vm_area_struct *vma) +static inline void vma_lock_init(struct vm_area_struct *vma) { - vma->vm_lock = calloc(1, sizeof(struct vma_lock)); - - if (!vma->vm_lock) - return false; - - init_rwsem(&vma->vm_lock->lock); + init_rwsem(&vma->vm_lock.lock); vma->vm_lock_seq = UINT_MAX; - - return true; } static inline void vma_assert_write_locked(struct vm_area_struct *); @@ -497,6 +490,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) vma->vm_ops = &vma_dummy_vm_ops; INIT_LIST_HEAD(&vma->anon_vma_chain); vma_mark_detached(vma, false); + vma_lock_init(vma); } static inline struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) @@ -507,10 +501,6 @@ static inline struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) return NULL; vma_init(vma, mm); - if (!vma_lock_alloc(vma)) { - free(vma); - return NULL; - } return vma; } @@ -523,10 +513,7 @@ static inline struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) return NULL; memcpy(new, orig, sizeof(*new)); - if (!vma_lock_alloc(new)) { - free(new); - return NULL; - } + vma_lock_init(new); INIT_LIST_HEAD(&new->anon_vma_chain); return new; @@ -696,14 +683,8 @@ static inline void mpol_put(struct mempolicy *) { } -static inline void vma_lock_free(struct vm_area_struct *vma) -{ - free(vma->vm_lock); -} - static inline void __vm_area_free(struct vm_area_struct *vma) { - vma_lock_free(vma); free(vma); }