Skip to contentSkip to conversation

make readmostly section correctly align

PATCH In review Shaohua Li 2 participants 3 messages Dec 2, 2010 Generic include/asm header files

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/3 make readmostly section correctly align

readmostly section should end at cache line aligned address, otherwise the last several data might share cachline with other data and make the readmostly data still have cache bounce.
For example, in ia64, secpath_cachep is the last readmostly data, and it shares cacheline with init_uts_ns.
a000000100e80480 d secpath_cachep
a000000100e80488 D init_uts_ns

---
 include/asm-generic/vmlinux.lds.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h +2 -1
Index: linux/include/asm-generic/vmlinux.lds.h
===================================================================
@@ -192,7 +192,8 @@
 
 #define READ_MOSTLY_DATA(align)						\
 	. = ALIGN(align);						\
-	*(.data..read_mostly)
+	*(.data..read_mostly)						\
+	. = ALIGN(align);
 
 #define CACHELINE_ALIGNED_DATA(align)					\
 	. = ALIGN(align);						\
#1 lore raw
Quoted 20 lines · On Thu, 02 Dec 2010 10:02:21 +0800 Shaohua Li <[email protected]> wrote:

readmostly section should end at cache line aligned address, otherwise the last several data might share cachline with other data and make the readmostly data still have cache bounce.
For example, in ia64, secpath_cachep is the last readmostly data, and it shares cacheline with init_uts_ns.
a000000100e80480 d secpath_cachep
a000000100e80488 D init_uts_ns

---
 include/asm-generic/vmlinux.lds.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/include/asm-generic/vmlinux.lds.h
===================================================================

include/asm-generic/vmlinux.lds.h line 199

Quoted 9 lines
include/asm-generic/vmlinux.lds.h +2 -1
@@ -192,7 +192,8 @@
 
 #define READ_MOSTLY_DATA(align)						\
 	. = ALIGN(align);						\
-	*(.data..read_mostly)
+	*(.data..read_mostly)						\
+	. = ALIGN(align);
 
 #define CACHELINE_ALIGNED_DATA(align)					\
 	. = ALIGN(align);						\

Surely the sane way to do this is to ensure that each section *starts* at an at-least-cacheline aligned address and then not worry about how the section ends. So shouldn't we be fixing DATA_DATA?

With your approach, .data may end up sharing a cacheline with some other section in some undesirable manner on a different arch.

"fixing" DATA_DATA would involve page-aligning it, which sucks a bit. Things would be better if include/asm-generic/vmlinux.lds.h had access to a globally-agreed cacheline-size, as it does the page size.

otoh, .data.read_mostly is "special", in that it wants the tail end of its last cacheline not to share with any other section. Most other sections aren't like that.

author
#2 lore raw
Quoted 28 lines · Andrew Morton
Quoted 26 lines · On Thu, 02 Dec 2010 10:02:21 +0800 Shaohua Li <[email protected]> wrote:

readmostly section should end at cache line aligned address, otherwise the last several data might share cachline with other data and make the readmostly data still have cache bounce.
For example, in ia64, secpath_cachep is the last readmostly data, and it shares cacheline with init_uts_ns.
a000000100e80480 d secpath_cachep
a000000100e80488 D init_uts_ns

---
 include/asm-generic/vmlinux.lds.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/include/asm-generic/vmlinux.lds.h
===================================================================

include/asm-generic/vmlinux.lds.h +2 -1
@@ -192,7 +192,8 @@
 
 #define READ_MOSTLY_DATA(align)						\
 	. = ALIGN(align);						\
-	*(.data..read_mostly)
+	*(.data..read_mostly)						\
+	. = ALIGN(align);
 
Quoted 7 lines

include/asm-generic/vmlinux.lds.h line 199

Quoted 3 lines
include/asm-generic/vmlinux.lds.h +0 -0
 #define CACHELINE_ALIGNED_DATA(align)					\
 	. = ALIGN(align);						\

Surely the sane way to do this is to ensure that each section *starts* at an at-least-cacheline aligned address and then not worry about how the section ends. So shouldn't we be fixing DATA_DATA?

Some archs don't use DATA_DATA but directly use READ_MOSTLY_DATA, so I change READ_MOSTLY_DATA.

Quoted 6 lines

With your approach, .data may end up sharing a cacheline with some other section in some undesirable manner on a different arch.

"fixing" DATA_DATA would involve page-aligning it, which sucks a bit. Things would be better if include/asm-generic/vmlinux.lds.h had access to a globally-agreed cacheline-size, as it does the page size.

yes, there isn't a well defined cacheline-size for vmlinux.lds.h.

Quoted 3 lines

otoh, .data.read_mostly is "special", in that it wants the tail end of its last cacheline not to share with any other section. Most other sections aren't like that.

yes, other sections don't need to be so.

Thanks,
Shaohua