From patchwork Mon Nov 11 20:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13871371 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 DC262D3ABF6 for ; Mon, 11 Nov 2024 20:55:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DFD36B00DB; Mon, 11 Nov 2024 15:55:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 465BE6B00DC; Mon, 11 Nov 2024 15:55:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B7D36B00DD; Mon, 11 Nov 2024 15:55:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0201B6B00DB for ; Mon, 11 Nov 2024 15:55:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B8E86AD7EC for ; Mon, 11 Nov 2024 20:55:21 +0000 (UTC) X-FDA: 82775019264.28.1CD0248 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 016DA1C0016 for ; Mon, 11 Nov 2024 20:54:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="Qy/SbHT6"; spf=pass (imf20.hostedemail.com: domain of 3Nm8yZwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3Nm8yZwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@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=1731358347; 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=akNUNHRHwFgLbLvzRySURA4LLcUajIyMqiu+hcl7K7Q=; b=kW4Y2omNqa3i4HxKts2QaLoxWZov03FPmC+p3zEEhBoUgelTfUF178T7C5PZkb24ASDIYg lOhONzJtyA/BEjgq4lGNi2RCwllRgR+zLvcgaFr17IEBH1cVbyQFLzMC2NgiyblVnfmkya OnOebCl6qOtsXdtVr2Cl3KwerhDc6xw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="Qy/SbHT6"; spf=pass (imf20.hostedemail.com: domain of 3Nm8yZwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3Nm8yZwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731358347; a=rsa-sha256; cv=none; b=agvx3q0nIPoLi8MlklP7C7R17fZH2yp+dNPRSJct4RDxoIwl3YIpuouytFWiSwRUVuH0g0 Xv+17NjkKkvHt6XdSx6gRompAIEeI7OK0VO7+k0rtZtXHEhc4zRD1UFN/I3PcnENX4uFmt O9MIYMDxG0rz7+4j8FQXs5ujPbPGBJc= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e33152c8225so10007123276.0 for ; Mon, 11 Nov 2024 12:55:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731358519; x=1731963319; 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=akNUNHRHwFgLbLvzRySURA4LLcUajIyMqiu+hcl7K7Q=; b=Qy/SbHT6gNhBdivtMeGCcRBMUnxvAf3sXCovvNeXkCKlKGhSsSgiHqRoVkHFOrdeEN Bz2vOoXD31eGcSrIAzQj9V5NzEHi7zRh69aIAWEqBTgCZ9bhOt6aElKv/MxI/Jg3YQrr HMoZmen01/psIiCQCPxY940mJniiauyR+gCHN2JQ+cF9PWi4pRwyWkB1Kky5hCJqHUbc 7ZJCrlE1dl3ahMGEMQFfSVeHBBrwjCkTNxyJ4gIJv1qe6vnxJEaPVgg0VnpabS9tLWmB qPOiPuu3PJB/yXalbH26AY6jIzIUAkBR9bceZSUuskZmaQqBxM6HhxLEJm138YBagtE4 Ihhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358519; x=1731963319; 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=akNUNHRHwFgLbLvzRySURA4LLcUajIyMqiu+hcl7K7Q=; b=BR47MLDx4Z+SJ3pP/1rt2kQOMAMDUBnjCOcvk2wUcV6TiL5WbwMELmHhS+yGeaE1CA xayp8/XlDDaPt0igjMxYg7TU9VlCB8ReW2Pb51EvtUt5aQH2GQdHdyEybzMGn4ca8qOy nFuW6W2gIvdfGDe4PxrqEGaQaNtP6ybdYZ7TX87hJN0PA/UJ8AYkzMu18oT/91qC8LF6 DoIoAOt1xQrCu9SbsMqKn61FR22Z92roxz1+W23mA2jhAaXFrOOBDkhesRO8giubd4pi S3kuRrkhJosrWgIcsXZ2RChmhIvilyzRmsBumqAxXnsvcajMfl3V/YMhxXJJpIHWtWm+ u1Bg== X-Forwarded-Encrypted: i=1; AJvYcCUUv3bJb+WISRpjilKXmprS9pkG+HQVn7f13lweEGgTKXsnE590HWQIG8zz8Vub/yAlbY0nvfxxRA==@kvack.org X-Gm-Message-State: AOJu0Yx+N6q8cYw0ScBtKbOzG4QUf8FosMA02+RZwATxUVUqzAvtN+w/ nWg33SgR3DxdcSWez3mF+jXWWbKoQcw2mzSCIKKDgNY0oEx5rCLS2xfJ810NuawjiAuGHVi/jon AWA== X-Google-Smtp-Source: AGHT+IHpj1lpqX7UFCEsgQvhYlvsKEu/LqdCTRcWojtEX3DucdiIWzMOj6Fj6hWiR/dHK1I4p9BRUvnrioQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:53af:d9fa:522d:99b1]) (user=surenb job=sendgmr) by 2002:a25:bcc2:0:b0:e2b:e955:d58a with SMTP id 3f1490d57ef6-e337f8fa240mr13216276.7.1731358518983; Mon, 11 Nov 2024 12:55:18 -0800 (PST) Date: Mon, 11 Nov 2024 12:55:06 -0800 In-Reply-To: <20241111205506.3404479-1-surenb@google.com> Mime-Version: 1.0 References: <20241111205506.3404479-1-surenb@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241111205506.3404479-5-surenb@google.com> Subject: [PATCH 4/4] mm: move lesser used vma_area_struct members into the last cacheline 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, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 016DA1C0016 X-Stat-Signature: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tHDFp8BaNfXWADELQnd/Rg7Zv2wHGc5tF3UURlciGFTavIOpsEzx3DqXXuiRdGKQsTAf9taSWVhhGIBtyDKwo48t5Ow5VrOfDwAAGf49chizTMj7xoGu5+ai1ceOhKKKt0RQwC209Rqnp/D39YKhdieqvcqTFsC8sOdwQvdxauuRJnpS1hIr3AOQxCW5oL1JcfgWG2XuiCHPMBbQ+G+nEH36ZNSYyQyZCSrgGUmH9Wl+CyTrZVZP9Hh4jRr7O3c6O3UimVUPwK61l4/R/Dbp4IomY9UzXR+uVv8zzkk3EM9/IOjERugOzTJKmAVAbak4bA9xMo4tH3jvAlnIl10wX2riTP+rHF+yU28R4KI1mytlh1l3TDMkAXKZSGTG05kZw2266b38FUKMgR05oHUHiwqVGPETDab3a8xDzZc3FYO3H8cbDAZEHkqAz8HiW2HTYOkUqYuykaC/wnfVxZM46Ww/3fyksDGCRpqb+94Jv8WTQFmW6EoU8iUUQvlhEepQKjzXe4ULXVayxd9U9ErCLXsyYrIA03sfc9HT+uIcmYO5hH1sWxeJHO21jLuDSkq49738Ek8p8ar9Vg== 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: Move several vma_area_struct members which are rarely or never used during page fault handling into the last cacheline to better pack vm_area_struct. As a result vm_area_struct will fit into 3 cachelines as opposed to 4 cachelines before this change. New vm_area_struct layout: struct vm_area_struct { union { struct { long unsigned int vm_start; /* 0 8 */ long unsigned int vm_end; /* 8 8 */ }; /* 0 16 */ struct callback_head vm_rcu ; /* 0 16 */ } __attribute__((__aligned__(8))); /* 0 16 */ struct mm_struct * vm_mm; /* 16 8 */ pgprot_t vm_page_prot; /* 24 8 */ union { const vm_flags_t vm_flags; /* 32 8 */ vm_flags_t __vm_flags; /* 32 8 */ }; /* 32 8 */ bool detached; /* 40 1 */ /* XXX 3 bytes hole, try to pack */ unsigned int vm_lock_seq; /* 44 4 */ struct list_head anon_vma_chain; /* 48 16 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct anon_vma * anon_vma; /* 64 8 */ const struct vm_operations_struct * vm_ops; /* 72 8 */ long unsigned int vm_pgoff; /* 80 8 */ struct file * vm_file; /* 88 8 */ void * vm_private_data; /* 96 8 */ atomic_long_t swap_readahead_info; /* 104 8 */ struct mempolicy * vm_policy; /* 112 8 */ /* XXX 8 bytes hole, try to pack */ /* --- cacheline 2 boundary (128 bytes) --- */ struct vma_lock vm_lock (__aligned__(64)); /* 128 4 */ /* XXX 4 bytes hole, try to pack */ struct { struct rb_node rb (__aligned__(8)); /* 136 24 */ long unsigned int rb_subtree_last; /* 160 8 */ } __attribute__((__aligned__(8))) shared; /* 136 32 */ struct vm_userfaultfd_ctx vm_userfaultfd_ctx; /* 168 0 */ /* size: 192, cachelines: 3, members: 17 */ /* sum members: 153, holes: 3, sum holes: 15 */ /* padding: 24 */ /* forced alignments: 3, forced holes: 2, sum forced holes: 12 */ } __attribute__((__aligned__(64))); Memory consumption per 1000 VMAs becomes 48 pages: slabinfo after vm_area_struct changes: ... : ... vm_area_struct ... 192 42 2 : ... Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 789bccc05520..c3755b680911 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -733,16 +733,6 @@ struct vm_area_struct { unsigned int vm_lock_seq; #endif - /* - * For areas with an address space and backing store, - * linkage into the address_space->i_mmap interval tree. - * - */ - struct { - struct rb_node rb; - unsigned long rb_subtree_last; - } shared; - /* * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma * list, after a COW of one of the file pages. A MAP_SHARED vma @@ -762,14 +752,6 @@ struct vm_area_struct { struct file * vm_file; /* File we map to (can be NULL). */ void * vm_private_data; /* was vm_pte (shared mem) */ -#ifdef CONFIG_ANON_VMA_NAME - /* - * For private and shared anonymous mappings, a pointer to a null - * terminated string containing the name given to the vma, or NULL if - * unnamed. Serialized by mmap_lock. Use anon_vma_name to access. - */ - struct anon_vma_name *anon_name; -#endif #ifdef CONFIG_SWAP atomic_long_t swap_readahead_info; #endif @@ -782,11 +764,28 @@ struct vm_area_struct { #ifdef CONFIG_NUMA_BALANCING 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 + /* + * For areas with an address space and backing store, + * linkage into the address_space->i_mmap interval tree. + * + */ + struct { + struct rb_node rb; + unsigned long rb_subtree_last; + } shared; +#ifdef CONFIG_ANON_VMA_NAME + /* + * For private and shared anonymous mappings, a pointer to a null + * terminated string containing the name given to the vma, or NULL if + * unnamed. Serialized by mmap_lock. Use anon_vma_name to access. + */ + struct anon_vma_name *anon_name; +#endif + struct vm_userfaultfd_ctx vm_userfaultfd_ctx; } __randomize_layout; #ifdef CONFIG_NUMA