All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap.
@ 2013-03-11 21:18 Raphael S. Carvalho
  2013-03-11 21:57 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Raphael S. Carvalho @ 2013-03-11 21:18 UTC (permalink / raw)
  To: Eric W. Biederman, Andrew Morton, Serge E. Hallyn, Serge Hallyn,
	David S. Miller
  Cc: linux-kernel, Raphael S.Carvalho

From: Raphael S.Carvalho <raphael.scarv@gmail.com>

Notes: find_next_offset searches for an available "cleaned bit"
in the respective pid bitmap (page), so returns the offset if found,
otherwise it returns a value equals to BITS_PER_PAGE.

For example, suppose find_next_offset didn't find any available
bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles).

Therefore, I found it could be better to call mk_pid after
the checking (offset < BITS_PER_PAGE) returned sucessfully!
Another point: If (offset < BITS_PER_PAGE) results in a "failure",
then mk_pid would be called again afterwards.

Signed-off-by: Raphael S. Carvalho <raphael.scarv@gmail.com>
---
 kernel/pid.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index 047dc62..7ecb09a 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
 					return pid;
 				}
 				offset = find_next_offset(map, offset);
-				pid = mk_pid(pid_ns, map, offset);
-			} while (offset < BITS_PER_PAGE && pid < pid_max);
+			} while (offset < BITS_PER_PAGE && 
+				(pid = mk_pid(pid_ns, map, offset)) < pid_max);
 		}
 		if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
 			++map;
-- 
1.7.2.5


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

* Re: [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap.
  2013-03-11 21:18 [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap Raphael S. Carvalho
@ 2013-03-11 21:57 ` Andrew Morton
  2013-03-11 22:01   ` Raphael S Carvalho
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2013-03-11 21:57 UTC (permalink / raw)
  To: Raphael S. Carvalho
  Cc: Eric W. Biederman, Serge E. Hallyn, Serge Hallyn,
	David S. Miller, linux-kernel

On Mon, 11 Mar 2013 18:18:56 -0300 "Raphael S. Carvalho" <raphael.scarv@gmail.com> wrote:

> From: Raphael S.Carvalho <raphael.scarv@gmail.com>
> 
> Notes: find_next_offset searches for an available "cleaned bit"
> in the respective pid bitmap (page), so returns the offset if found,
> otherwise it returns a value equals to BITS_PER_PAGE.
> 
> For example, suppose find_next_offset didn't find any available
> bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles).
> 
> Therefore, I found it could be better to call mk_pid after
> the checking (offset < BITS_PER_PAGE) returned sucessfully!
> Another point: If (offset < BITS_PER_PAGE) results in a "failure",
> then mk_pid would be called again afterwards.
> 
> ...
>
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
>  					return pid;
>  				}
>  				offset = find_next_offset(map, offset);
> -				pid = mk_pid(pid_ns, map, offset);
> -			} while (offset < BITS_PER_PAGE && pid < pid_max);
> +			} while (offset < BITS_PER_PAGE && 
> +				(pid = mk_pid(pid_ns, map, offset)) < pid_max);
>  		}
>  		if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
>  			++map;

Looks OK.  But I think it's simpler and more straightforward to do it
this way?

			for ( ; ; ) {
				if (!test_and_set_bit(offset, map->page)) {
					atomic_dec(&map->nr_free);
					set_last_pid(pid_ns, last, pid);
					return pid;
				}
				offset = find_next_offset(map, offset);
				if (offset >= BITS_PER_PAGE)
					break;
				pid = mk_pid(pid_ns, map, offset);
				if (pid >= pid_max)
					break;
			}


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

