CINXE.COM

LKML: Paul Jackson: [PATCH 05/10] Cpuset: combine refresh_mems and update_mems

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>LKML: Paul Jackson: [PATCH 05/10] Cpuset: combine refresh_mems and update_mems</title><link href="/css/message.css" rel="stylesheet" type="text/css" /><link href="/css/wrap.css" rel="alternate stylesheet" type="text/css" title="wrap" /><link href="/css/nowrap.css" rel="stylesheet" type="text/css" title="nowrap" /><link href="/favicon.ico" rel="shortcut icon" /><script src="/js/simple-calendar.js" type="text/javascript"></script><script src="/js/styleswitcher.js" type="text/javascript"></script><link rel="alternate" type="application/rss+xml" title="lkml.org : last 100 messages" href="/rss.php" /><link rel="alternate" type="application/rss+xml" title="lkml.org : last messages by Paul Jackson" href="/groupie.php?aid=5266" /><!--Matomo--><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//m.lkml.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!--End Matomo Code--></head><body onload="es.jasper.simpleCalendar.init();" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"><table border="0" cellpadding="0" cellspacing="0"><tr><td width="180" align="center"><a href="/"><img style="border:0;width:135px;height:32px" src="/images/toprowlk.gif" alt="lkml.org" /></a></td><td width="32">聽</td><td class="nb"><div><a class="nb" href="/lkml"> [lkml]</a> 聽 <a class="nb" href="/lkml/2005"> [2005]</a> 聽 <a class="nb" href="/lkml/2005/12"> [Dec]</a> 聽 <a class="nb" href="/lkml/2005/12/10"> [10]</a> 聽 <a class="nb" href="/lkml/last100"> [last100]</a> 聽 <a href="/rss.php"><img src="/images/rss-or.gif" border="0" alt="RSS Feed" /></a></div><div>Views: <a href="#" class="nowrap" onclick="setActiveStyleSheet('wrap');return false;">[wrap]</a><a href="#" class="wrap" onclick="setActiveStyleSheet('nowrap');return false;">[no wrap]</a> 聽 <a class="nb" href="/lkml/mheaders/2005/12/10/31" onclick="this.href='/lkml/headers'+'/2005/12/10/31';">[headers]</a>聽 <a href="/lkml/bounce/2005/12/10/31">[forward]</a>聽 </div></td><td width="32">聽</td></tr><tr><td valign="top"><div class="es-jasper-simpleCalendar" baseurl="/lkml/"></div><div class="threadlist">Messages in this thread</div><ul class="threadlist"><li class="root"><a href="/lkml/2005/12/10/28">First message in thread</a></li><li><a href="/lkml/2005/12/10/28">Paul Jackson</a><ul><li><a href="/lkml/2005/12/10/29">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/30">Paul Jackson</a></li><li class="origin"><a href="">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/32">Paul Jackson</a><ul><li><a href="/lkml/2005/12/10/48">Paul Jackson</a></li></ul></li><li><a href="/lkml/2005/12/10/33">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/34">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/35">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/36">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/37">Paul Jackson</a></li><li><a href="/lkml/2005/12/10/39">Paul Jackson</a></li></ul></li></ul><div class="threadlist">Patch in this message</div><ul class="threadlist"><li><a href="/lkml/diff/2005/12/10/31/1">Get diff 1</a></li></ul></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerl.gif" width="32" height="32" alt="/" /></td><td class="c" rowspan="2" valign="top" style="padding-top: 1em"><table><tr><td><table><tr><td class="lp">Date</td><td class="rp" itemprop="datePublished">Sat, 10 Dec 2005 00:19:11 -0800 (PST)</td></tr><tr><td class="lp">From</td><td class="rp" itemprop="author">Paul Jackson &lt;&gt;</td></tr><tr><td class="lp">Subject</td><td class="rp" itemprop="name">[PATCH 05/10] Cpuset: combine refresh_mems and update_mems</td></tr></table></td><td></td></tr></table><pre itemprop="articleBody">The important code paths through alloc_pages_current()<br />and alloc_page_vma(), by which most kernel page allocations<br />go, both called cpuset_update_current_mems_allowed(),<br />which in turn called refresh_mems(). -Both- of these<br />latter two routines did a tasklock, got the tasks cpuset<br />pointer, and checked for out of date cpuset-&gt;mems_generation.<br /><br />That was a silly duplication of code and waste of CPU cycles<br />on an important code path.<br /><br />Consolidated those two routines into a single routine,<br />called cpuset_update_task_memory_state(), since it updates<br />more than just mems_allowed.<br /><br />Changed all callers of either routine to call the new<br />consolidated routine.<br /><br />Signed-off-by: Paul Jackson &lt;pj&#64;sgi.com&gt;<br /><br />---<br /><br /> include/linux/cpuset.h | 4 +-<br /> kernel/cpuset.c | 95 +++++++++++++++++++++----------------------------<br /> mm/mempolicy.c | 10 ++---<br /> 3 files changed, 48 insertions(+), 61 deletions(-)<br /><br />--- 2.6.15-rc3-mm1.orig/include/linux/cpuset.h 2005-12-07 22:00:40.525006978 -0800<br />+++ 2.6.15-rc3-mm1/include/linux/cpuset.h 2005-12-07 23:48:54.860211028 -0800<br />&#64;&#64; -20,7 +20,7 &#64;&#64; extern void cpuset_fork(struct task_stru<br /> extern void cpuset_exit(struct task_struct *p);<br /> extern cpumask_t cpuset_cpus_allowed(const struct task_struct *p);<br /> void cpuset_init_current_mems_allowed(void);<br />-void cpuset_update_current_mems_allowed(void);<br />+void cpuset_update_task_memory_state(void);<br /> #define cpuset_nodes_subset_current_mems_allowed(nodes) \<br /> nodes_subset((nodes), current-&gt;mems_allowed)<br /> int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl);<br />&#64;&#64; -51,7 +51,7 &#64;&#64; static inline cpumask_t cpuset_cpus_allo<br /> }<br /> <br /> static inline void cpuset_init_current_mems_allowed(void) {}<br />-static inline void cpuset_update_current_mems_allowed(void) {}<br />+static inline void cpuset_update_task_memory_state(void) {}<br /> #define cpuset_nodes_subset_current_mems_allowed(nodes) (1)<br /> <br /> static inline int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl)<br />--- 2.6.15-rc3-mm1.orig/kernel/cpuset.c 2005-12-07 22:12:08.509137821 -0800<br />+++ 2.6.15-rc3-mm1/kernel/cpuset.c 2005-12-07 23:52:21.746290572 -0800<br />&#64;&#64; -584,13 +584,26 &#64;&#64; static void guarantee_online_mems(const <br /> BUG_ON(!nodes_intersects(*pmask, node_online_map));<br /> }<br /> <br />-/*<br />- * Refresh current tasks mems_allowed and mems_generation from current<br />- * tasks cpuset.<br />+/**<br />+ * cpuset_update_task_memory_state - update task memory placement<br /> *<br />- * Call without callback_sem or task_lock() held. May be called with<br />- * or without manage_sem held. Will acquire task_lock() and might<br />- * acquire callback_sem during call.<br />+ * If the current tasks cpusets mems_allowed changed behind our<br />+ * backs, update current-&gt;mems_allowed, mems_generation and task NUMA<br />+ * mempolicy to the new value.<br />+ *<br />+ * Task mempolicy is updated by rebinding it relative to the<br />+ * current-&gt;cpuset if a task has its memory placement changed.<br />+ * Do not call this routine if in_interrupt().<br />+ *<br />+ * Call without callback_sem or task_lock() held. May be called<br />+ * with or without manage_sem held. Except in early boot or<br />+ * an exiting task, when tsk-&gt;cpuset is NULL, this routine will<br />+ * acquire task_lock(). We don't need to use task_lock to guard<br />+ * against another task changing a non-NULL cpuset pointer to NULL,<br />+ * as that is only done by a task on itself, and if the current task<br />+ * is here, it is not simultaneously in the exit code NULL'ing its<br />+ * cpuset pointer. This routine also might acquire callback_sem and<br />+ * current-&gt;mm-&gt;mmap_sem during call.<br /> *<br /> * The task_lock() is required to dereference current-&gt;cpuset safely.<br /> * Without it, we could pick up the pointer value of current-&gt;cpuset<br />&#64;&#64; -605,32 +618,36 &#64;&#64; static void guarantee_online_mems(const <br /> * task has been modifying its cpuset.<br /> */<br /> <br />-static void refresh_mems(void)<br />+void cpuset_update_task_memory_state()<br /> {<br /> int my_cpusets_mem_gen;<br />+ struct task_struct *tsk = current;<br />+ struct cpuset *cs = tsk-&gt;cpuset;<br /> <br />- task_lock(current);<br />- my_cpusets_mem_gen = current-&gt;cpuset-&gt;mems_generation;<br />- task_unlock(current);<br />+ if (unlikely(!cs))<br />+ return;<br />+<br />+ task_lock(tsk);<br />+ my_cpusets_mem_gen = cs-&gt;mems_generation;<br />+ task_unlock(tsk);<br /> <br />- if (current-&gt;cpuset_mems_generation != my_cpusets_mem_gen) {<br />- struct cpuset *cs;<br />- nodemask_t oldmem = current-&gt;mems_allowed;<br />+ if (my_cpusets_mem_gen != tsk-&gt;cpuset_mems_generation) {<br />+ nodemask_t oldmem = tsk-&gt;mems_allowed;<br /> int migrate;<br /> <br /> down(&amp;callback_sem);<br />- task_lock(current);<br />- cs = current-&gt;cpuset;<br />+ task_lock(tsk);<br />+ cs = tsk-&gt;cpuset; /* Maybe changed when task not locked */<br /> migrate = is_memory_migrate(cs);<br />- guarantee_online_mems(cs, &amp;current-&gt;mems_allowed);<br />- current-&gt;cpuset_mems_generation = cs-&gt;mems_generation;<br />- task_unlock(current);<br />+ guarantee_online_mems(cs, &amp;tsk-&gt;mems_allowed);<br />+ tsk-&gt;cpuset_mems_generation = cs-&gt;mems_generation;<br />+ task_unlock(tsk);<br /> up(&amp;callback_sem);<br />- if (!nodes_equal(oldmem, current-&gt;mems_allowed)) {<br />- numa_policy_rebind(&amp;oldmem, &amp;current-&gt;mems_allowed);<br />+ numa_policy_rebind(&amp;oldmem, &amp;tsk-&gt;mems_allowed);<br />+ if (!nodes_equal(oldmem, tsk-&gt;mems_allowed)) {<br /> if (migrate) {<br />- do_migrate_pages(current-&gt;mm, &amp;oldmem,<br />- &amp;current-&gt;mems_allowed,<br />+ do_migrate_pages(tsk-&gt;mm, &amp;oldmem,<br />+ &amp;tsk-&gt;mems_allowed,<br /> MPOL_MF_MOVE_ALL);<br /> }<br /> }<br />&#64;&#64; -1630,7 +1647,7 &#64;&#64; static long cpuset_create(struct cpuset <br /> return -ENOMEM;<br /> <br /> down(&amp;manage_sem);<br />- refresh_mems();<br />+ cpuset_update_task_memory_state();<br /> cs-&gt;flags = 0;<br /> if (notify_on_release(parent))<br /> set_bit(CS_NOTIFY_ON_RELEASE, &amp;cs-&gt;flags);<br />&#64;&#64; -1688,7 +1705,7 &#64;&#64; static int cpuset_rmdir(struct inode *un<br /> /* the vfs holds both inode-&gt;i_sem already */<br /> <br /> down(&amp;manage_sem);<br />- refresh_mems();<br />+ cpuset_update_task_memory_state();<br /> if (atomic_read(&amp;cs-&gt;count) &gt; 0) {<br /> up(&amp;manage_sem);<br /> return -EBUSY;<br />&#64;&#64; -1873,36 +1890,6 &#64;&#64; void cpuset_init_current_mems_allowed(vo<br /> }<br /> <br /> /**<br />- * cpuset_update_current_mems_allowed - update mems parameters to new values<br />- *<br />- * If the current tasks cpusets mems_allowed changed behind our backs,<br />- * update current-&gt;mems_allowed and mems_generation to the new value.<br />- * Do not call this routine if in_interrupt().<br />- *<br />- * Call without callback_sem or task_lock() held. May be called<br />- * with or without manage_sem held. Unless exiting, it will acquire<br />- * task_lock(). Also might acquire callback_sem during call to<br />- * refresh_mems().<br />- */<br />-<br />-void cpuset_update_current_mems_allowed(void)<br />-{<br />- struct cpuset *cs;<br />- int need_to_refresh = 0;<br />-<br />- task_lock(current);<br />- cs = current-&gt;cpuset;<br />- if (!cs)<br />- goto done;<br />- if (current-&gt;cpuset_mems_generation != cs-&gt;mems_generation)<br />- need_to_refresh = 1;<br />-done:<br />- task_unlock(current);<br />- if (need_to_refresh)<br />- refresh_mems();<br />-}<br />-<br />-/**<br /> * cpuset_zonelist_valid_mems_allowed - check zonelist vs. curremt mems_allowed<br /> * &#64;zl: the zonelist to be checked<br /> *<br />--- 2.6.15-rc3-mm1.orig/mm/mempolicy.c 2005-12-07 22:00:40.525983551 -0800<br />+++ 2.6.15-rc3-mm1/mm/mempolicy.c 2005-12-07 23:48:54.994978144 -0800<br />&#64;&#64; -389,7 +389,7 &#64;&#64; static int contextualize_policy(int mode<br /> if (!nodes)<br /> return 0;<br /> <br />- cpuset_update_current_mems_allowed();<br />+ cpuset_update_task_memory_state();<br /> if (!cpuset_nodes_subset_current_mems_allowed(*nodes))<br /> return -EINVAL;<br /> return mpol_check_policy(mode, nodes);<br />&#64;&#64; -463,7 +463,7 &#64;&#64; long do_get_mempolicy(int *policy, nodem<br /> struct vm_area_struct *vma = NULL;<br /> struct mempolicy *pol = current-&gt;mempolicy;<br /> <br />- cpuset_update_current_mems_allowed();<br />+ cpuset_update_task_memory_state();<br /> if (flags &amp; ~(unsigned long)(MPOL_F_NODE|MPOL_F_ADDR))<br /> return -EINVAL;<br /> if (flags &amp; MPOL_F_ADDR) {<br />&#64;&#64; -1118,7 +1118,7 &#64;&#64; alloc_page_vma(gfp_t gfp, struct vm_area<br /> {<br /> struct mempolicy *pol = get_vma_policy(current, vma, addr);<br /> <br />- cpuset_update_current_mems_allowed();<br />+ cpuset_update_task_memory_state();<br /> <br /> if (unlikely(pol-&gt;policy == MPOL_INTERLEAVE)) {<br /> unsigned nid;<br />&#64;&#64; -1144,7 +1144,7 &#64;&#64; alloc_page_vma(gfp_t gfp, struct vm_area<br /> * interrupt context and apply the current process NUMA policy.<br /> * Returns NULL when no page can be allocated.<br /> *<br />- * Don't call cpuset_update_current_mems_allowed() unless<br />+ * Don't call cpuset_update_task_memory_state() unless<br /> * 1) it's ok to take cpuset_sem (can WAIT), and<br /> * 2) allocating for current task (not interrupt).<br /> */<br />&#64;&#64; -1153,7 +1153,7 &#64;&#64; struct page *alloc_pages_current(gfp_t g<br /> struct mempolicy *pol = current-&gt;mempolicy;<br /> <br /> if ((gfp &amp; __GFP_WAIT) &amp;&amp; !in_interrupt())<br />- cpuset_update_current_mems_allowed();<br />+ cpuset_update_task_memory_state();<br /> if (!pol || in_interrupt())<br /> pol = &amp;default_policy;<br /> if (pol-&gt;policy == MPOL_INTERLEAVE)<br />-- <br /> I won't rest till it's the best ...<br /> Programmer, Linux Scalability<br /> Paul Jackson &lt;pj&#64;sgi.com&gt; 1.650.933.1373<br />-<br />To unsubscribe from this list: send the line "unsubscribe linux-kernel" in<br />the body of a message to majordomo&#64;vger.kernel.org<br />More majordomo info at <a href="http://vger.kernel.org/majordomo-info.html">http://vger.kernel.org/majordomo-info.html</a><br />Please read the FAQ at <a href="http://www.tux.org/lkml/">http://www.tux.org/lkml/</a><br /><br /></pre></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerr.gif" width="32" height="32" alt="\" /></td></tr><tr><td align="right" valign="bottom"> 聽 </td></tr><tr><td align="right" valign="bottom">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerl.gif" width="32" height="32" alt="\" /></td><td class="c">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerr.gif" width="32" height="32" alt="/" /></td></tr><tr><td align="right" valign="top" colspan="2"> 聽 </td><td class="lm">Last update: 2005-12-10 09:22 聽聽 [from the cache]<br />漏2003-2020 <a href="http://blog.jasper.es/"><span itemprop="editor">Jasper Spaans</span></a>|hosted at <a href="https://www.digitalocean.com/?refcode=9a8e99d24cf9">Digital Ocean</a> and my Meterkast|<a href="http://blog.jasper.es/categories.html#lkml-ref">Read the blog</a></td><td>聽</td></tr></table><script language="javascript" src="/js/styleswitcher.js" type="text/javascript"></script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10