Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1635204 > unrolled thread
| Started by | Marcelo Tosatti <mtosatti@redhat.com> |
|---|---|
| First post | 2017-05-03 20:50 +0200 |
| Last post | 2017-05-11 17:40 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[patch 0/3] per-CPU vmstat thresholds and vmstat worker disablement (v2) Marcelo Tosatti <mtosatti@redhat.com> - 2017-05-03 20:50 +0200
[patch 3/3] MM: allow per-cpu vmstat_worker configuration Marcelo Tosatti <mtosatti@redhat.com> - 2017-05-03 20:50 +0200
Re: [patch 3/3] MM: allow per-cpu vmstat_worker configuration Rik van Riel <riel@redhat.com> - 2017-05-10 17:40 +0200
Re: [patch 3/3] MM: allow per-cpu vmstat_worker configuration Marcelo Tosatti <mtosatti@redhat.com> - 2017-05-11 17:40 +0200
| From | Marcelo Tosatti <mtosatti@redhat.com> |
|---|---|
| Date | 2017-05-03 20:50 +0200 |
| Subject | [patch 0/3] per-CPU vmstat thresholds and vmstat worker disablement (v2) |
| Message-ID | <tD7vz-Hg-5@gated-at.bofh.it> |
The per-CPU vmstat worker is a problem on -RT workloads (because ideally the CPU is entirely reserved for the -RT app, without interference). The worker transfers accumulated per-CPU vmstat counters to global counters. To resolve the problem, create two tunables: * Userspace configurable per-CPU vmstat threshold: by default the VM code calculates the size of the per-CPU vmstat arrays. This tunable allows userspace to configure the values. * Userspace configurable per-CPU vmstat worker: allow disabling the per-CPU vmstat worker. v2: - Improve documentation (Rik/Luiz). - Split patch in two (Luiz). - Fix comparison to include equal, in the helpers for stats accounting.
[toc] | [next] | [standalone]
| From | Marcelo Tosatti <mtosatti@redhat.com> |
|---|---|
| Date | 2017-05-03 20:50 +0200 |
| Subject | [patch 3/3] MM: allow per-cpu vmstat_worker configuration |
| Message-ID | <tD7vA-Hg-17@gated-at.bofh.it> |
| In reply to | #1635204 |
Following the reasoning on the last patch in the series,
this patch allows configuration of the per-CPU vmstat worker:
it allows the user to disable the per-CPU vmstat worker.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
--- linux/mm/vmstat.c.sothresh 2017-05-03 11:01:17.465914562 -0300
+++ linux/mm/vmstat.c 2017-05-03 11:01:39.746961917 -0300
@@ -92,6 +92,7 @@
EXPORT_SYMBOL(vm_node_stat);
struct vmstat_uparam {
+ atomic_t vmstat_work_enabled;
atomic_t user_stat_thresh;
};
@@ -1606,6 +1607,9 @@
long val;
int err;
int i;
+ int cpu;
+ struct work_struct __percpu *works;
+ static struct cpumask has_work;
/*
* The regular update, every sysctl_stat_interval, may come later
@@ -1619,9 +1623,31 @@
* transiently negative values, report an error here if any of
* the stats is negative, so we know to go looking for imbalance.
*/
- err = schedule_on_each_cpu(refresh_vm_stats);
- if (err)
- return err;
+
+ works = alloc_percpu(struct work_struct);
+ if (!works)
+ return -ENOMEM;
+
+ cpumask_clear(&has_work);
+ get_online_cpus();
+
+ for_each_online_cpu(cpu) {
+ struct work_struct *work = per_cpu_ptr(works, cpu);
+ struct vmstat_uparam *vup = &per_cpu(vmstat_uparam, cpu);
+
+ if (atomic_read(&vup->vmstat_work_enabled)) {
+ INIT_WORK(work, refresh_vm_stats);
+ schedule_work_on(cpu, work);
+ cpumask_set_cpu(cpu, &has_work);
+ }
+ }
+
+ for_each_cpu(cpu, &has_work)
+ flush_work(per_cpu_ptr(works, cpu));
+
+ put_online_cpus();
+ free_percpu(works);
+
for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {
val = atomic_long_read(&vm_zone_stat[i]);
if (val < 0) {
@@ -1713,6 +1739,10 @@
/* Check processors whose vmstat worker threads have been disabled */
for_each_online_cpu(cpu) {
struct delayed_work *dw = &per_cpu(vmstat_work, cpu);
+ struct vmstat_uparam *vup = &per_cpu(vmstat_uparam, cpu);
+
+ if (atomic_read(&vup->vmstat_work_enabled) == 0)
+ continue;
if (!delayed_work_pending(dw) && need_update(cpu))
queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0);
@@ -1737,6 +1767,40 @@
#ifdef CONFIG_SYSFS
+static ssize_t vmstat_worker_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned int cpu = dev->id;
+ struct vmstat_uparam *vup = &per_cpu(vmstat_uparam, cpu);
+
+ return sprintf(buf, "%d\n", atomic_read(&vup->vmstat_work_enabled));
+}
+
+static ssize_t vmstat_worker_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int ret, val;
+ struct vmstat_uparam *vup;
+ unsigned int cpu = dev->id;
+
+ ret = sscanf(buf, "%d", &val);
+ if (ret != 1 || val > 1 || val < 0)
+ return -EINVAL;
+
+ preempt_disable();
+
+ if (cpu_online(cpu)) {
+ vup = &per_cpu(vmstat_uparam, cpu);
+ atomic_set(&vup->vmstat_work_enabled, val);
+ } else
+ count = -EINVAL;
+
+ preempt_enable();
+
+ return count;
+}
+
static ssize_t vmstat_thresh_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1779,10 +1843,14 @@
return count;
}
+struct device_attribute vmstat_worker_attr =
+ __ATTR(vmstat_worker, 0644, vmstat_worker_show, vmstat_worker_store);
+
struct device_attribute vmstat_threshold_attr =
__ATTR(vmstat_threshold, 0644, vmstat_thresh_show, vmstat_thresh_store);
static struct attribute *vmstat_attrs[] = {
+ &vmstat_worker_attr.attr,
&vmstat_threshold_attr.attr,
NULL
};
@@ -1820,6 +1888,7 @@
struct vmstat_uparam *vup = &per_cpu(vmstat_uparam, cpu);
atomic_set(&vup->user_stat_thresh, 0);
+ atomic_set(&vup->vmstat_work_enabled, 1);
}
}
@@ -1857,6 +1926,7 @@
node = cpu_to_node(cpu);
atomic_set(&vup->user_stat_thresh, 0);
+ atomic_set(&vup->vmstat_work_enabled, 1);
refresh_zone_stat_thresholds();
node_cpus = cpumask_of_node(node);
[toc] | [prev] | [next] | [standalone]
| From | Rik van Riel <riel@redhat.com> |
|---|---|
| Date | 2017-05-10 17:40 +0200 |
| Subject | Re: [patch 3/3] MM: allow per-cpu vmstat_worker configuration |
| Message-ID | <tFBSx-2s3-9@gated-at.bofh.it> |
| In reply to | #1635209 |
On Wed, 2017-05-03 at 15:40 -0300, Marcelo Tosatti wrote: > Following the reasoning on the last patch in the series, > this patch allows configuration of the per-CPU vmstat worker: > it allows the user to disable the per-CPU vmstat worker. > > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Is there ever a case where you would want to configure this separately from the vmstat_threshold parameter? What use cases are you trying to address?
[toc] | [prev] | [next] | [standalone]
| From | Marcelo Tosatti <mtosatti@redhat.com> |
|---|---|
| Date | 2017-05-11 17:40 +0200 |
| Subject | Re: [patch 3/3] MM: allow per-cpu vmstat_worker configuration |
| Message-ID | <tFYm5-88r-5@gated-at.bofh.it> |
| In reply to | #1638917 |
On Wed, May 10, 2017 at 11:34:26AM -0400, Rik van Riel wrote: > On Wed, 2017-05-03 at 15:40 -0300, Marcelo Tosatti wrote: > > Following the reasoning on the last patch in the series, > > this patch allows configuration of the per-CPU vmstat worker: > > it allows the user to disable the per-CPU vmstat worker. > > > > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> > > Is there ever a case where you would want to configure > this separately from the vmstat_threshold parameter? > > What use cases are you trying to address? If you have a case where the performance decrease due to lack of vmstat collection aggretation (vmstat_threshold=1) is significant, so you increase vmstat_threshold on these CPUs to, say, 10 (and is willing to accept the cost of outdated vmstatistics by 10). This is the case that i imagined when separating the options in two (with the idea to have policy in userspace, not in the kernel). Do you think such case is not realistic? (Or that there are other problems by having vmstat_threshold > 1 and vmstat_worker=0).
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web