From patchwork Wed Mar 27 14:35:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13606744 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 96FE1C54E67 for ; Wed, 27 Mar 2024 14:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29E3F6B009B; Wed, 27 Mar 2024 10:36:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24BAC6B009C; Wed, 27 Mar 2024 10:36:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 114AF6B009D; Wed, 27 Mar 2024 10:36:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E70CD6B009B for ; Wed, 27 Mar 2024 10:36:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9ABC640EB6 for ; Wed, 27 Mar 2024 14:36:07 +0000 (UTC) X-FDA: 81943068774.23.2E2A50E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 685DA14002D for ; Wed, 27 Mar 2024 14:36:04 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PUDm825e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711550164; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=5X0RnZaVOLRhMTsaeQXkHZWLQRbPQMA3qc3xVHl4o8U=; b=HdMumJkllR/4q67ew4bmqZhF5MbHsjtq+YDkRn6SMwg/rwQLqvLCfbnumEKfoIo0MMmJr1 9fvEEO8hAD68awW/6s70TGSPwUUo139XtF+vtKTznljV2nHQ+4G3yWGHUovvQuI/A0U/Jl eF5XpGZc55XbYkCW5XlowwyUigYn9uo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PUDm825e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711550164; a=rsa-sha256; cv=none; b=K4Ii42tVhLO16CDmurCIfz9KYv2B7bXlrqpcTyyj240M5c33o1nvwoqMSf9jxZ1ep3lVJw mmAmHAc1EQyK38vqBeIJNeF6VvABTIMBMR8SCS/5OLGpXGCsbfLP8lVcg0y0CiY3Bt45Y4 Zq6Smjs+ZBlrEa8QIjDZFZq2D1fNIJ4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711550162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5X0RnZaVOLRhMTsaeQXkHZWLQRbPQMA3qc3xVHl4o8U=; b=PUDm825ejTbcnYcsf5F34e1PTb0ct957DbynHdeiXpTJ4c4XB9s3NLtnmIy0edEYYqqbXa HDp8ZysNDvH3ipr8xU2oWzuV5YopRVJij6ID+ZV+fJ5wDmI7XfG63fIOblTsoiEAkBzQ9+ x+eqb6anvKJxGPhN3Y6M2KKsnD3VtZM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-sXFsyY-OPDebimZQwGwPig-1; Wed, 27 Mar 2024 10:35:57 -0400 X-MC-Unique: sXFsyY-OPDebimZQwGwPig-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B6170101A58F; Wed, 27 Mar 2024 14:35:55 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 245851074E; Wed, 27 Mar 2024 14:35:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Suren Baghdasaryan Subject: [PATCH v1] mm: optimize CONFIG_PER_VMA_LOCK member placement in vm_area_struct Date: Wed, 27 Mar 2024 15:35:48 +0100 Message-ID: <20240327143548.744070-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 685DA14002D X-Stat-Signature: g9nobgbjbw6ej3bibzu5ykxqboewpm4n X-Rspam-User: X-HE-Tag: 1711550164-687719 X-HE-Meta: U2FsdGVkX1+VCuHQh5QezZjG2KxwWsfIpc5O1JdV9OTEghssKehc7jiZYn0kDZHVkCmU0oW8pW7DOYIEklNNDmlm6/5c1XsHciumVNjEisNyuKKS+7mqnTNqHT2tw8tOkB47qwXhvUz8EI7XFaY1Usitsh4QWnNMw2b+6ijs4QRqiUmvUYQCdEVAgMU2ac54J8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U4YLs+cWpJxhLEMEcq6SL5RgA= 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: Currently, we end up wasting some memory in each vm_area_struct. Pahole states that: [...] int vm_lock_seq; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ struct vma_lock * vm_lock; /* 48 8 */ bool detached; /* 56 1 */ /* XXX 7 bytes hole, try to pack */ [...] Let's reduce the holes and memory wastage by moving the bool: [...] bool detached; /* 40 1 */ /* XXX 3 bytes hole, try to pack */ int vm_lock_seq; /* 44 4 */ struct vma_lock * vm_lock; /* 48 8 */ [...] Effectively shrinking the vm_area_struct with CONFIG_PER_VMA_LOCK by 8 byte. Likely, we could place "detached" in the lowest bit of vm_lock, but at least on 64bit that won't really make a difference, so keep it simple. Cc: Andrew Morton Cc: Suren Baghdasaryan Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4ae4684d1add..f56739dece7a 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -671,6 +671,9 @@ struct vm_area_struct { }; #ifdef CONFIG_PER_VMA_LOCK + /* Flag to indicate areas detached from the mm->mm_mt tree */ + bool detached; + /* * Can only be written (using WRITE_ONCE()) while holding both: * - mmap_lock (in write mode) @@ -687,9 +690,6 @@ struct vm_area_struct { */ int vm_lock_seq; struct vma_lock *vm_lock; - - /* Flag to indicate areas detached from the mm->mm_mt tree */ - bool detached; #endif /*