Skip to contentSkip to conversation

vmalloc: remove #ifdef in function body

PATCH In review Minchan Kim 4 participants 13 messages Dec 21, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmalloc: remove #ifdef in function body

We don't like function body which include #ifdef. If we can, define null function to go out compile time. It's trivial, no functional change.

---
 mm/vmalloc.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
mm/vmalloc.c +7 -2
index 0aca3ce..e1fa5a6 100644
@@ -505,6 +505,7 @@ static void unmap_vmap_area(struct vmap_area *va)
 	vunmap_page_range(va->va_start, va->va_end);
 }
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
 static void vmap_debug_free_range(unsigned long start, unsigned long end)
 {
 	/*
@@ -520,11 +521,15 @@ static void vmap_debug_free_range(unsigned long start, unsigned long end)
 	 * debugging doesn't do a broadcast TLB flush so it is a lot
 	 * faster).
 	 */
-#ifdef CONFIG_DEBUG_PAGEALLOC
 	vunmap_page_range(start, end);
 	flush_tlb_kernel_range(start, end);
-#endif
 }
+#else
+static inline void vmap_debug_free_range(unsigned long start,
+					unsigned long end)
+{
+}
+#endif
 
 /*
  * lazy_max_pages is the maximum amount of virtual address space we gather up
Signature · 8 lines
1.7.6.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 1 line · Minchan Kim

We don't like function body which include #ifdef.

[]

mm/vmalloc.c

Quoted 1 line
mm/vmalloc.c +0 -0

[]

Quoted 13 lines
mm/vmalloc.c +1 -1
@@ -505,6 +505,7 @@ static void unmap_vmap_area(struct vmap_area *va)
 	vunmap_page_range(va->va_start, va->va_end);
 }
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
 static void vmap_debug_free_range(unsigned long start, unsigned long end)
 {
 	/*
@@ -520,11 +521,15 @@ static void vmap_debug_free_range(unsigned long start, unsigned long end)
 	 * debugging doesn't do a broadcast TLB flush so it is a lot
 	 * faster).
 	 */
-#ifdef CONFIG_DEBUG_PAGEALLOC

mm/vmalloc.c static void vmap_debug_free_range(unsigned long start, unsigned long end) · line 532

Quoted 10 lines
mm/vmalloc.c +6 -1
 	vunmap_page_range(start, end);
 	flush_tlb_kernel_range(start, end);
-#endif
 }
+#else
+static inline void vmap_debug_free_range(unsigned long start,
+					unsigned long end)
+{
+}
+#endif

I don't like this change.
I think it's perfectly good style to use:

1 void foo(args...)
2 {
3 #ifdef CONFIG_FOO
4 ...
5 #endif
6 }

instead of

1 #ifdef CONFIG_FOO
2 void foo(args...)
3 {
4 ...
5 }
6 #else
7 void foo(args...)
8 {
9 }
10 #endif

The first version is shorter and gcc optimizes
away the void func just fine. It also means
that 2 function prototypes don't need to be
kept in agreement when someone changes one
without testing CONFIG_FOO=y and CONFIG_FOO=n.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 23 lines · Joe Perches
Quoted 1 line · Minchan Kim

We don't like function body which include #ifdef.

[]

mm/vmalloc.c

Quoted 1 line
mm/vmalloc.c +0 -0

[]

Quoted 18 lines
mm/vmalloc.c +2 -2
@@ -505,6 +505,7 @@ static void unmap_vmap_area(struct vmap_area *va)
 	vunmap_page_range(va->va_start, va->va_end);
 }
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
 static void vmap_debug_free_range(unsigned long start, unsigned long end)
 {
 	/*
@@ -520,11 +521,15 @@ static void vmap_debug_free_range(unsigned long start, unsigned long end)
 	 * debugging doesn't do a broadcast TLB flush so it is a lot
 	 * faster).
 	 */
-#ifdef CONFIG_DEBUG_PAGEALLOC
 	vunmap_page_range(start, end);
 	flush_tlb_kernel_range(start, end);
-#endif
 }
+#else
Quoted 8 lines

mm/vmalloc.c static void vmap_debug_free_range(unsigned long start, unsigned long end) · line 532

Quoted 5 lines
mm/vmalloc.c +5 -0
+static inline void vmap_debug_free_range(unsigned long start,
+					unsigned long end)
+{
+}
+#endif

I don't like this change.
I think it's perfectly good style to use:

I feel it's no problem as it is because it's very short function now but it's not style we prefer.

Quoted 21 lines

1 void foo(args...)
2 {
3 #ifdef CONFIG_FOO
4 ...
5 #endif
6 }

instead of

