diff mbox series

[v7,21/21] mm/vma.h: Optimise vma_munmap_struct

Message ID 20240822192543.3359552-22-Liam.Howlett@oracle.com (mailing list archive)
State New
Headers show
Series Avoid MAP_FIXED gap exposure | expand

Commit Message

Liam R. Howlett Aug. 22, 2024, 7:25 p.m. UTC
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

The vma_munmap_struct has a hole of 4 bytes and pushes the struct to
three cachelines.  Relocating the three booleans upwards allows for the
struct to only use two cachelines (as reported by pahole on amd64).

Before:
struct vma_munmap_struct {
        struct vma_iterator *      vmi;                  /*     0     8 */
        struct vm_area_struct *    vma;                  /*     8     8 */
        struct vm_area_struct *    prev;                 /*    16     8 */
        struct vm_area_struct *    next;                 /*    24     8 */
        struct list_head *         uf;                   /*    32     8 */
        long unsigned int          start;                /*    40     8 */
        long unsigned int          end;                  /*    48     8 */
        long unsigned int          unmap_start;          /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        long unsigned int          unmap_end;            /*    64     8 */
        int                        vma_count;            /*    72     4 */

        /* XXX 4 bytes hole, try to pack */

        long unsigned int          nr_pages;             /*    80     8 */
        long unsigned int          locked_vm;            /*    88     8 */
        long unsigned int          nr_accounted;         /*    96     8 */
        long unsigned int          exec_vm;              /*   104     8 */
        long unsigned int          stack_vm;             /*   112     8 */
        long unsigned int          data_vm;              /*   120     8 */
        /* --- cacheline 2 boundary (128 bytes) --- */
        bool                       unlock;               /*   128     1 */
        bool                       clear_ptes;           /*   129     1 */
        bool                       closed_vm_ops;        /*   130     1 */

        /* size: 136, cachelines: 3, members: 19 */
        /* sum members: 127, holes: 1, sum holes: 4 */
        /* padding: 5 */
        /* last cacheline: 8 bytes */
};

After:
struct vma_munmap_struct {
        struct vma_iterator *      vmi;                  /*     0     8 */
        struct vm_area_struct *    vma;                  /*     8     8 */
        struct vm_area_struct *    prev;                 /*    16     8 */
        struct vm_area_struct *    next;                 /*    24     8 */
        struct list_head *         uf;                   /*    32     8 */
        long unsigned int          start;                /*    40     8 */
        long unsigned int          end;                  /*    48     8 */
        long unsigned int          unmap_start;          /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        long unsigned int          unmap_end;            /*    64     8 */
        int                        vma_count;            /*    72     4 */
        bool                       unlock;               /*    76     1 */
        bool                       clear_ptes;           /*    77     1 */
        bool                       closed_vm_ops;        /*    78     1 */

        /* XXX 1 byte hole, try to pack */

        long unsigned int          nr_pages;             /*    80     8 */
        long unsigned int          locked_vm;            /*    88     8 */
        long unsigned int          nr_accounted;         /*    96     8 */
        long unsigned int          exec_vm;              /*   104     8 */
        long unsigned int          stack_vm;             /*   112     8 */
        long unsigned int          data_vm;              /*   120     8 */

