2020-05-07 02:06:49

by Luis Chamberlain

[permalink] [raw]
Subject: [PATCH] mm: expland documentation over __read_mostly

__read_mostly can easily be misused by folks, its not meant for
just read-only data. There are performance reasons for using it, but
we also don't provide any guidance about its use. Provide a bit more
guidance over it use.

Acked-by: Christoph Lameter <[email protected]>
Signed-off-by: Luis Chamberlain <[email protected]>
---

I sent this 2 years ago, but it fell through the cracks. This time
I'm adding Andrew Morton now, the fix0r-of-falling-through-the-cracks.

Resending as I just saw a patch which doesn't clearly justifiy the
merits of the use of __read_mostly on it.

include/linux/cache.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/cache.h b/include/linux/cache.h
index 750621e41d1c..8106fb304fa7 100644
--- a/include/linux/cache.h
+++ b/include/linux/cache.h
@@ -15,8 +15,14 @@

/*
* __read_mostly is used to keep rarely changing variables out of frequently
- * updated cachelines. If an architecture doesn't support it, ignore the
- * hint.
+ * updated cachelines. Its use should be reserved for data that is used
+ * frequently in hot paths. Performance traces can help decide when to use
+ * this. You want __read_mostly data to be tightly packed, so that in the
+ * best case multiple frequently read variables for a hot path will be next
+ * to each other in order to reduce the number of cachelines needed to
+ * execute a critial path. We should be mindful and selective of its use.
+ * ie: if you're going to use it please supply a *good* justification in your
+ * commit log
*/
#ifndef __read_mostly
#define __read_mostly
--
2.25.1


2020-05-07 02:20:13

by Rafael Aquini

[permalink] [raw]
Subject: Re: [PATCH] mm: expland documentation over __read_mostly

On Wed, May 06, 2020 at 11:13:53PM +0000, Luis Chamberlain wrote:
> __read_mostly can easily be misused by folks, its not meant for
> just read-only data. There are performance reasons for using it, but
> we also don't provide any guidance about its use. Provide a bit more
> guidance over it use.
s/it/its

same goes for the subject, as I think there is a minor typo: s/expland/expand

>
> Acked-by: Christoph Lameter <[email protected]>
> Signed-off-by: Luis Chamberlain <[email protected]>
> ---
>
> I sent this 2 years ago, but it fell through the cracks. This time
> I'm adding Andrew Morton now, the fix0r-of-falling-through-the-cracks.
>
> Resending as I just saw a patch which doesn't clearly justifiy the
> merits of the use of __read_mostly on it.
>

That would be my fault! (sorry) given the rationale below, the patch I sent
really doesn't need the hint. Thanks for the extra bit of education here.

(not an excuse) In a glance over the source tree, though, it seems most
of the hinting cases are doing it in the misguided way.


> include/linux/cache.h | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/cache.h b/include/linux/cache.h
> index 750621e41d1c..8106fb304fa7 100644
> --- a/include/linux/cache.h
> +++ b/include/linux/cache.h
> @@ -15,8 +15,14 @@
>
> /*
> * __read_mostly is used to keep rarely changing variables out of frequently
> - * updated cachelines. If an architecture doesn't support it, ignore the
> - * hint.
> + * updated cachelines. Its use should be reserved for data that is used
> + * frequently in hot paths. Performance traces can help decide when to use
> + * this. You want __read_mostly data to be tightly packed, so that in the
> + * best case multiple frequently read variables for a hot path will be next
> + * to each other in order to reduce the number of cachelines needed to
> + * execute a critial path. We should be mindful and selective of its use.
> + * ie: if you're going to use it please supply a *good* justification in your
> + * commit log
> */
> #ifndef __read_mostly
> #define __read_mostly
> --
> 2.25.1
>

Acked-by: Rafael Aquini <[email protected]>