1 #ifdef CONFIG_FOO
2 void foo(args...)
3 {
4 ...
5 }
6 #else
7 void foo(args...)
8 {
9 }
10 #endif

Quoted 2 lines

The first version is shorter and gcc optimizes away the void func just fine. It also means

Agree but if function would be long(but I convice
it's not long in future :)), it would be messy.

Quoted 3 lines

that 2 function prototypes don't need to be kept in agreement when someone changes one without testing CONFIG_FOO=y and CONFIG_FOO=n.

The goal is not for making test easily.
Patch author should keep it consistent.

This patch is just trivial so I don't mind if who have against this patch strongly. What I want to say is it's not style we prefer.

Quoted 2 lines
Signature · 9 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 3 lines · Minchan Kim
Quoted 2 lines · Joe Perches
Quoted 1 line · Minchan Kim

We don't like function body which include #ifdef.

[]

Quoted 4 lines
Quoted 2 lines

I don't like this change.
I think it's perfectly good style to use:

I feel it's no problem as it is because it's very short function now but it's not style we prefer.

Who is this "we" you refer to?

There's nothing suggesting your patch as a preferred style in Documentation/CodingStyle.

cheers, Joe

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 7 lines · Joe Perches
Quoted 3 lines · Minchan Kim
Quoted 2 lines · Joe Perches
Quoted 1 line · Minchan Kim

We don't like function body which include #ifdef.

[]

Quoted 2 lines
Quoted 2 lines

I don't like this change.
I think it's perfectly good style to use:

Quoted 7 lines
Quoted 2 lines

I feel it's no problem as it is because it's very short function now but it's not style we prefer.

Who is this "we" you refer to?

There's nothing suggesting your patch as a preferred style in Documentation/CodingStyle.

Yes. It doesn't have.
But I have thought we have done until now.
I think we can see them easily.

#> grep -nRH 'static inline void' ./ | grep {} | wc -l 936

If we consider line which don't include brace in one line, it would be many.

Quoted 3 lines

cheers, Joe

Signature · 9 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw
In reply to Minchan Kim
Quoted 3 lines · Minchan Kim

We don't like function body which include #ifdef. If we can, define null function to go out compile time. It's trivial, no functional change.

It actually adds “flush_tlb_kenel_range()” call to the function so there is functional change.

Quoted 33 lines
---
 mm/vmalloc.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
mm/vmalloc.c +7 -2
index 0aca3ce..e1fa5a6 100644
@@ -505,6 +505,7 @@ static void unmap_vmap_area(struct vmap_area *va)
 	vunmap_page_range(va->va_start, va->va_end);
 }
+#ifdef CONFIG_DEBUG_PAGEALLOC
 static void vmap_debug_free_range(unsigned long start, unsigned long end)
 {
 	/*
@@ -520,11 +521,15 @@ static void vmap_debug_free_range(unsigned long start, unsigned long end)
 	 * debugging doesn't do a broadcast TLB flush so it is a lot
 	 * faster).
 	 */
-#ifdef CONFIG_DEBUG_PAGEALLOC
 	vunmap_page_range(start, end);
 	flush_tlb_kernel_range(start, end);
-#endif
 }
+#else
+static inline void vmap_debug_free_range(unsigned long start,
+					unsigned long end)
+{
+}
+#endif
 /*
  * lazy_max_pages is the maximum amount of virtual address space we gather up
Signature · 11 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to Joe Perches
Quoted 8 lines · Joe Perches
Quoted 2 lines · Minchan Kim

I feel it's no problem as it is because it's very short function now but it's not style we prefer.

Who is this "we" you refer to?

There's nothing suggesting your patch as a preferred style in Documentation/CodingStyle.

There is plenty that is not documented, ;) yet it seems the community prefers having ifdefs outside of the function.

Signature · 11 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw
In reply to Michal Nazarewicz
Quoted 7 lines · Michal Nazarewicz
Quoted 3 lines · Minchan Kim

We don't like function body which include #ifdef. If we can, define null function to go out compile time. It's trivial, no functional change.

It actually adds a??flush_tlb_kenel_range()a?? call to the function so there is functional change.

Sorry. I can't understand your point.
Why does it add flush_tlb_kernel_range in case of !CONFIG_DEBUG_PAGEALLOC?

Quoted 40 lines
Quoted 34 lines

---
mm/vmalloc.c | 9 +++++++--

1 files changed, 7 insertions(+), 2 deletions(-)
mm/vmalloc.c +7 -2
index 0aca3ce..e1fa5a6 100644
@@ -505,6 +505,7 @@ static void unmap_vmap_area(struct vmap_area *va)
 	vunmap_page_range(va->va_start, va->va_end);
 }
+#ifdef CONFIG_DEBUG_PAGEALLOC
 static void vmap_debug_free_range(unsigned long start, unsigned long end)
 {
 	/*
@@ -520,11 +521,15 @@ static void vmap_debug_free_range(unsigned long start, unsigned long end)
 	 * debugging doesn't do a broadcast TLB flush so it is a lot
 	 * faster).
 	 */
