linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm: optimize CONFIG_PER_VMA_LOCK member placement in vm_area_struct
@ 2024-03-27 14:35 David Hildenbrand
  2024-03-27 19:58 ` Suren Baghdasaryan
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand @ 2024-03-27 14:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Andrew Morton, Suren Baghdasaryan

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 <akpm@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 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
 
 	/*
-- 
2.43.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] mm: optimize CONFIG_PER_VMA_LOCK member placement in vm_area_struct
  2024-03-27 14:35 [PATCH v1] mm: optimize CONFIG_PER_VMA_LOCK member placement in vm_area_struct David Hildenbrand
@ 2024-03-27 19:58 ` Suren Baghdasaryan
  0 siblings, 0 replies; 2+ messages in thread
From: Suren Baghdasaryan @ 2024-03-27 19:58 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: linux-kernel, linux-mm, Andrew Morton

On Wed, Mar 27, 2024 at 7:36 AM David Hildenbrand <david@redhat.com> wrote:
>
> 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 <akpm@linux-foundation.org>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Looks reasonable to me. Thanks!

> ---
>  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
>
>         /*
> --
> 2.43.2
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-27 19:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 14:35 [PATCH v1] mm: optimize CONFIG_PER_VMA_LOCK member placement in vm_area_struct David Hildenbrand
2024-03-27 19:58 ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox