diff mbox series

[12/17] prmem: linked list: set alignment

Message ID 20181023213504.28905-13-igor.stoppa@huawei.com (mailing list archive)
State New, archived
Headers show
Series prmem: protected memory | expand

Commit Message

Igor Stoppa Oct. 23, 2018, 9:34 p.m. UTC
As preparation to using write rare on the nodes of various types of
lists, specify that the fields in the basic data structures must be
aligned to sizeof(void *)

It is meant to ensure that any static allocation will not cross a page
boundary, to allow pointers to be updated in one step.

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Masahiro Yamada <yamada.masahiro@socionext.com>
CC: Alexey Dobriyan <adobriyan@gmail.com>
CC: Pekka Enberg <penberg@kernel.org>
CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
CC: Lihao Liang <lianglihao@huawei.com>
CC: linux-kernel@vger.kernel.org
---
 include/linux/types.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

Peter Zijlstra Oct. 26, 2018, 9:31 a.m. UTC | #1
On Wed, Oct 24, 2018 at 12:34:59AM +0300, Igor Stoppa wrote:
> As preparation to using write rare on the nodes of various types of
> lists, specify that the fields in the basic data structures must be
> aligned to sizeof(void *)
> 
> It is meant to ensure that any static allocation will not cross a page
> boundary, to allow pointers to be updated in one step.
> 
> Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> CC: Andrew Morton <akpm@linux-foundation.org>
> CC: Masahiro Yamada <yamada.masahiro@socionext.com>
> CC: Alexey Dobriyan <adobriyan@gmail.com>
> CC: Pekka Enberg <penberg@kernel.org>
> CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> CC: Lihao Liang <lianglihao@huawei.com>
> CC: linux-kernel@vger.kernel.org
> ---
>  include/linux/types.h | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/types.h b/include/linux/types.h
> index 9834e90aa010..53609bbdcf0f 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -183,17 +183,29 @@ typedef struct {
>  } atomic64_t;
>  #endif
>  
> +#ifdef CONFIG_PRMEM
>  struct list_head {
> -	struct list_head *next, *prev;
> -};
> +	struct list_head *next __aligned(sizeof(void *));
> +	struct list_head *prev __aligned(sizeof(void *));
> +} __aligned(sizeof(void *));
>  
> -struct hlist_head {
> -	struct hlist_node *first;
> +struct hlist_node {
> +	struct hlist_node *next __aligned(sizeof(void *));
> +	struct hlist_node **pprev __aligned(sizeof(void *));
> +} __aligned(sizeof(void *));

Argh.. are we really supporting platforms that do not naturally align
this? If so, which and can't we fix those?

Also, if you force alignment on a member, the structure as a whole
inherits the largest member alignment.

Also, you made something that was simple an unreadable mess without
proper justification (ie. you fail to show need).
diff mbox series

Patch

diff --git a/include/linux/types.h b/include/linux/types.h
index 9834e90aa010..53609bbdcf0f 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -183,17 +183,29 @@  typedef struct {
 } atomic64_t;
 #endif
 
+#ifdef CONFIG_PRMEM
 struct list_head {
-	struct list_head *next, *prev;
-};
+	struct list_head *next __aligned(sizeof(void *));
+	struct list_head *prev __aligned(sizeof(void *));
+} __aligned(sizeof(void *));
 
-struct hlist_head {
-	struct hlist_node *first;
+struct hlist_node {
+	struct hlist_node *next __aligned(sizeof(void *));
+	struct hlist_node **pprev __aligned(sizeof(void *));
+} __aligned(sizeof(void *));
+#else
+struct list_head {
+	struct list_head *next, *prev;
 };
 
 struct hlist_node {
 	struct hlist_node *next, **pprev;
 };
+#endif
+
+struct hlist_head {
+	struct hlist_node *first;
+};
 
 struct ustat {
 	__kernel_daddr_t	f_tfree;