2003-08-05 15:46:31

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH] revert to static = {0}

Please revert to static zero initialization of a const: when thus
initialized it's linked into a readonly cacheline shared between cpus;
otherwise it's linked into bss, likely to be in a dirty cacheline
bouncing between cpus.

--- 2.6.0-test2-bk/mm/shmem.c Tue Aug 5 15:57:31 2003
+++ linux/mm/shmem.c Tue Aug 5 16:16:55 2003
@@ -296,7 +296,7 @@
struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
struct page *page = NULL;
swp_entry_t *entry;
- static const swp_entry_t unswapped;
+ static const swp_entry_t unswapped = {0};

if (sgp != SGP_WRITE &&
((loff_t) index << PAGE_CACHE_SHIFT) >= i_size_read(inode))


2003-08-05 16:07:28

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, 2003-08-05 at 17:48, Hugh Dickins wrote:
> Please revert to static zero initialization of a const: when thus
> initialized it's linked into a readonly cacheline shared between cpus;
> otherwise it's linked into bss, likely to be in a dirty cacheline
> bouncing between cpus.

how about adding a big fat comment here that says this?
Otherwise this keeps happening all the time...


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-08-05 16:14:03

by Randy.Dunlap

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, 5 Aug 2003 16:48:02 +0100 (BST) Hugh Dickins <[email protected]> wrote:

| Please revert to static zero initialization of a const: when thus
| initialized it's linked into a readonly cacheline shared between cpus;
| otherwise it's linked into bss, likely to be in a dirty cacheline
| bouncing between cpus.
|
| --- 2.6.0-test2-bk/mm/shmem.c Tue Aug 5 15:57:31 2003
| +++ linux/mm/shmem.c Tue Aug 5 16:16:55 2003
| @@ -296,7 +296,7 @@
| struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
| struct page *page = NULL;
| swp_entry_t *entry;
| - static const swp_entry_t unswapped;
| + static const swp_entry_t unswapped = {0};

In all of the "don't init statics to 0" patches, should we
check for "const" also and leave those with 0 initializers
(with explanation as Arjan requested)?

--
~Randy

2003-08-05 16:18:22

by Lou Langholtz

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

Hugh Dickins wrote:

>Please revert to static zero initialization of a const: when thus
>initialized it's linked into a readonly cacheline shared between cpus;
>otherwise it's linked into bss, likely to be in a dirty cacheline
>bouncing between cpus.
>
>--- 2.6.0-test2-bk/mm/shmem.c Tue Aug 5 15:57:31 2003
>+++ linux/mm/shmem.c Tue Aug 5 16:16:55 2003
>@@ -296,7 +296,7 @@
> struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
> struct page *page = NULL;
> swp_entry_t *entry;
>- static const swp_entry_t unswapped;
>+ static const swp_entry_t unswapped = {0};
>
> if (sgp != SGP_WRITE &&
> ((loff_t) index << PAGE_CACHE_SHIFT) >= i_size_read(inode))
>
>
If this static zero initialization makes it into the kernel distro for
the given reason, please also add a comment sharing your above mentioned
reasoning.

2003-08-05 17:44:33

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, Aug 05, 2003 at 04:48:02PM +0100, Hugh Dickins wrote:
> Please revert to static zero initialization of a const: when thus
> initialized it's linked into a readonly cacheline shared between cpus;
> otherwise it's linked into bss, likely to be in a dirty cacheline
> bouncing between cpus.
>
> --- 2.6.0-test2-bk/mm/shmem.c Tue Aug 5 15:57:31 2003
> +++ linux/mm/shmem.c Tue Aug 5 16:16:55 2003
> @@ -296,7 +296,7 @@
> struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
> struct page *page = NULL;
> swp_entry_t *entry;
> - static const swp_entry_t unswapped;
> + static const swp_entry_t unswapped = {0};
>
> if (sgp != SGP_WRITE &&
> ((loff_t) index << PAGE_CACHE_SHIFT) >= i_size_read(inode))
>

If it's const, it shouldn't be linked into anything at all... right?

Jeff



2003-08-05 18:39:45

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH] revert to static = {0} + comment

Please revert to static zero initialization of a const: when thus
initialized it's linked into a readonly cacheline shared between cpus;
otherwise it's linked into bss, likely to be in a dirty cacheline
bouncing between cpus.

On 5 Aug 2003, Arjan van de Ven wrote:
> how about adding a big fat comment here that says this?
> Otherwise this keeps happening all the time...
and others concurred.

Okay, by popular request, here it is with a small thin comment.

--- 2.6.0-test2-bk/mm/shmem.c Tue Aug 5 15:57:31 2003
+++ linux/mm/shmem.c Tue Aug 5 19:29:16 2003
@@ -296,7 +296,8 @@
struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
struct page *page = NULL;
swp_entry_t *entry;
- static const swp_entry_t unswapped;
+ static const swp_entry_t unswapped = {0};
+ /* = {0} to go in readonly data, to avoid bss cacheline bounce */

if (sgp != SGP_WRITE &&
((loff_t) index << PAGE_CACHE_SHIFT) >= i_size_read(inode))

2003-08-05 18:47:30

by Hugh Dickins

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, 5 Aug 2003, Randy.Dunlap wrote:
>
> In all of the "don't init statics to 0" patches, should we
> check for "const" also and leave those with 0 initializers
> (with explanation as Arjan requested)?

It's certainly something to consider. This was my "= {0}" so
I know the reasoning, but I've not looked at and won't speak for others.

Hugh


2003-08-05 18:50:09

by Hugh Dickins

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, 5 Aug 2003, Jeff Garzik wrote:
>
> If it's const, it shouldn't be linked into anything at all... right?

Sorry, Jeff, I don't get your point.

Hugh

2003-08-05 19:05:48

by William Lee Irwin III

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

On Tue, 5 Aug 2003, Jeff Garzik wrote:
>> If it's const, it shouldn't be linked into anything at all... right?

On Tue, Aug 05, 2003 at 07:51:41PM +0100, Hugh Dickins wrote:
> Sorry, Jeff, I don't get your point.

I suspect this assumes const values will get constant folded, which I'm
not sure is the case, though it certainly sounds legal and worthwhile
for a compiler to do when reasonable (i.e. for small structures and/or
extractions of small fields of const structures).


-- wli

2003-08-05 21:13:29

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH] revert to static = {0}

William Lee Irwin III wrote:
> On Tue, 5 Aug 2003, Jeff Garzik wrote:
>
>>>If it's const, it shouldn't be linked into anything at all... right?
>
>
> On Tue, Aug 05, 2003 at 07:51:41PM +0100, Hugh Dickins wrote:
>
>>Sorry, Jeff, I don't get your point.
>
>
> I suspect this assumes const values will get constant folded, which I'm
> not sure is the case, though it certainly sounds legal and worthwhile
> for a compiler to do when reasonable (i.e. for small structures and/or
> extractions of small fields of const structures).


Correct. In fact, some Linux kernel code _assumes_ the compiler will
fold constants...

Jeff