函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\cgroup\cpuset.c Create Date:2022-07-27 12:19:02
首页 Copyright©Brick

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
/**
 * update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
 * @cs: the cpuset in which each task's mems_allowed mask needs to be changed
 *
 * Iterate through each task of @cs updating its mems_allowed to the
 * effective cpuset's.  As this function is called with cpuset_mutex held,
 * cpuset membership stays stable.
 */
static void update_tasks_nodemask(struct cpuset *cs)
{
    static nodemask_t newmems;  /* protected by cpuset_mutex */
    struct css_task_iter it;
    struct task_struct *task;
 
    cpuset_being_rebound = cs;      /* causes mpol_dup() rebind */
 
    guarantee_online_mems(cs, &newmems);
 
    /*
     * The mpol_rebind_mm() call takes mmap_sem, which we couldn't
     * take while holding tasklist_lock.  Forks can happen - the
     * mpol_dup() cpuset_being_rebound check will catch such forks,
     * and rebind their vma mempolicies too.  Because we still hold
     * the global cpuset_mutex, we know that no other rebind effort
     * will be contending for the global variable cpuset_being_rebound.
     * It's ok if we rebind the same mm twice; mpol_rebind_mm()
     * is idempotent.  Also migrate pages in each mm to new nodes.
     */
    css_task_iter_start(&cs->css, 0, &it);
    while ((task = css_task_iter_next(&it))) {
        struct mm_struct *mm;
        bool migrate;
 
        cpuset_change_task_nodemask(task, &newmems);
 
        mm = get_task_mm(task);
        if (!mm)
            continue;
 
        migrate = is_memory_migrate(cs);
 
        mpol_rebind_mm(mm, &cs->mems_allowed);
        if (migrate)
            cpuset_migrate_mm(mm, &cs->old_mems_allowed, &newmems);
        else
            mmput(mm);
    }
    css_task_iter_end(&it);
 
    /*
     * All the tasks' nodemasks have been updated, update
     * cs->old_mems_allowed.
     */
    cs->old_mems_allowed = newmems;
 
    /* We're done rebinding vmas to this cpuset's new mems_allowed. */
    cpuset_being_rebound = NULL;
}