public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rene Herman <rene.herman@keyaccess.nl>
To: Ingo Molnar <mingo@elte.hu>
Cc: Venki Pallipadi <venkatesh.pallipadi@intel.com>,
	Dave Airlie <airlied@gmail.com>,
	"Li, Shaohua" <shaohua.li@intel.com>,
	Yinghai Lu <yhlu.kernel@gmail.com>,
	Andreas Herrmann <andreas.herrmann3@amd.com>,
	Arjan van de Ven <arjan@infradead.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	"Siddha, Suresh B" <suresh.b.siddha@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Dave Jones <davej@codemonkey.org.uk>
Subject: [PATCH] x86: have set_memory_array_{uc,wb} coalesce memtypes.
Date: Fri, 22 Aug 2008 22:02:50 +0200	[thread overview]
Message-ID: <48AF1B6A.80408@keyaccess.nl> (raw)
In-Reply-To: <20080822041544.GF30284@elte.hu>

[-- Attachment #1: Type: text/plain, Size: 2593 bytes --]

On 22-08-08 06:15, Ingo Molnar wrote:

>> Actually, might as well simply reconstruct the memtype list at free 
>> time I guess. How is this for a coalescing version of the array 
>> functions?
> 
> impressive! Rarely do we get this much bang for such a low linecount :-)

Thanks. Stared at it a little longer now and there  was a small cut and 
paste error in the error path (s/start/tmp/) but other than that, yes, 
I'll stand by this. set_memory_array_{uc,wb}() set all pages to the same
type, so coalescing them makes sense in any usage case it seems.

The attached version fixes the out path, is otherwise identical and this 
time comes with a proper changelog and a sign-off. Given that you needed 
the changelog and the sign-off anyway, I thought there wouldn't be much 
point in doing that incrementally, but if you disagree and refactor -- a 
changelog for the out path fix would be a simple:

===
x86: fix "have set_memory_array_{uc,wb} coalesce memtypes".

Fix copy and paste error in out path

Signed-off-by: Rene Herman <rene.herman@gmail.com>
===

> I'd do this in v2.6.27 but i forced myself to be reasonable and applied 
> your patches to tip/x86/pat instead, for tentative v2.6.28 merging 
> (assuming it all passes testing, etc.):

Yes, I agree not for .27

>  # 9a79f4f: x86: {reverve,free}_memtype() take a physical address
>  # c5e147c: x86: have set_memory_array_{uc,wb} coalesce memtypes.
>  # 5f310b6: agp: enable optimized agp_alloc_pages methods
> 
> ( note that i flipped them around a bit and have put your 
>   enable-agp_alloc_pages()-widely patch last, so that we get better 
>   bisection behavior. )
> 
> The frontside cache itself is in x86/urgent:
> 
>  # 80c5e73: x86: fix Xorg startup/shutdown slowdown with PAT
> 
> ... and should at least solve the symptom that you've hit in practice 
> (the slowdown), without changing the underlying PAT machinery. (which 
> would be way too dangerous for v2.6.27)

Well, please note that that specific commit only fixes X startup -- it 
doesn't do anything for shutdown. With only that one, I'm still at 14 
seconds for X shutdown (first time after boot that is, 5 seconds 
subsequent shutdowns) versus 1 (or sub 1, feels immediate) normally.

It's also a black-screen "hang", so we'll probably be getting a lot of 
"long hang at shutdown" reports without something additionally for .27.

Venki?

> And it's all merged up in tip/master, you might want to test that too to 
> check whether all the pieces fit together nicely.

Wasn't in tip/master when I just now fetched it. It does indeed sit in 
tip/x86/pat.

Rene.

[-- Attachment #2: 0001-x86-have-set_memory_array_-uc-wb-coalesce-memtypes.patch --]
[-- Type: text/plain, Size: 2922 bytes --]

>From 1a9bfbada3769e1bd9eecddd43ade9ebc4671c3d Mon Sep 17 00:00:00 2001
From: Rene Herman <rene.herman@gmail.com>
Date: Fri, 22 Aug 2008 21:27:45 +0200
Subject: [PATCH] x86: have set_memory_array_{uc,wb} coalesce memtypes.

Have set_memory_array_{uc,wb}() coalesce memtype entries so as to
avoid having unusefully many of them.

Especially in the case of AGP with its order 0 allocations for the
AGP memory the memtype list otherwise ends up with tens of thousands
of entries, slowing processing to a crawl. With this (and the former
changes to make AGP use this interface) AGP memory will just take as
many entries as needed -- which often means just one.

Note that the error path in set_memory_array_uc() just reconstructs
the entries from start again: no need to keep an expensive list of
regions around for an error condition which isn't going to happen.

Signed-off-by: Rene Herman <rene.herman@gmail.com>
---
 arch/x86/mm/pageattr.c |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index d49e4db..c7563b6 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -942,21 +942,38 @@ EXPORT_SYMBOL(set_memory_uc);
 
 int set_memory_array_uc(unsigned long *addr, int addrinarray)
 {
+	unsigned long start;
+	unsigned long end;
 	int i;
 	/*
 	 * for now UC MINUS. see comments in ioremap_nocache()
 	 */
 	for (i = 0; i < addrinarray; i++) {
-		if (reserve_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE,
-			    _PAGE_CACHE_UC_MINUS, NULL))
+		start = __pa(addr[i]);
+		for (end = start + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) {
+			if (end != __pa(addr[i + 1]))
+				break;
+			i++;
+		}
+		if (reserve_memtype(start, end, _PAGE_CACHE_UC_MINUS, NULL))
 			goto out;
 	}
 
 	return change_page_attr_set(addr, addrinarray,
 				    __pgprot(_PAGE_CACHE_UC_MINUS), 1);
 out:
-	while (--i >= 0)
-		free_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE);
+	for (i = 0; i < addrinarray; i++) {
+		unsigned long tmp = __pa(addr[i]);
+
+		if (tmp == start)
+			break;
+		for (end = tmp + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) {
+			if (end != __pa(addr[i + 1]))
+				break;
+			i++;
+		}
+		free_memtype(tmp, end);
+	}
 	return -EINVAL;
 }
 EXPORT_SYMBOL(set_memory_array_uc);
