aboutsummaryrefslogtreecommitdiffstats
path: root/mm/hugetlb.c
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2014-08-06 19:06:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 21:01:19 -0400
commit238d3c13f0cce38752072dc90f4e828abdfec143 (patch)
tree686986a56b3ca23679850c9bd87429fb37dd7cba /mm/hugetlb.c
parentf37d4298aa7f8b74395aa13c728677e2ed86fdaf (diff)
mm, hugetlb: generalize writes to nr_hugepages
Three different interfaces alter the maximum number of hugepages for an hstate: - /proc/sys/vm/nr_hugepages for global number of hugepages of the default hstate, - /sys/kernel/mm/hugepages/hugepages-X/nr_hugepages for global number of hugepages for a specific hstate, and - /sys/kernel/mm/hugepages/hugepages-X/nr_hugepages/mempolicy for number of hugepages for a specific hstate over the set of allowed nodes. Generalize the code so that a single function handles all of these writes instead of duplicating the code in two different functions. This decreases the number of lines of code, but also reduces the size of .text by about half a percent since set_max_huge_pages() can be inlined. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Acked-by: Davidlohr Bueso <davidlohr@hp.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/hugetlb.c')
-rw-r--r--mm/hugetlb.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e84d22ce5de8..7a0fcb33973e 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1734,21 +1734,13 @@ static ssize_t nr_hugepages_show_common(struct kobject *kobj,
1734 return sprintf(buf, "%lu\n", nr_huge_pages); 1734 return sprintf(buf, "%lu\n", nr_huge_pages);
1735} 1735}
1736 1736
1737static ssize_t nr_hugepages_store_common(bool obey_mempolicy, 1737static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
1738 struct kobject *kobj, struct kobj_attribute *attr, 1738 struct hstate *h, int nid,
1739 const char *buf, size_t len) 1739 unsigned long count, size_t len)
1740{ 1740{
1741 int err; 1741 int err;
1742 int nid;
1743 unsigned long count;
1744 struct hstate *h;
1745 NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY); 1742 NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
1746 1743
1747 err = kstrtoul(buf, 10, &count);
1748 if (err)
1749 goto out;
1750
1751 h = kobj_to_hstate(kobj, &nid);
1752 if (hstate_is_gigantic(h) && !gigantic_page_supported()) { 1744 if (hstate_is_gigantic(h) && !gigantic_page_supported()) {
1753 err = -EINVAL; 1745 err = -EINVAL;
1754 goto out; 1746 goto out;
@@ -1784,6 +1776,23 @@ out:
1784 return err; 1776 return err;
1785} 1777}
1786 1778
1779static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
1780 struct kobject *kobj, const char *buf,
1781 size_t len)
1782{
1783 struct hstate *h;
1784 unsigned long count;
1785 int nid;
1786 int err;
1787
1788 err = kstrtoul(buf, 10, &count);
1789 if (err)
1790 return err;
1791
1792 h = kobj_to_hstate(kobj, &nid);
1793 return __nr_hugepages_store_common(obey_mempolicy, h, nid, count, len);
1794}
1795
1787static ssize_t nr_hugepages_show(struct kobject *kobj, 1796static ssize_t nr_hugepages_show(struct kobject *kobj,
1788 struct kobj_attribute *attr, char *buf) 1797 struct kobj_attribute *attr, char *buf)
1789{ 1798{
@@ -1793,7 +1802,7 @@ static ssize_t nr_hugepages_show(struct kobject *kobj,
1793static ssize_t nr_hugepages_store(struct kobject *kobj, 1802static ssize_t nr_hugepages_store(struct kobject *kobj,
1794 struct kobj_attribute *attr, const char *buf, size_t len) 1803 struct kobj_attribute *attr, const char *buf, size_t len)
1795{ 1804{
1796 return nr_hugepages_store_common(false, kobj, attr, buf, len); 1805 return nr_hugepages_store_common(false, kobj, buf, len);
1797} 1806}
1798HSTATE_ATTR(nr_hugepages); 1807HSTATE_ATTR(nr_hugepages);
1799 1808
@@ -1812,7 +1821,7 @@ static ssize_t nr_hugepages_mempolicy_show(struct kobject *kobj,
1812static ssize_t nr_hugepages_mempolicy_store(struct kobject *kobj, 1821static ssize_t nr_hugepages_mempolicy_store(struct kobject *kobj,
1813 struct kobj_attribute *attr, const char *buf, size_t len) 1822 struct kobj_attribute *attr, const char *buf, size_t len)
1814{ 1823{
1815 return nr_hugepages_store_common(true, kobj, attr, buf, len); 1824 return nr_hugepages_store_common(true, kobj, buf, len);
1816} 1825}
1817HSTATE_ATTR(nr_hugepages_mempolicy); 1826HSTATE_ATTR(nr_hugepages_mempolicy);
1818#endif 1827#endif
@@ -2248,36 +2257,21 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
2248 void __user *buffer, size_t *length, loff_t *ppos) 2257 void __user *buffer, size_t *length, loff_t *ppos)
2249{ 2258{
2250 struct hstate *h = &default_hstate; 2259 struct hstate *h = &default_hstate;
2251 unsigned long tmp; 2260 unsigned long tmp = h->max_huge_pages;
2252 int ret; 2261 int ret;
2253 2262
2254 if (!hugepages_supported()) 2263 if (!hugepages_supported())
2255 return -ENOTSUPP; 2264 return -ENOTSUPP;
2256 2265
2257 tmp = h->max_huge_pages;
2258
2259 if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
2260 return -EINVAL;
2261
2262 table->data = &tmp; 2266 table->data = &tmp;
2263 table->maxlen = sizeof(unsigned long); 2267 table->maxlen = sizeof(unsigned long);
2264 ret = proc_doulongvec_minmax(table, write, buffer, length, ppos); 2268 ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
2265 if (ret) 2269 if (ret)
2266 goto out; 2270 goto out;
2267 2271
2268 if (write) { 2272 if (write)
2269 NODEMASK_ALLOC(nodemask_t, nodes_allowed, 2273 ret = __nr_hugepages_store_common(obey_mempolicy, h,
2270 GFP_KERNEL | __GFP_NORETRY); 2274 NUMA_NO_NODE, tmp, *length);
2271 if (!(obey_mempolicy &&
2272 init_nodemask_of_mempolicy(nodes_allowed))) {
2273 NODEMASK_FREE(nodes_allowed);
2274 nodes_allowed = &node_states[N_MEMORY];
2275 }
2276 h->max_huge_pages = set_max_huge_pages(h, tmp, nodes_allowed);
2277
2278 if (nodes_allowed != &node_states[N_MEMORY])
2279 NODEMASK_FREE(nodes_allowed);
2280 }
2281out: 2275out:
2282 return ret; 2276 return ret;
2283} 2277}