Bug 1892264

Summary: Avoiding vmstat_update kworker running on the (OCP) exclusive CPUs
Product: Red Hat Enterprise Linux 8 Reporter: Daniel Bristot de Oliveira <daolivei>
Component: kernel-rtAssignee: Marcelo Tosatti <mtosatti>
kernel-rt sub component: Memory Management QA Contact: Mark Simmons <msimmons>
Status: CLOSED WONTFIX Docs Contact:
Severity: high    
Priority: unspecified CC: aquini, bhu, blitton, bwensley, ddutile, fiezzi, jlelli, keyoung, lcapitulino, marjones, mstowell, mtosatti, nilal, rt-maint, rt-qe, william.caban, yjoseph
Version: 8.4   
Target Milestone: rc   
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1919404 (view as bug list) Environment:
Last Closed: 2021-04-07 19:17:55 UTC Type: Feature Request
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1893178    
Bug Blocks: 1919404    
Attachments:
Description Flags
patch against oslat to write to /proc/sys/vm/quiet_vmstat
none
testpmd patch to quiet vmstat before pkt fwd loop none

Description Daniel Bristot de Oliveira 2020-10-28 10:38:57 UTC
Description of problem:

While trying to achieve low latency on OCP, I noticed the execution of this kworker on the isolated CPU:

----------------- %< ---------------
     ksoftirqd/4-50    [004] d...113  9301.455882: workqueue_queue_work: work struct=000000006eb18cd3 function=vmstat_update workqueue=00000000dac03c76 req_cpu=4 cpu=4
     ksoftirqd/4-50    [004] d...313  9301.455884: sched_wakeup: comm=kworker/4:1 pid=875 prio=120 target_cpu=004
     ksoftirqd/4-50    [004] d...413  9301.455891: <stack trace>
 => trace_event_raw_event_sched_wakeup_template
 => ttwu_do_wakeup
 => try_to_wake_up
 => __queue_work
 => delayed_work_timer_fn
 => run_timer_softirq
 => __do_softirq
 => run_ksoftirqd
 => smpboot_thread_fn
 => kthread
 => ret_from_fork
     kworker/4:1-875   [004] .......  9301.455901: workqueue_execute_start: work struct 000000006eb18cd3: function vmstat_update
----------------- >% ---------------


Version-Release number of selected component (if applicable):
4.18.0-193.27.1.rt13.76

How reproducible:
Always


Steps to Reproduce:
1. Running oslat on OCP
2. Watch dmesg -w looking for stalld messages

Actual results:
Kworkers running, with trace pointing to vmstat_update work.

Expected results:
No kworkers

Additional info:
The good news is that it seems that they execute at the beginning of the "exclusive" container (in the first 120-ish seconds), and might be a side effect of the transition from non-exclusive to exclusive.


Note: I also saw this kworker:

----------------- %< ---------------
           <...>-512642 [043] d...111  8670.567448: workqueue_queue_work: work struct=00000000299a67e1 function=drain_local_stock workqueue=000000002cfc6246 req_cpu=4 cpu=4
           <...>-512642 [043] d...311  8670.567453: sched_wakeup: comm=kworker/4:1 pid=875 prio=120 target_cpu=004
           <...>-512642 [043] d...411  8670.567461: <stack trace>
 => trace_event_raw_event_sched_wakeup_template
 => ttwu_do_wakeup
 => try_to_wake_up
 => __queue_work
 => queue_work_on
 => drain_all_stock
 => mem_cgroup_css_offline
 => css_killed_work_fn
 => process_one_work
 => worker_thread
 => kthread
 => ret_from_fork
     kworker/4:1-875   [004] .......  8670.567465: workqueue_execute_start: work struct 00000000299a67e1: function drain_local_stock
----------------- >% ---------------

But it seems to run at the end of the exclusive execution, to remove data from there. Anyway, if it is also happening during the execution, we will need to file another BZ.

Comment 2 Marcelo Tosatti 2020-10-28 12:50:09 UTC
Daniel,

It might be useful to open individual bugs for each kworker (since the solution
is separate).

Also, for the runc issue... Note that for kworkers there is an expectation that 10us per 1ms division
will be sufficient (since we know that kworkers perform periodic, short jobs) but for userspace 
sufficient execution time might be larger: lack of progress might trigger timeouts up the stack, 
causing (for example) container restarts.

Great progress!

Comment 3 Daniel Bristot de Oliveira 2020-10-28 14:18:53 UTC
Yeah, I thought about opening two BZs, but if the memcg happens only after the end of the exclusive pod, it will not be a problem. So I mentioned it here as a "hey, if you hit this stack while the workload is running, please file a BZ."

The side effects of throttling kworkers will be felt by the threads waiting for it, obviously. That is why it is important to try to avoid them at all, as you are trying to achieve.

Comment 4 Marcelo Tosatti 2020-11-17 16:34:36 UTC
Patch posted upstream:

https://lore.kernel.org/linux-mm/20201117162805.GA274911@fuller.cnet/T/#u

Test application:

#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

void main(void)
{
        int ret, fd;
        void *buf = malloc(4096);

        fd = open("/proc/sys/vm/quiet_vmstat", O_RDWR);
        if (fd == -1) {
                perror("open /proc/sys/vm/quiet_vmstat");
                exit(0);
        }

        memset(buf, 1, 4096);
        ret = mlock(buf, 4096);
        if (ret) {
                perror("mlock");
                exit(0);
        }

        ret = write(fd, buf, 1);
        if (ret == -1) {
                perror("write");
                exit(0);
        }

        while (ret != 0)
                memset(buf, 0, 10);

}

Comment 5 Marcelo Tosatti 2020-11-18 13:41:41 UTC
Created attachment 1730547 [details]
patch against oslat to write to /proc/sys/vm/quiet_vmstat

Comment 7 Marcelo Tosatti 2020-11-23 19:01:05 UTC
Created attachment 1732633 [details]
testpmd patch to quiet vmstat before pkt fwd loop

Built but untested.

Comment 8 Marcelo Tosatti 2020-11-23 19:02:42 UTC
(In reply to Marcelo Tosatti from comment #7)
> Created attachment 1732633 [details]
> testpmd patch to quiet vmstat before pkt fwd loop
> 
> Built but untested.

Against dpdk.git.

Comment 12 Martin Sivák 2020-12-13 11:31:37 UTC
One question, would something like this work as a wrapper too?

isolate.sh
#!/bin/sh
cat > /proc/sys/vm/quiet_vmstat &
exec "$@"



./isolate.sh oslat ....

Comment 13 Marcelo Tosatti 2020-12-14 17:01:04 UTC
(In reply to Martin Sivák from comment #12)
> One question, would something like this work as a wrapper too?
> 
> isolate.sh
> #!/bin/sh
> cat > /proc/sys/vm/quiet_vmstat &
> exec "$@"
> 
> 
> 
> ./isolate.sh oslat ....

Depends on the application, but for oslat, for example, it won't work.

So its better to suggest a proper change (which won't be a write to a file in /proc/, but
a prctl interface).

Anyway, for the current interface, please do it properly inside the application.

Comment 15 Ken Young 2021-01-14 20:11:45 UTC
Bryan,

Is this a defect we can publish as a known issue?  It does impact OCP and the DU use case.

/KenY

Comment 19 Luiz Capitulino 2021-01-29 03:05:18 UTC
This is clearly a feature and not a bug, marking the BZ appropriately.

Also dropping NEEDINFO request since question has been answered.