* Re: [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap.
  2013-03-11 21:57 ` Andrew Morton
@ 2013-03-11 22:01   ` Raphael S Carvalho
  0 siblings, 0 replies; 4+ messages in thread
From: Raphael S Carvalho @ 2013-03-11 22:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Eric W. Biederman, Serge E. Hallyn, Serge Hallyn,
	David S. Miller, linux-kernel

On Mon, Mar 11, 2013 at 6:57 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Mon, 11 Mar 2013 18:18:56 -0300 "Raphael S. Carvalho" <raphael.scarv@gmail.com> wrote:
>
>> From: Raphael S.Carvalho <raphael.scarv@gmail.com>
>>
>> Notes: find_next_offset searches for an available "cleaned bit"
>> in the respective pid bitmap (page), so returns the offset if found,
>> otherwise it returns a value equals to BITS_PER_PAGE.
>>
>> For example, suppose find_next_offset didn't find any available
>> bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles).
>>
>> Therefore, I found it could be better to call mk_pid after
>> the checking (offset < BITS_PER_PAGE) returned sucessfully!
>> Another point: If (offset < BITS_PER_PAGE) results in a "failure",
>> then mk_pid would be called again afterwards.
>>
>> ...
>>
>> --- a/kernel/pid.c
>> +++ b/kernel/pid.c
>> @@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
>>                                       return pid;
>>                               }
>>                               offset = find_next_offset(map, offset);
>> -                             pid = mk_pid(pid_ns, map, offset);
>> -                     } while (offset < BITS_PER_PAGE && pid < pid_max);
>> +                     } while (offset < BITS_PER_PAGE &&
>> +                             (pid = mk_pid(pid_ns, map, offset)) < pid_max);
>>               }
>>               if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
>>                       ++map;
>
> Looks OK.  But I think it's simpler and more straightforward to do it
> this way?

Yes, it looks much better.
>
>                         for ( ; ; ) {
>                                 if (!test_and_set_bit(offset, map->page)) {
>                                         atomic_dec(&map->nr_free);
>                                         set_last_pid(pid_ns, last, pid);
>                                         return pid;
>                                 }
>                                 offset = find_next_offset(map, offset);
>                                 if (offset >= BITS_PER_PAGE)
>                                         break;
>                                 pid = mk_pid(pid_ns, map, offset);
>                                 if (pid >= pid_max)
>                                         break;
>                         }
>

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

* [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap.
@ 2013-03-08 23:07 Raphael S.Carvalho
  0 siblings, 0 replies; 4+ messages in thread
From: Raphael S.Carvalho @ 2013-03-08 23:07 UTC (permalink / raw)
  To: David S. Miller, Serge Hallyn, Serge E. Hallyn, Andrew Morton,
	Eric W. Biederman
  Cc: linux-kernel, Raphael S.Carvalho

Notes: find_next_offset searches for an available "cleaned bit"
in the respective pid bitmap (page), so returns the offset if found,
otherwise it returns a value equals to BITS_PER_PAGE (invalid offset).

For example, suppose find_next_offset didn't find any available
bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles)
since it only computes a new PID based on a *valid* offset of 
the current map.

Therefore, I found it could be better to call mk_pid after
the checking (offset < BITS_PER_PAGE) returned sucessfully!

Signed-off-by: Raphael S.Carvalho <raphael.scarv@gmail.com>
---
 kernel/pid.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index 047dc62..7ecb09a 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
 					return pid;
 				}
 				offset = find_next_offset(map, offset);
-				pid = mk_pid(pid_ns, map, offset);
-			} while (offset < BITS_PER_PAGE && pid < pid_max);
+			} while (offset < BITS_PER_PAGE &&
+				(pid = mk_pid(pid_ns, map, offset)) < pid_max);
 		}
 		if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
 			++map;
-- 
1.7.2.5


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

end of thread, other threads:[~2013-03-11 22:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 21:18 [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap Raphael S. Carvalho
2013-03-11 21:57 ` Andrew Morton
2013-03-11 22:01   ` Raphael S Carvalho
  -- strict thread matches above, loose matches on Subject: below --
2013-03-08 23:07 Raphael S.Carvalho

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.