@@ -997,9 +1014,18 @@ EXPORT_SYMBOL(set_memory_wb);
 int set_memory_array_wb(unsigned long *addr, int addrinarray)
 {
 	int i;
-	for (i = 0; i < addrinarray; i++)
-		free_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE);
 
+	for (i = 0; i < addrinarray; i++) {
+		unsigned long start = __pa(addr[i]);
+		unsigned long end;
+
+		for (end = start + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) {
+			if (end != __pa(addr[i + 1]))
+				break;
+			i++;
+		}
+		free_memtype(start, end);
+	}
 	return change_page_attr_clear(addr, addrinarray,
 				      __pgprot(_PAGE_CACHE_MASK), 1);
 }
-- 
1.5.5


  parent reply	other threads:[~2008-08-22 20:02 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04 16:30 AGP and PAT (induced?) problem (on AMD family 6) Rene Herman
2008-08-06 13:51 ` Andreas Herrmann
2008-08-06 20:57   ` Rene Herman
2008-08-11  9:46     ` Rene Herman
2008-08-15 14:22 ` Ingo Molnar
2008-08-15 15:24   ` Rene Herman
2008-08-19 10:11     ` Rene Herman
2008-08-19 10:26       ` Ingo Molnar
2008-08-19 14:19         ` Rene Herman
2008-08-19 19:07           ` Venki Pallipadi
2008-08-19 19:22             ` Rene Herman
2008-08-19 23:28               ` Venki Pallipadi
2008-08-20 10:09                 ` Ingo Molnar
2008-08-20 10:04             ` Ingo Molnar
2008-08-20 10:50               ` Rene Herman
2008-08-20 14:27                 ` Rene Herman
2008-08-20 19:41                   ` Venki Pallipadi
2008-08-20 21:40                     ` Rene Herman
2008-08-20 21:46                       ` Dave Airlie
2008-08-20 22:16                         ` Venki Pallipadi
2008-08-21  3:42                           ` Andi Kleen
2008-08-21 21:13                             ` Suresh Siddha
2008-08-22  2:12                               ` Andi Kleen
2008-08-21 12:06                           ` Ingo Molnar
2008-08-21 17:15                             ` Rene Herman
2008-08-21 22:10                               ` [PATCH] x86: {reverve,free}_memtype() take a physical address Rene Herman
2008-08-21 22:16                                 ` Pallipadi, Venkatesh
2008-08-21 22:26                                   ` Rene Herman
2008-08-21 22:57                                     ` Pallipadi, Venkatesh
2008-08-21 23:06                                       ` Rene Herman
2008-08-21 23:02                               ` [PATCH] x86: have set_memory_array_{uc,wb} coalesce memtypes Rene Herman
2008-08-22  4:15                                 ` Ingo Molnar
2008-08-22 19:08                                   ` Venki Pallipadi
2008-08-22 20:15                                     ` Rene Herman
2008-08-23 15:33                                       ` Ingo Molnar
2008-08-22 20:02                                   ` Rene Herman [this message]
2008-09-10 19:52                                     ` AGP PAT issue Rene Herman
2008-09-11  8:17                                       ` Ingo Molnar
2008-09-11  8:30                                         ` Rene Herman
2008-09-13  0:26                                           ` Pallipadi, Venkatesh
2008-09-13  0:44                                             ` Rene Herman
2008-10-09 15:53                                               ` Thomas Hellstrom
2008-10-13 17:10                                                 ` Pallipadi, Venkatesh
2008-10-13 19:26                                                   ` Thomas Hellström
2008-08-20 21:02                 ` AGP and PAT (induced?) problem (on AMD family 6) Dave Airlie
2008-08-20 21:16                   ` Rene Herman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48AF1B6A.80408@keyaccess.nl \
    --to=rene.herman@keyaccess.nl \
    --cc=airlied@gmail.com \
    --cc=andreas.herrmann3@amd.com \
    --cc=arjan@infradead.org \
    --cc=davej@codemonkey.org.uk \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=shaohua.li@intel.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=tglx@linutronix.de \
    --cc=venkatesh.pallipadi@intel.com \
    --cc=yhlu.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox