diff options
Diffstat (limited to 'mm/mempolicy.c')
-rw-r--r-- | mm/mempolicy.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 5bc0a96beb51..8a73708d59bb 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c | |||
@@ -1712,6 +1712,50 @@ bool init_nodemask_of_mempolicy(nodemask_t *mask) | |||
1712 | } | 1712 | } |
1713 | #endif | 1713 | #endif |
1714 | 1714 | ||
1715 | /* | ||
1716 | * mempolicy_nodemask_intersects | ||
1717 | * | ||
1718 | * If tsk's mempolicy is "default" [NULL], return 'true' to indicate default | ||
1719 | * policy. Otherwise, check for intersection between mask and the policy | ||
1720 | * nodemask for 'bind' or 'interleave' policy. For 'perferred' or 'local' | ||
1721 | * policy, always return true since it may allocate elsewhere on fallback. | ||
1722 | * | ||
1723 | * Takes task_lock(tsk) to prevent freeing of its mempolicy. | ||
1724 | */ | ||
1725 | bool mempolicy_nodemask_intersects(struct task_struct *tsk, | ||
1726 | const nodemask_t *mask) | ||
1727 | { | ||
1728 | struct mempolicy *mempolicy; | ||
1729 | bool ret = true; | ||
1730 | |||
1731 | if (!mask) | ||
1732 | return ret; | ||
1733 | task_lock(tsk); | ||
1734 | mempolicy = tsk->mempolicy; | ||
1735 | if (!mempolicy) | ||
1736 | goto out; | ||
1737 | |||
1738 | switch (mempolicy->mode) { | ||
1739 | case MPOL_PREFERRED: | ||
1740 | /* | ||
1741 | * MPOL_PREFERRED and MPOL_F_LOCAL are only preferred nodes to | ||
1742 | * allocate from, they may fallback to other nodes when oom. | ||
1743 | * Thus, it's possible for tsk to have allocated memory from | ||
1744 | * nodes in mask. | ||
1745 | */ | ||
1746 | break; | ||
1747 | case MPOL_BIND: | ||
1748 | case MPOL_INTERLEAVE: | ||
1749 | ret = nodes_intersects(mempolicy->v.nodes, *mask); | ||
1750 | break; | ||
1751 | default: | ||
1752 | BUG(); | ||
1753 | } | ||
1754 | out: | ||
1755 | task_unlock(tsk); | ||
1756 | return ret; | ||
1757 | } | ||
1758 | |||
1715 | /* Allocate a page in interleaved policy. | 1759 | /* Allocate a page in interleaved policy. |
1716 | Own path because it needs to do special accounting. */ | 1760 | Own path because it needs to do special accounting. */ |
1717 | static struct page *alloc_page_interleave(gfp_t gfp, unsigned order, | 1761 | static struct page *alloc_page_interleave(gfp_t gfp, unsigned order, |