From patchwork Sat Jan 11 04:25:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13935778 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 A6935E7719D for ; Sat, 11 Jan 2025 04:26:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E3AC6B00A4; Fri, 10 Jan 2025 23:26:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 391216B00A5; Fri, 10 Jan 2025 23:26:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 198226B00A6; Fri, 10 Jan 2025 23:26:37 -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 EB2E36B00A4 for ; Fri, 10 Jan 2025 23:26:36 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A6D18457AC for ; Sat, 11 Jan 2025 04:26:36 +0000 (UTC) X-FDA: 82993884792.05.B9FE129 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf06.hostedemail.com (Postfix) with ESMTP id DB88C18000A for ; Sat, 11 Jan 2025 04:26:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JGqnaHKY; spf=pass (imf06.hostedemail.com: domain of 3-fKBZwYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3-fKBZwYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736569595; a=rsa-sha256; cv=none; b=dk1Nrckt/v6AkMBs//WmNVdzOy/LNAbm9DPAiSmp6irGtuPu2gQrYH/mOaGjCq1t1AIODv BLUHcWk0rP7jpRXPyIURLQ7WMxYtqOmvjd3mR0InayattxZbGg16aZNlBiHH/nrLFGZcdT hSjrTby+wKQbC25MyPsqToSowvw7RhM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JGqnaHKY; spf=pass (imf06.hostedemail.com: domain of 3-fKBZwYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3-fKBZwYKCCoYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@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=1736569594; 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=2TrBali5XeUoD22YNdBhZEhX/KaryyxFeSYnw61ebAw=; b=Lo89TcI6VornvvHEm9wcYgb+5Pn0YpH0uj870Ul/hcOyTQ8/RtYg7el6NaZ5HlYsiTY6kf oaRg6cQhTrz7C468r5/xq2yvfqZesthD94OaLIAL8Hizp2YJst8ovAMf67eFFz/97wq9aF YyxGD5+x76En3BkXbp4g/HVDDtjp1ic= Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9e38b0cfso4790788a91.0 for ; Fri, 10 Jan 2025 20:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736569593; x=1737174393; 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=2TrBali5XeUoD22YNdBhZEhX/KaryyxFeSYnw61ebAw=; b=JGqnaHKYToRWTacU7bR5rN0FggeO+7uFRALHaNKy5UMkZV17rMHqvWLWEULsDVeRFu iXkePh9HWJlODnetlZTjP6rKycRDSsJA+uCPgrRbUYcbZEB3AHnpyr0AmL8ynGfabwKE H577L668i/j1qS/wTuEzCoYRQfgpt2uHbc/fg8GF2l2wEpRgBwSbxsEjJ+ULBKcOKsni SBJEXA3c8kJ3XRKpJCzZl6RPSHoZxJpvftZvoZyGN7bukU1O49/ubGgjBQuGf0RfaV9K KO3GPrW+O21dzlVHPhCePamsg7xDn55mFrppJBcx35FJ4D4gg9AmUGh/ABoI6nrNgpVx kHLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736569593; x=1737174393; 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=2TrBali5XeUoD22YNdBhZEhX/KaryyxFeSYnw61ebAw=; b=kPwrTtsLv9lQW/Zv8UC6oW16ZvE4iOZXuWch5Vz4DPctdpsnu8y3sTG30YfL5joL/p 2lxd5K/orSQVupxciKDffHFW8FTqiqt26a3OFeurDpvGaMNZFQ77WCH1Z2QEoH+ZtDOA klflypwbQhg59nzLOkW+Trv3GtkREE9b/sXR6Rj/8Me3720ERl+QZMqOtDKByHTe4+Ac zYS2EB8NUOm0d5Q9WE0YwqNjsnOH+S1x+kC5fIrJtJbfFlVZ5mlfs4mr+66TVArm2h/L 0GE+dtH+2tDMdotaCgZV6pcw83MlibLRvZJwixA7LQbadlBugPu1cEgWaI/WOAGCsaU2 ceGg== X-Forwarded-Encrypted: i=1; AJvYcCXsbzUqTarTB0XMiormVQ55icA1pZSCznVFCgGe2ZgzmtxNKOp6e558eJM8EqbjU7sJ+nVLJbEcYg==@kvack.org X-Gm-Message-State: AOJu0YwSN5Mha8453Lpm9TjpQl2rhElDZpMUBa5FaxWtMpVTeCbsjIx7 8sZg87OqyL4dVtJVkhwFf+BtPU5K4NSarNdKTJdH5lqe7lydS6n/29wpsMhquCbyUFMRoFjDPdG lSg== X-Google-Smtp-Source: AGHT+IGO/d7KP6nJwj/5X1Bl/23roKwNny3F3/SdCo6a/vda+g/68kT+5jbEnMfYJNiY3Hot1V2n9uarLr4= X-Received: from pjbdj16.prod.google.com ([2002:a17:90a:d2d0:b0:2ee:4826:cae3]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:518b:b0:2ee:b2fe:eeee with SMTP id 98e67ed59e1d1-2f548eba7d0mr20657931a91.15.1736569593696; Fri, 10 Jan 2025 20:26:33 -0800 (PST) Date: Fri, 10 Jan 2025 20:25:59 -0800 In-Reply-To: <20250111042604.3230628-1-surenb@google.com> Mime-Version: 1.0 References: <20250111042604.3230628-1-surenb@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250111042604.3230628-13-surenb@google.com> Subject: [PATCH v9 12/17] mm: move lesser used vma_area_struct members into the last cacheline 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 X-Rspamd-Queue-Id: DB88C18000A X-Stat-Signature: w5u1s184rfcaacs4kd9wm9hhnau3gcr4 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736569594-389909 X-HE-Meta: U2FsdGVkX1/CwKc8toSUCmeDmD4KRE8S5gH0Z4setPtK6i3fsvhEljzq+VF14mpI71H/o/32HclHqBdmLptkr/83c0xLXbJwZZpnGox1Pk3k+h91Q7tcntAfGZkrNRh/t6B5aF6nr9Gvp/r9SVT3+jFOVV5G+f0JLuvhiKevYTrI1TNYs97BgiGJ742QDtyDYo4S9Lvvpq2lh57dClMwn/y6NyNuNTrDP0iE8IU7numlTfoGR5KRUPEVghopj+yveEfrTGrUxjuqQ+9InKmuQotKTdqEspwi92DAjbG8r1pDVaYZW4hIFQDFIvPHhaEPlQF5hiwvf/2JitaUn1fETTYUSmYY4wkX3o+YBIfX+l4S+w5miE2e5mo/VEIrMA6UtegG7iD+Z0mYO5s7qNbrR230xvZrVh0mw/IAPiylHcBEvf/JTw2pqtv1LWQUOnE40ZGUKgHqj2ACQIxs2lDWXYqulJ0Cp9mKlNp5kfPYli17kqp7SbDMq+6Od3j1rh43yqZwsv3qp13VuFC1iYuW6gqmc8vmzuUlBOW5C4GelBJeysbyDl0/R3dPSfNWUQaI12Zi/ZR5ehZ6rRUFuU72n3P547hZPzCsm7S7/jVF9oddfnwe60x5CO9Ro0gilEi8fu1JB2IIztrr8ch7CC+Eu1N8lLKfNvmcc20YBh/XXuIU/8JZ/GOtdR67AeFMylOr5izzwjjqfs8zg8h6Kspw1cZ/B4cMhmJYeHTIWk5biCM3dzv+hMHoblVYC0suBYGu9nxyqOeoEpbXPpD3sJlJz4r/mpvzpfXGvQUzVvOvaMGvhPwzsRMHFwlTA2W4r0KtaAxKadGroNBc8oWTv/oSt1Jt+f7ZpPoKd6azy6AlenCDZHAxWjxHc0n+gWfMRQhBH2Aq6KyrK2dDlFJJ6zybeq2GMhhWnDB9U6Obse+KiZrznF0osGfapouNd/zgaX4d3AzyvdBJiz9WavHT3Yy c75rZMaQ ZtMkK3JR3zxgsQKPoTZVEpaCx9fRJOpCHivKxFBp4E3LU/sBQCn2D7bsb5gMsKXl/m2gNfUhpr9vAGeeE+yVyhoUifFMdg/dNoqXzfOVLRjIlV31hjaJ4EPKI9tCgHk0ITREJsDZGnNLA9iXyyEzUDK6AT8EISAFcRTD0FwhmuOVmHXJ16U7H5rwmydHiNF3dW2SQ54E+2ZbMgorH6UhffHF82GzlJG7Q/s/jDbRW7XDLVt0Jj9oIC4wwn6UEwhJWhj83J1MM2+lm9e3+Lev0aWvFMtrlnO/aiXbUFtEZgGa0KtCNzD6eHA/bEWEzkf7kOW22zwkgwyvllZgzcE6u0D2DYgFF9L/GTv0KsYpfbOsoedyEgxVNAHveIJy7eGdbaNdzvmE+qmjVnmzHsnf52iU/+9d0bVWlMd5DhQDm3wDgvlon6HVKBb2OCZ8PrpkyjRJMSiOOHJanHPU/SIQdax3o2VrU/YHlmFtiAkNHl4tA3VNBO7AxCJcdiT2t2jiq/M4Npn9NAhXSYfvfuOOhDSi5nls3M3szbhRyUUU2UNXaaTNS40E5d5zlzs8gcnLOo1KDvy6U4gW4JVQiZxrhRyAqsfz2jcuBueSJU+s5MQCb2LqKqip1W8yAWo/Q4q1UDHLQv/cZzS0feHohXCLU9FyzTgon/Oqa26rg 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 as opposed to 4 cachelines. New typical 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 */ freeptr_t vm_freeptr; /* 0 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 */ unsigned int vm_lock_seq; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ 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 */ struct vma_numab_state * numab_state; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ refcount_t vm_refcnt (__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 anon_vma_name * anon_name; /* 168 8 */ struct vm_userfaultfd_ctx vm_userfaultfd_ctx; /* 176 8 */ /* size: 192, cachelines: 3, members: 18 */ /* sum members: 176, holes: 2, sum holes: 8 */ /* padding: 8 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 4 */ } __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 | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 9228d19662c6..d902e6730654 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -725,17 +725,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 @@ -755,14 +744,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 @@ -775,7 +756,6 @@ 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. */ refcount_t vm_refcnt ____cacheline_aligned_in_smp; @@ -783,6 +763,24 @@ struct vm_area_struct { struct lockdep_map vmlock_dep_map; #endif #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