From patchwork Thu Jan 9 02:30:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13931809 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 9B5C9E77188 for ; Thu, 9 Jan 2025 02:30:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFC0F6B008A; Wed, 8 Jan 2025 21:30:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E849D6B0092; Wed, 8 Jan 2025 21:30:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C86376B0093; Wed, 8 Jan 2025 21:30:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 982226B008A for ; Wed, 8 Jan 2025 21:30:36 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 44D421C860A for ; Thu, 9 Jan 2025 02:30:36 +0000 (UTC) X-FDA: 82986334872.30.C10D1DA Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf01.hostedemail.com (Postfix) with ESMTP id 76B4B40003 for ; Thu, 9 Jan 2025 02:30:34 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oML3B2an; spf=pass (imf01.hostedemail.com: domain of 3yTR_ZwYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3yTR_ZwYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@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=1736389834; 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=n13GufSG5JFan3cWwE4IJTcm9x/mZeh3KsDD3Zuaiv0=; b=gMQmemQ30Gd6wW5Qa3pQsuzhtz7djfjsviaPSIjxzOjJaGy5CTSwp59nH6/e2C68Fm/+W0 ecg2M7+3IHU6zhrwwfghlT1dI92qVQTXmLmg6UIouoL5WJJE+6MMLCXMi00O9GG5/Axhf3 cOAegHhWlVGHPuDpK8JPMSezXxJHQ5Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736389834; a=rsa-sha256; cv=none; b=LXxc1egEai5a81FtS9BDj0h8L98viCBA3KjQ/13B5Q76PL60PHyloseB/rjEpJ6jLRVMhi o0weLoS2aLG8gm4TwL301xt+IbLnpoKSKcsknFIvijYuYMvY4J26Wiz33KS1rlUV+x8GIJ gnchXhhtq9kBAe75TtK4pakj148V1n4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oML3B2an; spf=pass (imf01.hostedemail.com: domain of 3yTR_ZwYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3yTR_ZwYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2efc3292021so1160926a91.1 for ; Wed, 08 Jan 2025 18:30:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736389833; x=1736994633; 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=n13GufSG5JFan3cWwE4IJTcm9x/mZeh3KsDD3Zuaiv0=; b=oML3B2anS4X52JojWsIQuKSg697Zbom5cVZlF6ET/g+ICFcYm8tcqtOmHGQz0rSpGe 6bnGZhOUwdSXNxFfSAt5V3Ronorv6NwQsI39NHdQepT/bmfl24EJVL8LKudAwm9hKHwW /3NuViZ5XKJYWf4j9XAkS2U+keNP0CQ+bZvDD9B1/phfHXHOQyYD0R52v7pyyE+6EgNv Htvq4RqDJ0kt/C9m+hRrQgzwIzwe0Ott6Uq+rAGcbcwmeYdqCNw4LtjIteLdbRlWU5kQ 81gK9bl0NqP2gjkFEcO78g0wAgMbN2PVB+HZufmbmwbzLbk8f3KXkRSwtPqslLsjjKYi Temg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736389833; x=1736994633; 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=n13GufSG5JFan3cWwE4IJTcm9x/mZeh3KsDD3Zuaiv0=; b=R735lP9RV9S2KmBz40TG6ZMw3suK9r4KTh7Fc+BrHAXJOqBCVDnr5EiRVCSMrMkSnQ IFbDHhVebRhpQWrWryhXEhrw/Gpc41cVHPaHARKnBzfxelN8qj4h81ozMMCPPt9/vrkh pAEW2OwXi0MWWpiEEsnSY48wGSF7E/qyAO/QBCM4mZ/T0Q3eV1zqhzRBYjI4dzxrbtzY J+/vucus7XJlfvGEdOP65VdTtG3jw6HXzQYRLAMJXFku10PG4CO1g/WHz5WCcp3qgbd1 87WjHMWDEewzhLuHiUJuZb2qic5kXAx1FsqKyNM9g18pDHu+anpprTTXozVbZMvrvTW0 yEsg== X-Forwarded-Encrypted: i=1; AJvYcCVzw/ZVZIJqBozJ8PmgQc4iQ984yG7QcKjgvKDxkLbuH7MXohjfzjYcuCZPmrsGBM4CxE9ou8/BRg==@kvack.org X-Gm-Message-State: AOJu0YzfjadgSBdBQ4dV8IWeS07oJaNB2q/8YvhqKGlfjla7+rHfGNTg ys9QW+Pq7veW6E2lMIGSL3Wi4w0/xyjoft6VoKUdmKcWWq8RX/oEbccEMsprg0eINSFTkGfpR4d +sA== X-Google-Smtp-Source: AGHT+IGBuBHPJFwa+WnmyRNuk6q4QQ/D91Vih/bjyZrS7FqQF0qJtxsRqNnpS2q9DSPjt8+5JEu4B+raBhE= X-Received: from pjbsu4.prod.google.com ([2002:a17:90b:5344:b0:2f4:47fc:7f17]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:c88f:b0:2f4:434d:c7ed with SMTP id 98e67ed59e1d1-2f548f34ee2mr8134361a91.16.1736389833219; Wed, 08 Jan 2025 18:30:33 -0800 (PST) Date: Wed, 8 Jan 2025 18:30:11 -0800 In-Reply-To: <20250109023025.2242447-1-surenb@google.com> Mime-Version: 1.0 References: <20250109023025.2242447-1-surenb@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109023025.2242447-3-surenb@google.com> Subject: [PATCH v8 02/16] 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, 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: 76B4B40003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: faxa3wrmbj97k1rp3g3m849eufjjcbfy X-HE-Tag: 1736389834-230316 X-HE-Meta: U2FsdGVkX1+zmwkzLQ7zGNYl7VObiqTowku1qiYjt1V1yXHozwd/gFH5e81jTTa6xIc9U0AbZyhqeSn8h+y1GgZAoq51LIrwFokkIOwg85itxJEX5a0/zMC/lRBSdMKQZ+EHO7bBPsYWhVpRxLUa+eBx/n8E9hFOiWlCMRwEt/9qFWT37qc6YsJUAmit8wDf0LytHBvKVnHAmY3Yvmtg/d4yEO1TeT0+a7WcNI3MvSzLqqHydwgvn4iaPfjIHf5Fo32XEDpvRD8KYouFEPO02mZ+7VUXTvPt0QGfkW4LrOiVxjT4jeUarm6scAsu86Yu3k0QZ+vI3nN5oWd04S5VsBJXpQ9RnzepgAhHcncH9UVILwJuqUDugBIhf173ooB5GalgalqhycCrTUAHjkZw+g83YINhOlQQZN59iNAEBMj7TmfwOWv7oILH0rCKjoUN4eRHA/EUBpBUVz6P7DpfSV1wR6By/7ygu/pHjgpnpGIZ//MksXE779kbieRTzo8y4OLKaDH1U3MbvMTEpPa4+TfdqgdpoSObG8yRLlkWfF9b4FxqiUgEjfo1AmmrrtLKxlutFVhEXGrLwKbeG82tjKhE2oYtmwL9K0vWHtpeGOZcrYpARaifqUeMgIdlTvsD8k2wscP7xx4FsvcFHwpXAMSes1R3QfykpB+NmoYaF2DBjKIP1jYH6C99m0Va30d90ELZGeVGpbe9fC1AX58oSdLYxY9TibJipQmDgnC7nMZQId5cr54XYUU0dzh4fxBSXNh3PAg3ao8RENlQ+ZF8vaixPjze8i97yO6dM7Dj6QxcNOP7b7tT+lufvFClJHx5SlQCJxPVdEBUpfay/CoN8rq8r/tLjS+GfljDVjOCaT4M5LJeSRT0iTWEkuHnW9VucmzaZ0gkr4bu5NIP2vTJ6cRLpk5V0foPMAAozn3HJa+CIh65Y5cG2KUwLw7OalyZb6kCIhq4CHRXLt8s164 KvERLI+i PUzHUjJXPEcZxXN3Hi9o/cXAJCfO88z20UGVJZeB3Xsfrye2T/jp7S+5M3uIyO6smDyfhpnBpOB/iMBR6zfBPOn64oRuSw0ihAL2pUbj/ZNb0I44qydPXSEiW5cR4k6d2xAmUOaWQOT3fTcBwKvtr9dYbpkwXyqny4BM8Ebxfup6WKdIzN9ZcEAH2ve0gweVhPufncrOgheteEB2bk2LzEBr7qcpDvjZin97tCRKm5OoYoo8zDImzXoh2rtEsZx/NhOw39Ug9zTIIMuC8cPe1OikMPVX4Hk7EA+MGPqPM9UHfG5WTd9uWQzJZtjT3Mh0r/Wvm3feGvhUUFY05X+43uCGCCdhhRapDu8PDMJuW1eCsHVujkH2nZ/Ps8YtN6xEWrn8v6DQoomg4NvsKMqW12RIAyxrTThD38JAQHVYTneJXtAPbqqUq/vDEIVU9tkPLsw91hX135KcnQEZX3vHdzvFvyVP3GnZb+LdEhUh5U+r1/cvXt8XWQK7rvMCVOsoH53xm9qpQDLrKEVHqVcDL+vMwwk1t+8sKa8oYRGRdfG9qYHUEiVzcbriHr4YtqiewcX/73267aBk5AW3lbfOrTP2R2jVm6nJ0+uYjLLsyNiLs/O3G26FMZ1tuKbyYnOxrvuoBjFXDSjAKWkKREDEDONlY8VV2Vg9DMIOEdJ1nEryZ6Hp1DpKikc8zWlK/aAN+7XSkm5yMq0hZcT/d90rW9RaWvS68pOReg8Fr 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 b040376ee81f..920e5ddd77cc 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 70dce20cbfd1..0ca63dee1902 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -738,8 +738,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 /* @@ -792,6 +790,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 ded49f18cd95..40a8e615499f 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 @@ -3188,11 +3151,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 2404347fa2c7..96aeb28c81f9 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -274,10 +274,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). * @@ -286,7 +286,7 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; - struct vma_lock *vm_lock; + struct vma_lock vm_lock; #endif /* @@ -463,17 +463,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 *); @@ -496,6 +489,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) @@ -506,10 +500,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; } @@ -522,10 +512,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; @@ -695,14 +682,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); }