        /* size: 128, cachelines: 2, members: 19 */
        /* sum members: 127, holes: 1, sum holes: 1 */
};

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 mm/vma.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Lorenzo Stoakes Aug. 22, 2024, 7:41 p.m. UTC | #1
On Thu, Aug 22, 2024 at 03:25:43PM GMT, Liam R. Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> The vma_munmap_struct has a hole of 4 bytes and pushes the struct to
> three cachelines.  Relocating the three booleans upwards allows for the
> struct to only use two cachelines (as reported by pahole on amd64).
>
> Before:
> struct vma_munmap_struct {
>         struct vma_iterator *      vmi;                  /*     0     8 */
>         struct vm_area_struct *    vma;                  /*     8     8 */
>         struct vm_area_struct *    prev;                 /*    16     8 */
>         struct vm_area_struct *    next;                 /*    24     8 */
>         struct list_head *         uf;                   /*    32     8 */
>         long unsigned int          start;                /*    40     8 */
>         long unsigned int          end;                  /*    48     8 */
>         long unsigned int          unmap_start;          /*    56     8 */
>         /* --- cacheline 1 boundary (64 bytes) --- */
>         long unsigned int          unmap_end;            /*    64     8 */
>         int                        vma_count;            /*    72     4 */
>
>         /* XXX 4 bytes hole, try to pack */
>
>         long unsigned int          nr_pages;             /*    80     8 */
>         long unsigned int          locked_vm;            /*    88     8 */
>         long unsigned int          nr_accounted;         /*    96     8 */
>         long unsigned int          exec_vm;              /*   104     8 */
>         long unsigned int          stack_vm;             /*   112     8 */
>         long unsigned int          data_vm;              /*   120     8 */
>         /* --- cacheline 2 boundary (128 bytes) --- */
>         bool                       unlock;               /*   128     1 */
>         bool                       clear_ptes;           /*   129     1 */
>         bool                       closed_vm_ops;        /*   130     1 */
>
>         /* size: 136, cachelines: 3, members: 19 */
>         /* sum members: 127, holes: 1, sum holes: 4 */
>         /* padding: 5 */
>         /* last cacheline: 8 bytes */
> };
>
> After:
> struct vma_munmap_struct {
>         struct vma_iterator *      vmi;                  /*     0     8 */
>         struct vm_area_struct *    vma;                  /*     8     8 */
>         struct vm_area_struct *    prev;                 /*    16     8 */
>         struct vm_area_struct *    next;                 /*    24     8 */
>         struct list_head *         uf;                   /*    32     8 */
>         long unsigned int          start;                /*    40     8 */
>         long unsigned int          end;                  /*    48     8 */
>         long unsigned int          unmap_start;          /*    56     8 */
>         /* --- cacheline 1 boundary (64 bytes) --- */
>         long unsigned int          unmap_end;            /*    64     8 */
>         int                        vma_count;            /*    72     4 */
>         bool                       unlock;               /*    76     1 */
>         bool                       clear_ptes;           /*    77     1 */
>         bool                       closed_vm_ops;        /*    78     1 */
>
>         /* XXX 1 byte hole, try to pack */
>
>         long unsigned int          nr_pages;             /*    80     8 */
>         long unsigned int          locked_vm;            /*    88     8 */
>         long unsigned int          nr_accounted;         /*    96     8 */
>         long unsigned int          exec_vm;              /*   104     8 */
>         long unsigned int          stack_vm;             /*   112     8 */
>         long unsigned int          data_vm;              /*   120     8 */
>
>         /* size: 128, cachelines: 2, members: 19 */
>         /* sum members: 127, holes: 1, sum holes: 1 */
> };
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  mm/vma.h | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/mm/vma.h b/mm/vma.h
> index 7047fedce459..c774642697a0 100644
> --- a/mm/vma.h
> +++ b/mm/vma.h
> @@ -40,15 +40,16 @@ struct vma_munmap_struct {
>  	unsigned long unmap_start;      /* Unmap PTE start */
>  	unsigned long unmap_end;        /* Unmap PTE end */
>  	int vma_count;                  /* Number of vmas that will be removed */
> +	bool unlock;                    /* Unlock after the munmap */
> +	bool clear_ptes;                /* If there are outstanding PTE to be cleared */
> +	bool closed_vm_ops;		/* call_mmap() was encountered, so vmas may be closed */
> +	/* 1 byte hole */
>  	unsigned long nr_pages;         /* Number of pages being removed */
>  	unsigned long locked_vm;        /* Number of locked pages */
>  	unsigned long nr_accounted;     /* Number of VM_ACCOUNT pages */
>  	unsigned long exec_vm;
>  	unsigned long stack_vm;
>  	unsigned long data_vm;
> -	bool unlock;                    /* Unlock after the munmap */
> -	bool clear_ptes;                /* If there are outstanding PTE to be cleared */
> -	bool closed_vm_ops;		/* call_mmap() was encountered, so vmas may be closed */
>  };
>
>  #ifdef CONFIG_DEBUG_VM_MAPLE_TREE
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/mm/vma.h b/mm/vma.h
index 7047fedce459..c774642697a0 100644
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -40,15 +40,16 @@  struct vma_munmap_struct {
 	unsigned long unmap_start;      /* Unmap PTE start */
 	unsigned long unmap_end;        /* Unmap PTE end */
 	int vma_count;                  /* Number of vmas that will be removed */
+	bool unlock;                    /* Unlock after the munmap */
+	bool clear_ptes;                /* If there are outstanding PTE to be cleared */
+	bool closed_vm_ops;		/* call_mmap() was encountered, so vmas may be closed */
+	/* 1 byte hole */
 	unsigned long nr_pages;         /* Number of pages being removed */
 	unsigned long locked_vm;        /* Number of locked pages */
 	unsigned long nr_accounted;     /* Number of VM_ACCOUNT pages */
 	unsigned long exec_vm;
 	unsigned long stack_vm;
 	unsigned long data_vm;
-	bool unlock;                    /* Unlock after the munmap */
-	bool clear_ptes;                /* If there are outstanding PTE to be cleared */
-	bool closed_vm_ops;		/* call_mmap() was encountered, so vmas may be closed */
 };
 
 #ifdef CONFIG_DEBUG_VM_MAPLE_TREE