From patchwork Mon Dec 16 19:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13910236 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 A6924E7717F for ; Mon, 16 Dec 2024 19:24:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AC636B00AB; Mon, 16 Dec 2024 14:24:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 35C916B00AD; Mon, 16 Dec 2024 14:24:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 224616B00AF; Mon, 16 Dec 2024 14:24:31 -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 00E886B00AB for ; Mon, 16 Dec 2024 14:24:30 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 92C5B12098D for ; Mon, 16 Dec 2024 19:24:30 +0000 (UTC) X-FDA: 82901797776.30.7F00D60 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 26BFB80014 for ; Mon, 16 Dec 2024 19:23:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=A3ZgUdSR; spf=pass (imf02.hostedemail.com: domain of 3a35gZwYKCCwacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3a35gZwYKCCwacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734377041; a=rsa-sha256; cv=none; b=mqUjLRu6E9U1DK9LrCEjap59jQGt3kh/Y6Kxc4CWSlqPgg4AmeihpCafVDPwmyDMRWIMWu HWRr/PQvwJem3ajbhwDmX8epBAHRsH1sHPAvFHlcaXS3/V9nAPlqER1xVpzqhMpwp9lil8 6AZaVzEKtV+wACNQP3RESGvkl41MYKA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=A3ZgUdSR; spf=pass (imf02.hostedemail.com: domain of 3a35gZwYKCCwacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3a35gZwYKCCwacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@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=1734377041; 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=igJVFGm55VljdfCWWP1FWPjwRGLgL1kTgn08p8BmWdc=; b=hzwC+Hos7pcMN7X/tQC7YaVTI2JIy6/EaZLMOx4BqZ4/EPJGG3Q75YXOk96JWCVfl2YU6O gTF79jq5NIP4vkAHuODV/B2IwaZIM+C+AEq5AqDVgALljdqnd1AQu+00VaMw2j0ugUjka+ 0KxNzXG3DNjd1PvIY5GM3QZV2btigCc= Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-728e4e30163so3251238b3a.1 for ; Mon, 16 Dec 2024 11:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734377067; x=1734981867; 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=igJVFGm55VljdfCWWP1FWPjwRGLgL1kTgn08p8BmWdc=; b=A3ZgUdSR4vn5hIGa85sFpGFq3zBPRyCmf2eFKdj7jDgN0JgOyazfWcCQkmGFopl2PF cDzykDLF+yqkPE7IMXW5TSO9bhsJejD7nYTO1vCZqZAzi2bp8VDFe2APAFvVN7W2DEkm Gq/jjnMahLC9un6YYoaq7EobHHP84eAoekLLWDJtqZhuCIKEHbNg1tkWD555E3+6zDZ3 7ccl1usv/tPO9qZmsGtZ+CN01C3JuvyflGnxkhJLJt0jc3p2U0Gl+803jvEQZNoNSIBs VPYHFkJhgWjSioi9Wr1rNYZpbF1IPSqnZK7speqI8Zsfn94cpm2VQ8zfk8Rm5nlECm0V OeKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734377067; x=1734981867; 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=igJVFGm55VljdfCWWP1FWPjwRGLgL1kTgn08p8BmWdc=; b=dWKl118Inyu750yz4XaqpC783pyHdRV8+hwysuWhFGGMG/aFllxAUd32JGi5NvuEc6 ikV+Idn3fDBIJGI4BwLNRXw6rc5mh1Tv2QNyuizfE+IrDqpagOFXUlCpBE53E2e97snD ZdjK4i2P57SsnvSB7CVhQhhNI7/wuGvryWeHvqh2K2FLXXXDTsIc4cCxa5MMcRx01tXl /scp4yTpScgkmOa5VwRgT/lfglMpuKzHDyVozJc0+qDGoBEMWe2e9PqDNYNKSDcnDryQ QPCztsWpbxCxpFXPB31dD2NS9KHkBGk8BDCbVenp6rGFpw7Rc4p2JXGkmQpUf30qj6bk jz5g== X-Forwarded-Encrypted: i=1; AJvYcCVq7q3XVUhrQuNAZ1Ccx4RQZuGoLqfhWHkRLvuVWGLZ4xoxkhZIVLWOPB+D8RC8xfOvujrsVkf1Rw==@kvack.org X-Gm-Message-State: AOJu0YyJ2SO3wJyn+i79ssI8/bnAUh7hCOOI1GS8wzoHB2bCpZXvvFyz 8abO0N03arKLyB+zjou6kaCL6hF4Ho7gvWIXRxKW/LZQ7HG9eL5EX0f/V6CnkcfB/joRWGlz+IM 0ug== X-Google-Smtp-Source: AGHT+IH2UojHUVJ+gBvUhOeXPQ2zGfzEXizGrigN1NQ9dKN5xlrh19HGwEfI3CKJSRYp1fQb42E5oINrzxo= X-Received: from pfbbk15.prod.google.com ([2002:aa7:830f:0:b0:728:e508:8a3e]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:cd5:b0:724:f86e:e3d9 with SMTP id d2e1a72fcca58-7290c181255mr20564216b3a.14.1734377067561; Mon, 16 Dec 2024 11:24:27 -0800 (PST) Date: Mon, 16 Dec 2024 11:24:05 -0800 In-Reply-To: <20241216192419.2970941-1-surenb@google.com> Mime-Version: 1.0 References: <20241216192419.2970941-1-surenb@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241216192419.2970941-3-surenb@google.com> Subject: [PATCH v6 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, 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-Queue-Id: 26BFB80014 X-Stat-Signature: byw9rqfmwpip7qyawg1wukyrd1gnk3on X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1734377011-387777 X-HE-Meta: U2FsdGVkX1+F4aXQrvONZ367o0Sbyqm3vBTLi7vaPTjh5IUjW+zL0+R+Aqi17m1FD1O2Sb3VtWdsnvRznnXbIB26jM5DbT8W+3ERIdE2QFNJ9jGIfKGYIOX0FQCt393/BmZgZyhNvmP5d+IY7luoVMfbW+BmBIL/3G7oWEVwfco/Me6TrTz9pPZdlWgUQmW317IGxxwPI25BeqiR/6MymhCz3D+diRAOmCcD6l8XPLq2SOc5BNnTnw+iK4N4YHa8Q8M9nhYfHXXT0ZJTWIA4a77muO9HtCbyNdc2bUG0rUsI6wnJzMC5IejbDL72X4UHBocQhiMrasmXsYLpPDnATnBN/DlOaBgdpHXJPR2ORd+kXLZHB4tmIso69Uwwqm53YBDrbdthHcnPz4Yhx1uM9RH+wF+Ii8vdc70lqtSqKgE08Yb5nsWlnJv0uZrYioTlMsxy54mE714DGmNFGiLdLngbl1AQEKMaTtXwVZ3tJIWy0pWb+8SELTkPgt4oYpBs5pwoCFuZ5NLBOrFUEhWx+AItUVEtlrY3cBTsL5gzS/n0lKEWF3b8tKpB23KNp+RO8AFPs1Sc38ekhUlrGzPxAAGq4ZD7EZKrSJF3HwDj1lwY/9aRxhTDOYiC+RexxmEsCzO+GmMQ4UE7eJUoviRo/WmWvagK5or7YBYC6rLIbUQfZqaheZ6sgKADRji8/oFoPjV0v6yBpSoRqcxbdJp6aMjvV2UOQWzPu2RxqCE2bH9L5IZHkXZYySbduQg/gNBOSE3op1/IK1aeH6NJldpOV74klBnUVdsyaUlMcIowAI/zgqnWEglZ15BANKBEPtwtdM7c8h7tVWxQIvSjYO2JdUmyzM9SON+hf758QTVGndymwS+ZuxBT/e7md4OSikcZs4P0qSKGHTYN0DXdSfdLsQ/zqWFjQHslcyJW4/EiJ+Sm3XHGGoNuySmB4TB2cjyV0DaVwgnjH29rbF86Qaj 9xpAB/oF UZYwPZmbAhwajSoDtOKUzvkeAZ7RtqX18ZrQuPo4oMFhA6Nuz8Ch4KY5wrxl5QgFbB44scGNhZgpDMMn+h1wLw6BnK7DflADm8fpesmyd5gM7QO269mRUbSQHDFf4bLVKIvnHYz38gIZtAJnAAfI0KyEQADQ7Mq1XfWyCTT37vcG4K6L6tfrve22XMW/ubemxzHLq7Jlf6An5EePPu6JLVmE3ovZcaCIUn/LdRIu0TuEVBtk/BBV5zyR/DZoA9+Zq+TPxfKbzriCIGK7ZNCB9EauJxQY9bYlbWre9B4xQYaJ7Y/9KlJTmvm4X3XwCTKAL9KRp9C8BFUjl0E7tYWNXNpMDZvcJa1MUdLEwub479E0Pl80gAOvQLalX8llBtQo1JoBO/AZr31nnBkh/M7+dfKVgC+jZ3nD9W9yElkUQ7wBL1yWZifRKBov/vGTKxPEHntIw4/Cu49IC/VxGs4MKMRh7/eKmSlr5hbUbdxKP9MT3tD2i7X7r4k9N9Z2TpuBmPiKjmtIsq+s+3GCP/V+MT+No0Frs1zbpOrWLk2UelueQE8xVO9NVhqKGBPiNb/+EBkcjg5jycZ7/Fo4aA2Dvm4BPMRTel2tSbfDZnMVUF3h+6hRvYk0sb4SHqhscT68fpYuC1AeqXDlvhx100gFvrFC41tPRUdtZM7o2 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 --- 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 3815a43ba504..e1768a9395c9 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 266f53b2bb49..825f6328f9e5 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -700,8 +700,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 /* @@ -754,6 +752,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 8dc670fe90d4..eb3e35d65e95 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 @@ -3189,11 +3152,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 b973b3e41c83..568c18d24d53 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -270,10 +270,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). * @@ -282,7 +282,7 @@ struct vm_area_struct { * slowpath. */ unsigned int vm_lock_seq; - struct vma_lock *vm_lock; + struct vma_lock vm_lock; #endif /* @@ -459,17 +459,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 *); @@ -492,6 +485,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) @@ -502,10 +496,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; } @@ -518,10 +508,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; @@ -691,14 +678,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); }