2007-05-08 10:57:07

by Shani Moideen

[permalink] [raw]
Subject: [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in kernel/kexec.c

Hi,

Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in
kernel/kexec.c

Signed-off-by: Shani Moideen <[email protected]>
----

thanks.


diff --git a/kernel/kexec.c b/kernel/kexec.c
index 2a59c8a..1a1afdd 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -787,7 +787,7 @@ static int kimage_load_normal_segment(struct kimage *image,

ptr = kmap(page);
/* Start with a clear page */
- memset(ptr, 0, PAGE_SIZE);
+ clear_page(ptr);
ptr += maddr & ~PAGE_MASK;
mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
if (mchunk > mbytes)






--
Shani


2007-05-08 11:10:53

by Michael Tokarev

[permalink] [raw]
Subject: Re: [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in kernel/kexec.c

Shani Moideen wrote:
> ptr = kmap(page);
> - memset(ptr, 0, PAGE_SIZE);
> + clear_page(ptr);

I wonder if it's worth to invent kzmap() or something like that... ;)

/mjt

2007-05-08 12:21:59

by Pekka Enberg

[permalink] [raw]
Subject: Re: [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in kernel/kexec.c

Shani Moideen wrote:
> > ptr = kmap(page);
> > - memset(ptr, 0, PAGE_SIZE);
> > + clear_page(ptr);

On 5/8/07, Michael Tokarev <[email protected]> wrote:
> I wonder if it's worth to invent kzmap() or something like that... ;)

I am counting 59 kmap + memset pairs in the kernel, so perhaps it is
worth it to reduce kernel text size.

2007-05-08 17:13:57

by Satyam Sharma

[permalink] [raw]
Subject: Re: [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in kernel/kexec.c

On 5/8/07, Pekka Enberg <[email protected]> wrote:
> Shani Moideen wrote:
> > > ptr = kmap(page);
> > > - memset(ptr, 0, PAGE_SIZE);
> > > + clear_page(ptr);
>
> On 5/8/07, Michael Tokarev <[email protected]> wrote:
> > I wonder if it's worth to invent kzmap() or something like that... ;)
>
> I am counting 59 kmap + memset pairs in the kernel, so perhaps it is
> worth it to reduce kernel text size.

Stuff of the sort already exists. Look for clear_highpage(),
clear_user_highpage() and memclear_highpage_flush (recently renamed to
zero_user_page, see -mm). But they all use kmap_atomic() -- kmap()
variants would have to be added. Also, they're all inlines, so I'm not
sure you'd be able to cut down text size, but still getting rid of
open-coding is always good.

2007-05-08 17:42:03

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in kernel/kexec.c

"Satyam Sharma" <[email protected]> writes:

> On 5/8/07, Pekka Enberg <[email protected]> wrote:
>> Shani Moideen wrote:
>> > > ptr = kmap(page);
>> > > - memset(ptr, 0, PAGE_SIZE);
>> > > + clear_page(ptr);
>>
>> On 5/8/07, Michael Tokarev <[email protected]> wrote:
>> > I wonder if it's worth to invent kzmap() or something like that... ;)
>>
>> I am counting 59 kmap + memset pairs in the kernel, so perhaps it is
>> worth it to reduce kernel text size.
>
> Stuff of the sort already exists. Look for clear_highpage(),
> clear_user_highpage() and memclear_highpage_flush (recently renamed to
> zero_user_page, see -mm). But they all use kmap_atomic() -- kmap()
> variants would have to be added. Also, they're all inlines, so I'm not
> sure you'd be able to cut down text size, but still getting rid of
> open-coding is always good.

In this instance a clear_page variant should be ok. The combined
variants are likely not because I use the mapping after it is cleared.

Eric