All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Get 7% more pages in a pagevec
@ 2017-12-06  2:25 Matthew Wilcox
  2017-12-06 12:38 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2017-12-06  2:25 UTC (permalink / raw)
  To: linux-mm


7% sounds so much more impressive than one more, right?

I just noticed that we *could* do this when I was looking at pagevec.h.
I have no idea how much this will affect performance.  Probably minimally,
but I'm hoping to see a report from 0day as a result of posting this
patch ;-)

--- 8< ---

From: Matthew Wilcox <mawilcox@microsoft.com>

We don't have to use an entire 'long' for the number of elements in the
pagevec; we know it's a number between 0 and 14 (now 15).  So we can
store it in a char, and then the bool packs next to it and we still have
two or six bytes of padding for more elements in the header.  That gives
us space to cram in an extra page.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>

diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 5fb6580f7f23..6dc456ac6136 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -9,14 +9,14 @@
 #ifndef _LINUX_PAGEVEC_H
 #define _LINUX_PAGEVEC_H
 
-/* 14 pointers + two long's align the pagevec structure to a power of two */
-#define PAGEVEC_SIZE	14
+/* 15 pointers + header align the pagevec structure to a power of two */
+#define PAGEVEC_SIZE	15
 
 struct page;
 struct address_space;
 
 struct pagevec {
-	unsigned long nr;
+	unsigned char nr;
 	bool percpu_pvec_drained;
 	struct page *pages[PAGEVEC_SIZE];
 };

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get 7% more pages in a pagevec
  2017-12-06  2:25 [PATCH] Get 7% more pages in a pagevec Matthew Wilcox
@ 2017-12-06 12:38 ` Michal Hocko
  2017-12-06 14:15   ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2017-12-06 12:38 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-mm

On Tue 05-12-17 18:25:21, Matthew Wilcox wrote:
[...]
> From: Matthew Wilcox <mawilcox@microsoft.com>
> 
> We don't have to use an entire 'long' for the number of elements in the
> pagevec; we know it's a number between 0 and 14 (now 15).  So we can
> store it in a char, and then the bool packs next to it and we still have
> two or six bytes of padding for more elements in the header.  That gives
> us space to cram in an extra page.
> 
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> 
> diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
> index 5fb6580f7f23..6dc456ac6136 100644
> --- a/include/linux/pagevec.h
> +++ b/include/linux/pagevec.h
> @@ -9,14 +9,14 @@
>  #ifndef _LINUX_PAGEVEC_H
>  #define _LINUX_PAGEVEC_H
>  
> -/* 14 pointers + two long's align the pagevec structure to a power of two */
> -#define PAGEVEC_SIZE	14
> +/* 15 pointers + header align the pagevec structure to a power of two */
> +#define PAGEVEC_SIZE	15

And now you have ruined the ultimate constant of the whole MM :p
But seriously, I have completely missed that pagevec has such a bad
layout.

>  struct page;
>  struct address_space;
>  
>  struct pagevec {
> -	unsigned long nr;
> +	unsigned char nr;
>  	bool percpu_pvec_drained;
>  	struct page *pages[PAGEVEC_SIZE];
>  };

Anyway the change looks good to me.

Acked-by: Michal Hocko <mhocko@suse.com>
-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get 7% more pages in a pagevec
  2017-12-06 12:38 ` Michal Hocko
@ 2017-12-06 14:15   ` Matthew Wilcox
  2017-12-06 14:23     ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2017-12-06 14:15 UTC (permalink / raw)
  To: Michal Hocko; +Cc: linux-mm

On Wed, Dec 06, 2017 at 01:38:42PM +0100, Michal Hocko wrote:
> On Tue 05-12-17 18:25:21, Matthew Wilcox wrote:
> > -/* 14 pointers + two long's align the pagevec structure to a power of two */
> > -#define PAGEVEC_SIZE	14
> > +/* 15 pointers + header align the pagevec structure to a power of two */
> > +#define PAGEVEC_SIZE	15
> 
> And now you have ruined the ultimate constant of the whole MM :p
> But seriously, I have completely missed that pagevec has such a bad
> layout.

It's fun to go back into the historical tree and see why.

First it was two 'int's and an array of 16 pointers.  Marcelo noticed that
was three cachelines instead of two, so he shrank it to two shorts and
an array of 15 pointers:

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/include/linux/pagevec.h?id=afead7df5a05118052a238c54285e7119da65831

But then he found out that Pentium 2 and Pentium Pro sucked at 16-bit loads,
so he changed it to two longs and an array of 14 pointers:

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/include/linux/pagevec.h?id=6140f8a54db42320b1d05ce2680b5619210b88ad

I wonder what would have happened if he had benchmarked it with 'char'
instead of 'short'.  I think I have a Pentium 2 in the basement somewhere;
perhaps I'll drag it out and fire it up.

> Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get 7% more pages in a pagevec
  2017-12-06 14:15   ` Matthew Wilcox
@ 2017-12-06 14:23     ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2017-12-06 14:23 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-mm

On Wed 06-12-17 06:15:35, Matthew Wilcox wrote:
> On Wed, Dec 06, 2017 at 01:38:42PM +0100, Michal Hocko wrote:
> > On Tue 05-12-17 18:25:21, Matthew Wilcox wrote:
> > > -/* 14 pointers + two long's align the pagevec structure to a power of two */
> > > -#define PAGEVEC_SIZE	14
> > > +/* 15 pointers + header align the pagevec structure to a power of two */
> > > +#define PAGEVEC_SIZE	15
> > 
> > And now you have ruined the ultimate constant of the whole MM :p
> > But seriously, I have completely missed that pagevec has such a bad
> > layout.
> 
> It's fun to go back into the historical tree and see why.
> 
> First it was two 'int's and an array of 16 pointers.  Marcelo noticed that
> was three cachelines instead of two, so he shrank it to two shorts and
> an array of 15 pointers:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/include/linux/pagevec.h?id=afead7df5a05118052a238c54285e7119da65831
> 
> But then he found out that Pentium 2 and Pentium Pro sucked at 16-bit loads,
> so he changed it to two longs and an array of 14 pointers:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/include/linux/pagevec.h?id=6140f8a54db42320b1d05ce2680b5619210b88ad

Yeah, i've done that exercise several times because 14 is just
_strange_. I always had that feeling that we were trying to be too
clever for minor things while larger ones just got unnotices...

> I wonder what would have happened if he had benchmarked it with 'char'
> instead of 'short'.  I think I have a Pentium 2 in the basement somewhere;
> perhaps I'll drag it out and fire it up.
> 
> > Acked-by: Michal Hocko <mhocko@suse.com>
> 
> Thanks!

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-06 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06  2:25 [PATCH] Get 7% more pages in a pagevec Matthew Wilcox
2017-12-06 12:38 ` Michal Hocko
2017-12-06 14:15   ` Matthew Wilcox
2017-12-06 14:23     ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.