lkml.org 
[lkml]   [2011]   [Nov]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH 2/3] pids: Split alloc_pidmap into parts
    The map's page allocation code is moved to separate function
    to make clone-with-pids patching simpler.

    Signed-off-by: Pavel Emelyanov <xemul@parallels.com>

    ---
    kernel/pid.c | 37 ++++++++++++++++++++++---------------
    1 files changed, 22 insertions(+), 15 deletions(-)

    diff --git a/kernel/pid.c b/kernel/pid.c
    index 2d9704c..700dda3 100644
    --- a/kernel/pid.c
    +++ b/kernel/pid.c
    @@ -159,6 +159,25 @@ static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
    } while ((prev != last_write) && (pid_before(base, last_write, pid)));
    }

    +static int alloc_pidmap_page(struct pidmap *map)
    +{
    + void *page = kzalloc(PAGE_SIZE, GFP_KERNEL);
    +
    + /*
    + * Free the page if someone raced with us
    + * installing it:
    + */
    + spin_lock_irq(&pidmap_lock);
    + if (!map->page) {
    + map->page = page;
    + page = NULL;
    + }
    + spin_unlock_irq(&pidmap_lock);
    + kfree(page);
    +
    + return map->page ? 0 : -1;
    +}
    +
    static int alloc_pidmap(struct pid_namespace *pid_ns)
    {
    int i, offset, max_scan, pid, last = pid_ns->last_pid;
    @@ -176,22 +195,10 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
    */
    max_scan = DIV_ROUND_UP(pid_max, BITS_PER_PAGE) - !offset;
    for (i = 0; i <= max_scan; ++i) {
    - if (unlikely(!map->page)) {
    - void *page = kzalloc(PAGE_SIZE, GFP_KERNEL);
    - /*
    - * Free the page if someone raced with us
    - * installing it:
    - */
    - spin_lock_irq(&pidmap_lock);
    - if (!map->page) {
    - map->page = page;
    - page = NULL;
    - }
    - spin_unlock_irq(&pidmap_lock);
    - kfree(page);
    - if (unlikely(!map->page))
    + if (unlikely(!map->page))
    + if (alloc_pidmap_page(map))
    break;
    - }
    +
    if (likely(atomic_read(&map->nr_free))) {
    do {
    if (!test_and_set_bit(offset, map->page)) {
    --
    1.5.5.6

    \
     
     \ /
      Last update: 2011-11-10 18:19    [W:0.062 / U:0.028 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site