-#ifdef CONFIG_DEBUG_PAGEALLOC
 	vunmap_page_range(start, end);
 	flush_tlb_kernel_range(start, end);
-#endif
 }
+#else
+static inline void vmap_debug_free_range(unsigned long start,
+					unsigned long end)
+{
+}
+#endif
 /*
 * lazy_max_pages is the maximum amount of virtual address space we gather up
Signature · 4 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  MichaA? a??mina86a?? Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
Signature · 9 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw
Quoted 11 lines · Minchan Kim
Quoted 7 lines · Michal Nazarewicz
Quoted 3 lines · Minchan Kim

We don't like function body which include #ifdef. If we can, define null function to go out compile time. It's trivial, no functional change.

It actually adds “flush_tlb_kenel_range()” call to the function so there is functional change.

Sorry. I can't understand your point.
Why does it add flush_tlb_kernel_range in case of !CONFIG_DEBUG_PAGEALLOC?

Uh, sorry, I've totally misread the function. Never mind my comment.

Signature · 11 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
In reply to Minchan Kim
Quoted 8 lines · Minchan Kim
Quoted 7 lines · Joe Perches
Quoted 3 lines · Minchan Kim
Quoted 2 lines · Joe Perches
Quoted 1 line · Minchan Kim

We don't like function body which include #ifdef.

[]

Quoted 2 lines
Quoted 2 lines

I don't like this change.
I think it's perfectly good style to use:

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I feel it's no problem as it is because it's very short function now but it's not style we prefer.

Who is this "we" you refer to?
There's nothing suggesting your patch as a preferred style in Documentation/CodingStyle.

Yes. It doesn't have.
But I have thought we have done until now.

But whoever this "we" you're referring to hasn't
actually done so.

Quoted 6 lines

I think we can see them easily.

#> grep -nRH 'static inline void' ./ | grep {} | wc -l 936

If we consider line which don't include brace in one line, it would be many.

Try:

$ grep -rP --include=*.[ch] \
  '^(static|)\s*(inline|)\s*void\b[^\n;]+\n(?:{\s*|)\#\s*if' * | \
  wc -l
3603

A rough approximation would be to divide by 3. So there's maybe a 1000 or so of the other style too.

cheers, Joe

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
In reply to Michal Nazarewicz
Quoted 2 lines · Michal Nazarewicz

it seems the community prefers
having ifdefs outside of the function.

Some do, some don't.

http://comments.gmane.org/gmane.linux.network/214543

If it's not in coding style, I suggest
it should be changed if it doesn't
add some other useful value.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 7 lines · Joe Perches
Quoted 2 lines · Michal Nazarewicz

it seems the community prefers
having ifdefs outside of the function.

Some do, some don't.

http://comments.gmane.org/gmane.linux.network/214543

This patch that you pointed to is against “#ifdefs are ugly” style described in Documentation/SubmittingPatches.

Quoted 3 lines

If it's not in coding style, I suggest
it should be changed if it doesn't
add some other useful value.

That my be true. I guess no one took time to adding it to the document.

Signature · 11 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 8 lines · Michal Nazarewicz

This patch that you pointed to is against a??#ifdefs are uglya?? style described in Documentation/SubmittingPatches.

Quoted 3 lines

If it's not in coding style, I suggest
it should be changed if it doesn't
add some other useful value.

That my be true. I guess no one took time to adding it to the document.

Like all things, judgement is required. Some of the greatest artists know when it's OK (and in fact, a good thing) to break the rules. Beethoven, for example, broke the rules when he added a chorus of singers to his 9th Symphony. Take a look at Bach's chorales, universally acknowledged to be works of genius. Yet there Bach has occasionally double thirds, crossed voices, and engaged in parallel fifths --- and big no-no's which go against the textbook rules of chorale writing.

In this case, if you have an #ifdef surrounding an entire function body, I think common sense says that the it's fine. There's also the rule which is says that all other things being equal, it's better not to waste vertical space and useless boiler plate.

Worst of all is patches to change perfectly existing code because someone is trying to be a stickler for rules, since it can break other people's patches. If you are need to make a change, it's best that it be checkpatch clean. But sending random cleanups just because someone is trying to get their patch count in the kernel higher is Just Stupid, and should be strongly discouraged.

(And that last, too, is a rule that has exceptions...)

- Ted

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>