From patchwork Sun Nov 17 08:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13877797 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 50E6BD68BDD for ; Sun, 17 Nov 2024 08:09:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFE619C001A; Sun, 17 Nov 2024 03:09:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CADE46B00C3; Sun, 17 Nov 2024 03:09:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B28CB9C001A; Sun, 17 Nov 2024 03:09:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8D27A6B00C1 for ; Sun, 17 Nov 2024 03:09:45 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1D1F21A016E for ; Sun, 17 Nov 2024 08:09:45 +0000 (UTC) X-FDA: 82794862668.14.5E7DFCF Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 4368740010 for ; Sun, 17 Nov 2024 08:08:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MXhbcmJw; spf=pass (imf07.hostedemail.com: domain of 3xqQ5ZwYKCDclnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3xqQ5ZwYKCDclnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@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=1731830784; 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=sPYYZoVCqtknZIayzm8p1ItIUlzdQ0oYPahBTNB5G3w=; b=oUppGrR+vN7B4WGl3n9ANrxnCJGO5TWOEpqIKh0hoJBrCMNmK3wW9NiyQDriw5lCZrqy+C pM++Q/CAX0Z+m3PCdRGjOHgKHSRwzFpZi1iHrTqZGbn9woR0/AFNZi0NEEQHC3GfQDQcRJ ieZgkGSPOPJgHtFixCpdlUnHZdMbkcE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MXhbcmJw; spf=pass (imf07.hostedemail.com: domain of 3xqQ5ZwYKCDclnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3xqQ5ZwYKCDclnkXgUZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731830784; a=rsa-sha256; cv=none; b=raAj3cowjrV/gAIZ/Z/Pn/J2LaThQnSUuKwIVTTzfiqF46pdCQzh/iVtZx7O46rU3KvD5h BExqwC5c5rx3gTKfik4GBdW1KAgFRw409xUxRVl8GUWXZAF8z9z58I2qo89+TaAmzWemBz m0+c4sbck8XzL+grcyQUyG/lIsVdnB0= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ee6c2b65b9so23988097b3.0 for ; Sun, 17 Nov 2024 00:09:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731830982; x=1732435782; 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=sPYYZoVCqtknZIayzm8p1ItIUlzdQ0oYPahBTNB5G3w=; b=MXhbcmJwYnW6QGjbTWseF+5MU/R9lbgXHPt73NfFOhr3jALs+KaubOmJ0V4pnaMxym utSgRpeC+TSE5ZoPLaZsjOt3og8fmZjFgAjC/TK49XpPLwABDMyTL8GQKxipIvwuKs87 7j9dDaIErd5doSBDWn6xU8XmwT+FxEvNqlnZjNIUTLt4N4v6cvstd+x4NdhfGlFh//EQ o1w0AxkAZ1RuSfnnLWC//90NFSRus3vGUqqXEcbPX1Pv2T/rdscpZ16DrHivLaZMMpJg /S0MKWDkECVzNyG0uWdqEANU/bIH/EZXTwrAW+xgeOjxRddTKw2ww/wqEiNr0iAkomt+ BxyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731830982; x=1732435782; 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=sPYYZoVCqtknZIayzm8p1ItIUlzdQ0oYPahBTNB5G3w=; b=Pi/02jRMYaYgOv6p722b1c2L6KoLYqvCqKkMg2PKJ7hn6qJfiqXuK2X3lsOP/cNtVq bw8HOybg8d2YnkME8bNhTRTM4rFz6m1vPCHZDEqqshrilRi+TdHro/LQ2tny2g6WJUst mPHxkZmSO2y4e2UgtFP6EFACMdndWwjwSyFtfieePiuqYZg3dsTB8IF8W43hEozJL9lP 2rFn92u4LoBwIxl6Xvb3J3WH34SMY2hclCZuqbHfB3Rv0p8WFl21bnyaDFR8ZxZHdBOw 7oHuba/jg9rlid02CaPoXECle8v3p9upH40HbJgnevsEvaz5livO3TczS0Q5gNLO3gze IwZA== X-Forwarded-Encrypted: i=1; AJvYcCUH77u03rW86nBxNOz0ZHb/0kgUlqX3zcP1tNLVDqjNVpi8/tclr/D4Bsn7NM103mZwoj+PyO1qKA==@kvack.org X-Gm-Message-State: AOJu0YwVNALHhXVZXWGKZs1w1Rk95rBbjXBn2X7Sm+uHLk+IQmko0Xzy /dLTigSrZ0zGhP9IJX7DftK5YF+aW0y1QqbRDqw0TVfF9gIHhzgm2kYo0JtVjJQ/KU9g8Fpe6cS XQA== X-Google-Smtp-Source: AGHT+IFmq2c1p1+TPAUk2jQ4A7Cpj3uaypUiZEZvBLe44BDcqceNyYvrL452knc8vwv/9E7sGLOMSXBRweU= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:bafc:6633:f766:6415]) (user=surenb job=sendgmr) by 2002:a0d:e505:0:b0:6e3:8562:ffa with SMTP id 00721157ae682-6ee55c729b9mr919347b3.5.1731830982118; Sun, 17 Nov 2024 00:09:42 -0800 (PST) Date: Sun, 17 Nov 2024 00:09:28 -0800 In-Reply-To: <20241117080931.600731-1-surenb@google.com> Mime-Version: 1.0 References: <20241117080931.600731-1-surenb@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241117080931.600731-3-surenb@google.com> Subject: [PATCH v3 2/5] mm: 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: rspam07 X-Rspamd-Queue-Id: 4368740010 X-Stat-Signature: 7tzxxcj16tbuir38smbqwthfhn46xz1z X-Rspam-User: X-HE-Tag: 1731830916-108516 X-HE-Meta: U2FsdGVkX1/ZExlz06QoJPmxxp6ATeVHmHHi9OHrYqj4J1JxUWNa7v4bI2s8+ucGrqqnqMfdPGBNR1uJzL3OQEm/w3LmKJBDziDO4GTLMAaI9tyXM1xDPa2mzfmhZp2RcNX9GhPu4CNvu8rcytWKw0QUGt3pyylbezE+N6Zn34YpoAmhcQ6NGIR6b8rAVnSRTFJ5UHdspQh0zWpDWDJ40/y4/pHAityEaX3B1t6RAjxCu/4o/7JxkjseGB7J1SI0f4F5r5THHhcRX6AKVDDzo7V+6Eb4XHEFkRzr5KyVXUypsAjPZ9bfpUA/sE3txXOTXn0SleNOR1dFV/A90UKJiEVfR3eI1sBznJaIsc6z3aJyx5Aw2eD2l7bxVv2DrX1yygkoEcAlt6zEcvwTnBUFLDDgdKShq7JS07Fi1vedw/iKTN671ViWX+UtQOoE5xJjj9rG7gaiYFWTAD/t63w/d7ODM7XQ+tG3OnZCIHR6FyUB6/buaKhly6RnB9aQS10XnmQqWco5TP6kvT0Sw1asFc7yVsfnb1sXmd/cfg1Qs7piVzcr4zbQhS+fFNRgl4l+gVS+1nZ71yCjSzlDtgtv9ZZ7XbswZu9cJc1855hSrBfqkL53Svkzw76H9tc3mpkeEMeNm1DOc6k0xSbRyh9FW/UuiRgsbmg9zPwK3jOb0FwuUvVzR6GZoCXFQmJ1RoG8KWM95NcLIdsJmwhWYzHBEaSdFnFfRLnu43aYOd+77SGiHQ522u8oySN2z/qcTnAKgxvS9VKcVQPrZb6SThBTv+HzEo56v9dKVQfaiKsfFc7km5nyPHuaNBbyerEZG7vlV3KhS+thfZbQTtp13K7rb5cDzq3cExC3LyvfX61y9GS748pbcWzzcSEouORghE3Jz2ewzAex2SKb9zL7E06H7oglDguRg+XFktSbA7yodssjoNBoS10mWtLkio5UKaRKfsxlOM14I9jn+CMzr4J nfCRI5Ez MckxYT+5EDV+j/m86qrwaeoMTfOlfkWw54lJ7iWixQkR5AKlNe/2xRL2NK7crbYdt36dewQAZbVnQK4AUSeZyKiziijGh+1wqarUsobWQ4el7JdTLGn213sJ+fAwWvn/rPeEexbYmodeOFjAScIX5BJiYND5d0ebpI35IZYBJSkAmG+Yw0mBJi68eFjLEc2PAgDSKWMQyQGRRr6IwFjHjHIzOewDdyvDymwHukCfV1ZRaQTfudFvNint8xZTSZYyVhdCqoiEkH36J31DkZ5RXdpRVWnkbpx2t/12aM1dF55T5CV0BPkiRv0CVU4Iuh35FSNHoDVaaNv3/VCsYUORlvmeWpjqUo7mAyabfMGsZgBPTkCuqAIBplOPI6t4GDeaY6tGZq9QD1yPu7TWP8Y19dYkp9zi4WWpFWWTjIZ8wc08PMvuW//XTUHt/2GcOHwJl3JyeSyLNQG8v/iKyMdIiuNq9PWNn7Je/tDMBnPvrkbY6KAYbUvfnJ1mgbivOyTfVk1ZTyWcMvLvikLaYPxhOM3aZ7W1WisqDQk0eBquAfYpiLGaS2uopHDsi+hkIBz+muj/Quz7rRL3ueV36RpVuYAJg/zWtntHFycKC/Ilz9JCGKlmMGTvZZCVo1jf5MzGLOqio 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 --- 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 1ba2e480ae63..737c003b0a1e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -684,6 +684,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 @@ -701,7 +707,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; /* @@ -716,7 +722,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; @@ -731,7 +737,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); } /* @@ -743,13 +749,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(); } @@ -778,7 +784,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(). @@ -786,7 +792,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) @@ -798,7 +804,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); } @@ -831,6 +837,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) {} @@ -865,10 +872,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)); @@ -877,6 +880,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 80fef38d9d64..5c4bfdcfac72 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -716,8 +716,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 /* @@ -770,6 +768,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 0061cf2450ef..7823797e31d2 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 @@ -3168,11 +3131,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 1d9fc97b8e80..11c2c38ca4e8 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -230,10 +230,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). * @@ -242,7 +242,7 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; - struct vma_lock *vm_lock; + struct vma_lock vm_lock; #endif /* @@ -408,17 +408,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 *); @@ -439,6 +432,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) @@ -449,10 +443,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; } @@ -465,10 +455,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; @@ -638,14 +625,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); }