BPF / XDP: 'bpftool batch file' returns 'Error: reading batch file failed: Operation not permitted' - ebpf

I have a docker container with an XDP program loaded on it. I also have a batch file for the bpftool to run. When I run bpftool batch file tmp_bpftool.txt, I get Error: reading batch file failed: Operation not permitted. I am the root in the container. So, what could possibly be the problem?
The batch file is as below: (512 updates on map 59 and 1 update on map 58)
map update id 59 key 0 0 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
map update id 59 key 1 0 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
.
.
.
map update id 59 key 255 0 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
map update id 59 key 0 1 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
map update id 59 key 1 1 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
.
. // All the way down to ... (512 entries for id 59)
.
map update id 59 key 254 1 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
map update id 59 key 255 1 00 00 00 00 00 00 value 10 0 0 1 10 89 0 4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 0 0 0 4 00 00
map update id 58 key 10 89 0 4 00 00 00 00 value 0 0 00 00 00 00 00 00
UPDATE:
Here is the output of the strace bpftool batch file command:
execve("/usr/sbin/bpftool", ["bpftool", "batch", "file", "tmp_bpftool.txt"], 0x7fffdb7d3a98 /* 9 vars */) = 0
brk(NULL) = 0x558ee931c000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd7cb85610) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=13993, ...}) = 0
mmap(NULL, 13993, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9c4c69f000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\346\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=192032, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9c4c69d000
mmap(NULL, 194944, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c4c66d000
mmap(0x7f9c4c67b000, 61440, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7f9c4c67b000
mmap(0x7f9c4c68a000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d000) = 0x7f9c4c68a000
mmap(0x7f9c4c698000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2a000) = 0x7f9c4c698000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \22\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=18816, ...}) = 0
mmap(NULL, 20752, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c4c667000
mmap(0x7f9c4c668000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f9c4c668000
mmap(0x7f9c4c66a000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9c4c66a000
mmap(0x7f9c4c66b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9c4c66b000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360A\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\237\333t\347\262\27\320l\223\27*\202C\370T\177"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029560, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\237\333t\347\262\27\320l\223\27*\202C\370T\177"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c4c475000
mmap(0x7f9c4c497000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f9c4c497000
mmap(0x7f9c4c60f000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f9c4c60f000
mmap(0x7f9c4c65d000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f9c4c65d000
mmap(0x7f9c4c663000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f9c4c663000
close(3) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9c4c472000
arch_prctl(ARCH_SET_FS, 0x7f9c4c472740) = 0
mprotect(0x7f9c4c65d000, 16384, PROT_READ) = 0
mprotect(0x7f9c4c66b000, 4096, PROT_READ) = 0
mprotect(0x7f9c4c698000, 16384, PROT_READ) = 0
mprotect(0x558ee85e3000, 16384, PROT_READ) = 0
mprotect(0x7f9c4c6d0000, 4096, PROT_READ) = 0
munmap(0x7f9c4c69f000, 13993) = 0
openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
close(3) = 0
brk(NULL) = 0x558ee931c000
brk(0x558ee933d000) = 0x558ee933d000
getuid() = 0
getgid() = 0
geteuid() = 0
getegid() = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
ioctl(-1, TIOCGPGRP, 0x7ffd7cb85464) = -1 EBADF (Bad file descriptor)
sysinfo({uptime=1021, loads=[43680, 55104, 39616], totalram=8066469888, freeram=1033973760, sharedram=594358272, bufferram=135041024, totalswap=2147479552, freeswap=2147479552, procs=1331, totalhigh=0, freehigh=0, mem_unit=1}) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
uname({sysname="Linux", nodename="balancer", ...}) = 0
stat("/xdp", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/xdp", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getpid() = 177
getppid() = 174
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=494, ...}) = 0
read(3, "# /etc/nsswitch.conf\n#\n# Example"..., 4096) = 494
read(3, "", 4096) = 0
close(3) = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=13993, ...}) = 0
mmap(NULL, 13993, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9c4c69f000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3005\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=51832, ...}) = 0
mmap(NULL, 79672, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c4c45e000
mmap(0x7f9c4c461000, 28672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9c4c461000
mmap(0x7f9c4c468000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0x7f9c4c468000
mmap(0x7f9c4c46a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xb000) = 0x7f9c4c46a000
mmap(0x7f9c4c46c000, 22328, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f9c4c46c000
close(3) = 0
mprotect(0x7f9c4c46a000, 4096, PROT_READ) = 0
munmap(0x7f9c4c69f000, 13993) = 0
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=976, ...}) = 0
read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 976
close(3) = 0
getpid() = 177
getpgrp() = 174
ioctl(2, TIOCGPGRP, [174]) = 0
rt_sigaction(SIGCHLD, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=30509, rlim_max=30509}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
openat(AT_FDCWD, "/usr/sbin/bpftool", O_RDONLY) = 3
stat("/usr/sbin/bpftool", {st_mode=S_IFREG|0755, st_size=1622, ...}) = 0
ioctl(3, TCGETS, 0x7ffd7cb853f0) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
read(3, "#!/bin/bash\nfull_version=`uname "..., 80) = 80
lseek(3, 0, SEEK_SET) = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=512*1024}) = 0
fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
dup2(3, 255) = 255
close(3) = 0
fcntl(255, F_SETFD, FD_CLOEXEC) = 0
fcntl(255, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
fstat(255, {st_mode=S_IFREG|0755, st_size=1622, ...}) = 0
lseek(255, 0, SEEK_CUR) = 0
read(255, "#!/bin/bash\nfull_version=`uname "..., 1622) = 1622
pipe([3, 4]) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [INT CHLD], [], 8) = 0
lseek(255, -1586, SEEK_CUR) = 36
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f9c4c472a10) = 178
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
close(4) = 0
read(3, "5.13.0-35-generic\n", 128) = 18
read(3, "", 128) = 0
close(3) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=178, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG, NULL) = 178
wait4(-1, 0x7ffd7cb847d0, WNOHANG, NULL) = -1 ECHILD (No child processes)
rt_sigreturn({mask=[]}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x558ee8526480, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=0x558ee8526480, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(255, "\n# First check for a fully quali"..., 1622) = 1586
pipe([3, 4]) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [INT CHLD], [], 8) = 0
lseek(255, -1484, SEEK_CUR) = 138
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f9c4c472a10) = 179
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
close(4) = 0
read(3, "bpftool\n", 128) = 8
read(3, "", 128) = 0
close(3) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=179, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG, NULL) = 179
wait4(-1, 0x7ffd7cb84710, WNOHANG, NULL) = -1 ECHILD (No child processes)
rt_sigreturn({mask=[]}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x558ee8526480, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=0x558ee8526480, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(255, "if [ -f \"$this\" ]; then\n\texec \"$"..., 1622) = 1484
stat("/usr/lib/linux-tools/5.13.0-35-generic/bpftool", {st_mode=S_IFREG|0755, st_size=1650632, ...}) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, {sa_handler=0x558ee8529aa0, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f9c4c4b80c0}, 8) = 0
lseek(255, -1438, SEEK_CUR) = 184
execve("/usr/lib/linux-tools/5.13.0-35-generic/bpftool", ["/usr/lib/linux-tools/5.13.0-35-g"..., "batch", "file", "tmp_bpftool.txt"], 0x558ee9325940 /* 8 vars */) = 0
brk(NULL) = 0x556ccae20000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd8177b850) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=13993, ...}) = 0
mmap(NULL, 13993, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9c039c5000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libelf.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\2005\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=109200, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9c039c3000
mmap(NULL, 110976, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c039a7000
mmap(0x7f9c039aa000, 73728, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f9c039aa000
mmap(0x7f9c039bc000, 20480, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f9c039bc000
mmap(0x7f9c039c1000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19000) = 0x7f9c039c1000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\"\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=108936, ...}) = 0
mmap(NULL, 110776, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c0398b000
mprotect(0x7f9c0398d000, 98304, PROT_NONE) = 0
mmap(0x7f9c0398d000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f9c0398d000
mmap(0x7f9c0399e000, 24576, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13000) = 0x7f9c0399e000
mmap(0x7f9c039a5000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19000) = 0x7f9c039a5000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300#\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=31120, ...}) = 0
mmap(NULL, 33112, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c03982000
mprotect(0x7f9c03984000, 20480, PROT_NONE) = 0
mmap(0x7f9c03984000, 12288, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f9c03984000
mmap(0x7f9c03987000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5000) = 0x7f9c03987000
mmap(0x7f9c03989000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f9c03989000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360A\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\237\333t\347\262\27\320l\223\27*\202C\370T\177"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029560, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0#\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\237\333t\347\262\27\320l\223\27*\202C\370T\177"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f9c03790000
mmap(0x7f9c037b2000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f9c037b2000
mmap(0x7f9c0392a000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f9c0392a000
mmap(0x7f9c03978000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f9c03978000
mmap(0x7f9c0397e000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f9c0397e000
close(3) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9c0378e000
arch_prctl(ARCH_SET_FS, 0x7f9c0378eb80) = 0
mprotect(0x7f9c03978000, 16384, PROT_READ) = 0
mprotect(0x7f9c03989000, 4096, PROT_READ) = 0
mprotect(0x7f9c039a5000, 4096, PROT_READ) = 0
mprotect(0x7f9c039c1000, 4096, PROT_READ) = 0
mprotect(0x556cc8e27000, 12288, PROT_READ) = 0
mprotect(0x7f9c039f6000, 4096, PROT_READ) = 0
munmap(0x7f9c039c5000, 13993) = 0
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x28 /* CAP_??? */) = 0
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
brk(NULL) = 0x556ccae20000
brk(0x556ccae41000) = 0x556ccae41000
openat(AT_FDCWD, "tmp_bpftool.txt", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=70140, ...}) = 0
read(3, "map update id 15 key 0 0 00 00 0"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "00 00 00 00 00 00 value 10 0 0 1"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "0 value 10 0 0 1 10 89 0 4 00 00"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 10 89 0 4 00 00 00 00 00 00 00 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "0 0 1 10 89 0 4 00 00 00 00 00 0"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "0 00 value 10 0 0 1 10 89 0 4 00"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 00 00 00 00 00 00 value 10 0 0 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "d 15 key 210 0 00 00 00 00 00 00"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " \nmap update id 15 key 240 0 00 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "te id 15 key 14 1 00 00 00 00 00"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "1 00 00 00 00 00 00 value 10 0 0"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 00 value 10 0 0 1 10 89 0 4 00 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "0 0 0 1 10 89 0 4 00 00 00 00 00"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 00 00 value 10 0 0 1 10 89 0 4 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 1 00 00 00 00 00 00 value 10 0 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " id 15 key 194 1 00 00 00 00 00 "..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "00 \nmap update id 15 key 224 1 0"..., 4096) = 4096
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, " 0 0 0 0 6 00 00 \nmap update id "..., 4096) = 508
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=15, next_id=0, open_flags=0}, 120) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=80, info=0x7ffd81753730}}, 120) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=4, key=0x556ccae21490, value=0x556ccae214b0, flags=BPF_ANY}, 120) = 0
close(4) = 0
read(3, "", 4096) = 0
write(2, "Error: ", 7) = 7
write(2, "reading batch file failed: Opera"..., 50) = 50
write(2, "\n", 1) = 1
close(3) = 0
exit_group(-1) = ?
+++ exited with 255 +++

TL;DR: Your map update works fine. The message is a bug in bpftool.
Bpftool updates the maps just as you would expect; and then, after processing all the batch file, it checks errno. If errno is 0, it supposes that everything went fine, and it's good. If not, it prints strerror(errno) so you can see what went wrong when processing the file.
errno being set is not due to your map updates. I'm not entirely sure of what's happening to it. The bug was seemingly introduced with commit cf9bf714523d ("tools: bpftool: Allow unprivileged users to probe features"), where we manipulate process capabilities with libcap. Having a call to cap_get_proc() in feature.c is apparently enough for the executable to pick it up and to run some checks on capabilities that are supported, or not, on the system even if we're not doing any probing. I'm observing the following calls with strace:
# strace -e prctl ./bpftool batch file /tmp/batch
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
Error: reading batch file failed: Operation not permitted
+++ exited with 255 +++
This seems to be coming from cap_get_bound() in libcap, where the -1 returned is negated and passed to errno, thus becoming 1, Operation not permitted. I'm not sure what the capability numbers passed to prctl() correspond to.
I'm not sure what's the cleanest way to fix this. A simple workaround consists in resetting errno at the beginning of the main() function; we can submit that and see if the reviewers have a better idea. Let me know if you would like to send a patch yourself, otherwise I'll do it when I have a moment.
[EDIT August 2022] Fixed in libcap 2.63 and also in bpf-next for bpftool.

Related

Postgresql bottleneck neither CPU, network nor I/O

We are testing our application for performance, which is using Postgresql 13 as a database. It is very insert and update heavy and we cannot get more than 65k TPS on the database. But none of the most common bottlenecks do apply (CPU/network/disk IO).
We have also run multiple combinations with pgbench but also those cannot go past 65k.
E.g.
pgbench -i -s 50 -U postgres -h <DB_HOST> -d <DB_NAME>
pgbench -c 64 -j 32 -t 100000 -h <DB_HOST> -U postgres <DB_NAME>
starting vacuum...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 64
number of threads: 32
number of transactions per client: 100000
number of transactions actually processed: 6400000/6400000
latency average = 0.976 ms
tps = 65584.664360 (including connections establishing)
tps = 65594.330678 (excluding connections establishing)
(Using more clients resulted in fewer TPS)
The database server has the following specs:
64 Cores (Intel Xeon Gold 6130 (Skylake, 2.10GHz, 2 CPUs/node, 16 cores/CPU))
192 GiB RAM (12 * 16GiB DIMM DDR4 Synchronous Registered (Buffered) 2666 MHz (0.4 ns))
2 * SSD SATA Samsung MZ7KM240HMHQ0D3 (one is used for the WAL and the other for the data)
10 Gbps network link
OS: Debian 11
And we are using the following configuration:
shared_buffers=65551953kB
effective_cache_size=147491895kB
huge_pages=on
min_wal_size=4GB
max_wal_size=16GB
wal_buffers=1GB
work_mem=2GB
maintenance_work_mem=4GB
checkpoint_completion_target=0.9
checkpoint_timeout = 15min
random_page_cost=1.1
bgwriter_flush_after = 2MB
effective_io_concurrency = 200
# Disabled just for performance experiments
fsync = off
synchronous_commit = off
full_page_writes = on
max_worker_processes=64
max_parallel_workers=64
max_parallel_workers_per_gather=10
max_parallel_maintenance_workers=12
When we reach the 65k TPS we have the following resource usage on the server:
Our application:
CPU: 25%
I/O Utilization: 30% resp. 60% (WAL)
Network: in 200Mbps out 125Mbps
pgbench:
CPU: 75%
I/O Utilization: 2% resp. 5% (WAL)
Network: in/out ~500Mbps
We have also temporarily placed the WAL and data into RAM to verify that the disks are not the issue, but this had no impact either.
Does anyone have a guess where our bottleneck might be?
(We have thought about sharding already but would like to use the single server as much as possible)
Edit:
vmstat 1 -S M while running pgbench:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 92009 25 18316 0 0 3 318 405 22 26 11 63 0 0
0 0 0 92009 25 18316 0 0 0 0 261 320 0 0 100 0 0
0 0 0 92009 25 18316 0 0 0 46616 216 257 0 0 100 0 0
45 0 0 92260 25 17996 0 0 0 0 509124 781029 35 13 52 0 0
44 1 0 92252 25 17998 0 0 0 82192 743920 1140285 51 20 30 0 0
50 0 0 92247 25 18003 0 0 0 65564 740366 1152212 52 18 30 0 0
41 0 0 92243 25 18005 0 0 0 0 736052 1138409 50 20 30 0 0
35 0 0 92240 25 18009 0 0 0 0 734265 1138483 50 20 30 0 0
36 0 0 92238 25 18012 0 0 0 264 741315 1152409 52 19 29 0 0
43 0 0 92236 25 18016 0 0 0 36 740374 1147759 51 20 29 0 0
46 0 0 92231 25 18020 0 0 0 163856 737491 1166498 53 19 28 0 0
47 0 0 92228 25 18023 0 0 0 0 741582 1171814 52 19 28 0 0
43 0 0 92223 25 18027 0 0 0 61584 741537 1168119 53 19 28 0 0
46 0 0 92220 25 18030 0 0 0 36 739695 1167456 53 19 28 0 0
43 0 0 92216 25 18034 0 0 0 228 741992 1150333 52 20 29 0 0
38 0 0 92214 25 18036 0 0 0 147464 740589 1166289 52 19 28 0 0
41 0 0 92209 25 18042 0 0 0 0 737148 1162946 52 19 28 0 0
44 0 0 92207 25 18044 0 0 0 2480 741757 1173128 53 19 28 0 0
39 0 0 92205 25 18049 0 0 0 48 740404 1170644 53 19 28 0 0
52 0 0 92201 25 18051 0 0 0 292 739032 1159037 52 19 28 0 0
42 1 0 92198 25 18054 0 0 0 20072 740101 1165594 52 20 28 0 0
51 0 0 92194 25 18059 0 0 0 45464 738055 1165382 53 19 28 0 0
41 0 0 92190 25 18062 0 0 0 0 742838 1172377 53 19 28 0 0
45 0 0 92185 25 18067 0 0 0 36 740704 1174534 53 19 28 0 0
50 0 0 92182 25 18069 0 0 0 92 741691 1150716 52 19 28 0 0
42 0 0 92177 25 18073 0 0 0 28 740220 1168488 53 18 28 0 0
44 0 0 92174 25 18077 0 0 0 0 738818 1164769 53 19 28 0 0
46 0 0 92172 25 18080 0 0 0 0 740720 1169902 53 19 28 0 0
46 0 0 92166 25 18083 0 0 0 90404 592524 945810 42 15 43 0 0
45 0 0 92161 25 18087 0 0 0 3884 746310 1159898 52 19 28 0 0
49 0 0 92157 25 18090 0 0 0 20 747242 1177750 53 19 28 0 0
36 0 0 92152 25 18094 0 0 0 0 744477 1173832 53 19 28 0 0
46 0 0 92149 25 18098 0 0 0 0 746194 1172700 53 19 28 0 0
39 0 0 92147 26 18101 0 0 0 49768 745651 1177462 54 18 28 0 0
43 0 0 92143 26 18105 0 0 0 212 744968 1161110 53 19 28 0 0
43 0 0 92138 26 18109 0 0 0 0 743223 1176960 54 19 28 0 0
43 0 0 92135 26 18112 0 0 0 81920 745168 1173574 53 19 28 0 0
48 0 0 92132 26 18116 0 0 0 0 743174 1169255 53 19 28 0 0
48 0 0 92129 26 18120 0 0 0 68 592295 933445 42 15 43 0 0
41 0 0 92124 26 18123 0 0 0 76 740354 1162221 52 19 28 0 0
49 0 0 92120 26 18125 0 0 0 0 738456 1158291 53 19 28 0 0
39 0 0 92117 26 18129 0 0 0 147536 740735 1162479 52 20 28 0 0
49 0 0 92113 26 18133 0 0 0 0 737209 1165532 53 20 28 0 0
49 0 0 92111 26 18137 0 0 0 40 741185 1168133 54 19 28 0 0
45 0 0 92110 26 18140 0 0 0 4000 740693 1141945 52 20 28 0 0
42 0 0 92105 26 18144 0 0 0 0 741857 1168830 53 19 28 0 0
43 0 0 92102 26 18147 0 0 0 8 742546 1168867 54 18 28 0 0
43 0 0 92101 26 18150 0 0 0 147456 741941 1166646 53 19 28 0 0
41 1 0 92097 26 18154 0 0 0 64192 740052 1169040 53 19 28 0 0
48 0 0 92094 26 18158 0 0 0 27484 737224 1139511 52 20 28 0 0
47 0 0 92087 26 18162 0 0 0 0 740821 1165037 53 19 28 0 0
54 0 0 92059 26 18164 0 0 0 4 737109 1155098 53 19 27 0 0
38 0 0 92051 26 18170 0 0 0 147456 701847 1075069 55 20 25 0 0
35 0 0 92064 26 18174 0 0 0 44 723153 1125736 54 19 27 0 0
48 0 0 92056 26 18179 0 0 0 53008 734590 1134838 52 19 29 0 0
46 0 0 92053 26 18183 0 0 0 0 741595 1166891 53 19 28 0 0
46 0 0 92049 26 18186 0 0 0 0 740196 1170838 54 19 27 0 0
31 1 0 92045 26 18191 0 0 0 98304 741800 1170076 54 18 28 0 0
44 0 0 92043 26 18194 0 0 0 49188 733352 1173652 53 20 27 0 0
43 0 0 92028 26 18198 0 0 0 116 733522 1151497 53 20 27 0 0
44 0 0 92037 26 18201 0 0 0 0 730364 1137665 53 19 27 0 0
37 0 0 92035 26 18204 0 0 0 0 742348 1164945 53 19 28 0 0
44 0 0 92031 26 18208 0 0 0 0 739273 1165044 53 19 28 0 0
52 0 0 92028 26 18211 0 0 0 147888 739274 1164496 53 19 28 0 0
50 0 0 92024 26 18215 0 0 0 144 739684 1145210 53 19 28 0 0
50 0 0 92020 26 18219 0 0 0 0 742847 1167779 54 18 28 0 0
38 0 0 92016 26 18223 0 0 0 0 738079 1166580 53 19 28 0 0
36 0 0 92013 26 18226 0 0 0 0 742687 1171101 54 18 27 0 0
48 0 0 92009 26 18229 0 0 0 147500 741536 1166846 53 19 28 0 0
40 0 0 92006 26 18233 0 0 0 94600 740746 1147102 52 20 28 0 0
45 0 0 92001 26 18238 0 0 0 0 741119 1163851 53 19 28 0 0
48 0 0 91999 26 18241 0 0 0 0 740995 1167197 53 19 28 0 0
35 0 0 91996 26 18244 0 0 0 0 742235 1165666 53 19 28 0 0
44 1 0 91993 26 18248 0 0 0 49192 741392 1164506 53 19 28 0 0
43 1 0 91990 26 18251 0 0 0 124876 743695 1144639 52 19 29 0 0
48 0 0 91987 26 18255 0 0 0 24864 737759 1159383 52 20 28 0 0
44 0 0 91983 26 18258 0 0 0 0 740224 1164983 53 19 28 0 0
43 0 0 91980 26 18262 0 0 0 0 741742 1168140 54 19 27 0 0
18 0 0 91976 26 18267 0 0 0 36 737449 1162293 53 19 28 0 0
49 0 0 91973 26 18269 0 0 0 147576 741462 1148048 52 20 28 0 0
43 0 0 91969 26 18274 0 0 0 0 742408 1168332 54 19 27 0 0
43 0 0 91966 26 18277 0 0 0 0 738803 1164992 53 19 28 0 0
39 0 0 91963 26 18280 0 0 0 4 737891 1159372 52 19 28 0 0
43 0 0 91962 26 18283 0 0 0 40 741888 1166835 53 19 28 0 0
48 0 0 91958 26 18287 0 0 0 164144 738677 1145900 52 20 28 0 0
46 0 0 91955 26 18291 0 0 0 0 740956 1165789 53 19 28 0 0
44 0 0 91952 26 18295 0 0 0 0 741055 1166460 53 19 28 0 0
44 0 0 91948 26 18299 0 0 0 8 739414 1165698 53 19 28 0 0
46 0 0 91945 26 18301 0 0 0 48 743218 1165277 53 19 28 0 0
36 0 0 91941 26 18305 0 0 0 208 736320 1134425 51 20 29 0 0
47 0 0 91936 26 18309 0 0 0 239096 739799 1159730 52 19 28 0 0
45 0 0 91932 26 18312 0 0 0 0 742477 1167618 53 20 28 0 0
45 0 0 91928 26 18316 0 0 0 0 736442 1159690 52 20 28 0 0
47 0 0 91926 26 18319 0 0 0 76 737145 1157620 52 20 28 0 0
48 0 0 91921 26 18323 0 0 0 64 739999 1146323 52 19 29 0 0
50 0 0 91918 26 18326 0 0 0 197176 739590 1159797 52 19 28 0 0
50 0 0 91915 26 18330 0 0 0 0 740533 1166111 53 19 28 0 0
52 0 0 91911 26 18334 0 0 0 0 739776 1161328 52 20 28 0 0
42 0 0 91907 26 18338 0 0 0 60 590783 929545 41 16 43 0 0
39 0 0 91904 26 18341 0 0 0 4248 744434 1161062 52 19 29 0 0
41 1 0 91900 26 18345 0 0 0 114688 741817 1163511 53 19 28 0 0
14 0 0 91928 26 18349 0 0 0 32768 598242 996868 43 15 42 0 0
0 0 0 91951 26 18349 0 0 0 0 41914 84357 3 1 96 0 0
0 0 0 91952 26 18349 0 0 0 36 174 204 0 0 100 0 0
0 0 0 91954 26 18349 0 0 0 276 7897 13403 0 0 99 0 0
0 0 0 91954 26 18349 0 0 0 0 1911 3678 0 0 100 0 0
0 0 0 91954 26 18349 0 0 0 147456 330 351 0 0 100 0 0
Edit:
The same pgbench benchmark as above gave about 68k when it was run on the same system as the database and select only 540k (507k from a remote system).
Is CPU:75% user or user + system?
Anyway, 75% of OS CPU with hyper-threading means all cores 100% busy.
You use simple protocol tpc-b which is stressing network and context switches.
See https://franckpachot.medium.com/do-you-know-what-you-are-measuring-with-pgbench-d8692a33e3d6

Matlab find zero value with certain range

I have this matrix:
A =[22 22 142 142 142 92 92 92 0 0
0 109 109 151 151 151 23 23 149 149
0 0 0 152 152 152 38 38 0 0
0 13 13 113 113 113 119 119 119 0
0 8 8 8 84 84 14 14 14 0
0 0 144 144 144 0 0 0 66 66
139 139 139 34 34 34 0 0 0 0
0 0 64 64 64 128 128 59 59 59
83 83 83 65 65 65 67 67 67 0];
How can I find indices (row, column) from matrix with zero value respectively 2 or more?
You can use find as follows:
[r,c] = find(A==0)
[rows,cols] = ind2sub(size(A),find(A==0))
find gives you the indices and ind2sub converts them in column-row format.

Finding Good Ambisonics Objects for Pure Data?

Does anybody know of good (3D) ambisonics extensions for Pure Data?
I'm trying to setup some ambisonics examples for students in a small studio (8 speaker cube), so a simple 1st order panner and decoder object should be fine.
It seems like there are ambisonics libraries available in pd-extended, but I can't see how they actually work - i.e. where is the b-format encoder and decoder objects?
Check out the hoalibrary
You can download it here
I'm still looking for example projects -- I'll update if I find any.
Update 1:
Ambilib
This pd library is sweet. It comes with a bunch of good sample projects in the help folder.
Here's basic 1st order ambisonic panner and decoder objects for an 8 speaker cube configuration. I've also put these objects on GitHub with some examples. The code snippets below should be put into separate .pd files!
Panner:
#N canvas 66 87 448 490 10;
#X obj 32 421 outlet~;
#X obj 141 421 outlet~;
#X obj 244 421 outlet~;
#X obj 324 421 outlet~;
#X obj 27 61 inlet~;
#X obj 32 336 /~ 1.41421;
#X obj 131 61 inlet;
#X obj 304 61 inlet;
#X text 27 37 signal;
#X text 131 37 azimuth (theta);
#X text 304 37 elevation (phi);
#X text 32 446 W;
#X text 141 446 X;
#X text 244 446 Y;
#X text 324 446 Z;
#X obj 134 179 cos;
#X obj 173 179 sin;
#X obj 307 179 cos;
#X obj 336 179 sin;
#X obj 141 336 *~;
#X obj 243 336 *~;
#X obj 324 336 *~;
#X obj 219 64 loadbang;
#X obj 131 87 \$1;
#X obj 304 87 \$2;
#X obj 141 362 *~;
#X obj 243 362 *~;
#X obj 131 123 * 3.14159;
#X obj 304 120 * 1.57079;
#X connect 4 0 5 0;
#X connect 4 0 19 0;
#X connect 4 0 21 0;
#X connect 4 0 20 0;
#X connect 5 0 0 0;
#X connect 6 0 23 0;
#X connect 7 0 24 0;
#X connect 15 0 19 1;
#X connect 16 0 20 1;
#X connect 17 0 25 1;
#X connect 17 0 26 1;
#X connect 18 0 21 1;
#X connect 19 0 25 0;
#X connect 20 0 26 0;
#X connect 21 0 3 0;
#X connect 22 0 23 0;
#X connect 22 0 24 0;
#X connect 23 0 27 0;
#X connect 24 0 28 0;
#X connect 25 0 1 0;
#X connect 26 0 2 0;
#X connect 27 0 15 0;
#X connect 27 0 16 0;
#X connect 28 0 17 0;
#X connect 28 0 18 0;
Decoder:
#N canvas 42 77 788 411 10;
#X obj 199 25 inlet~;
#X obj 303 29 inlet~;
#X obj 415 29 inlet~;
#X obj 538 26 inlet~;
#X text 199 5 W;
#X text 303 9 X;
#X text 415 9 Y;
#X text 538 6 Z;
#X obj 21 333 outlet~;
#X obj 123 333 outlet~;
#X obj 219 331 outlet~;
#X obj 318 331 outlet~;
#X obj 21 177 +~;
#X obj 215 177 -~;
#X obj 404 331 outlet~;
#X obj 506 331 outlet~;
#X obj 602 329 outlet~;
#X obj 701 329 outlet~;
#X text 21 359 LFU;
#X text 123 359 LBU;
#X text 219 357 RBU;
#X text 318 357 RFU;
#X text 404 357 LFD;
#X text 506 357 LBD;
#X text 602 355 RBD;
#X text 701 355 RFD;
#X obj 403 180 +~;
#X obj 600 180 -~;
#X obj 404 220 +~;
#X obj 601 220 -~;
#X obj 21 217 +~;
#X obj 215 217 -~;
#X obj 21 269 +~;
#X obj 122 177 -~;
#X obj 303 56 *~ 0.25;
#X obj 414 58 *~ 0.25;
#X obj 538 56 *~ 0.1768;
#X obj 199 55 *~ 0.1768;
#X obj 124 269 +~;
#X obj 219 269 +~;
#X obj 317 269 +~;
#X obj 404 267 -~;
#X obj 507 267 -~;
#X obj 602 267 -~;
#X obj 700 267 -~;
#X obj 317 217 -~;
#X obj 507 220 +~;
#X obj 695 220 -~;
#X obj 122 217 +~;
#X obj 317 177 +~;
#X obj 506 180 -~;
#X obj 694 180 +~;
#X connect 0 0 37 0;
#X connect 1 0 34 0;
#X connect 2 0 35 0;
#X connect 3 0 36 0;
#X connect 12 0 30 0;
#X connect 13 0 31 0;
#X connect 26 0 28 0;
#X connect 27 0 29 0;
#X connect 28 0 41 0;
#X connect 29 0 43 0;
#X connect 30 0 32 0;
#X connect 31 0 39 0;
#X connect 32 0 8 0;
#X connect 33 0 48 0;
#X connect 34 0 12 1;
#X connect 34 0 13 1;
#X connect 34 0 26 1;
#X connect 34 0 27 1;
#X connect 34 0 33 1;
#X connect 34 0 49 1;
#X connect 34 0 50 1;
#X connect 34 0 51 1;
#X connect 35 0 30 1;
#X connect 35 0 31 1;
#X connect 35 0 28 1;
#X connect 35 0 29 1;
#X connect 35 0 45 1;
#X connect 35 0 46 1;
#X connect 35 0 47 1;
#X connect 35 0 48 1;
#X connect 36 0 32 1;
#X connect 36 0 38 1;
#X connect 36 0 39 1;
#X connect 36 0 40 1;
#X connect 36 0 41 1;
#X connect 36 0 42 1;
#X connect 36 0 43 1;
#X connect 36 0 44 1;
#X connect 37 0 12 0;
#X connect 37 0 13 0;
#X connect 37 0 26 0;
#X connect 37 0 27 0;
#X connect 37 0 33 0;
#X connect 37 0 49 0;
#X connect 37 0 50 0;
#X connect 37 0 51 0;
#X connect 38 0 9 0;
#X connect 39 0 10 0;
#X connect 40 0 11 0;
#X connect 41 0 14 0;
#X connect 42 0 15 0;
#X connect 43 0 16 0;
#X connect 44 0 17 0;
#X connect 45 0 40 0;
#X connect 46 0 42 0;
#X connect 47 0 44 0;
#X connect 48 0 38 0;
#X connect 49 0 45 0;
#X connect 50 0 46 0;
#X connect 51 0 47 0;
There's helpful discussions about making ambisonic decoders in this paper:
Heller, Aaron, Richard Lee, and Eric Benjamin. "Is my decoder ambisonic?." Audio Engineering Society Convention 125. Audio Engineering Society, 2008.
APA
I've put the code from that paper ("Is My Decoder...") and a number of newer design techniques into a MATLAB/Octave toolbox. The toolbox writes out ambisonic decoders in the Faust DSP specification language, which can then be compiled to Pd externals (and many other plugin formats, like VST, Max/MSP, LV2, ...). The code is in a git repo at
https://bitbucket.org/ambidecodertoolbox/adt. I'm sorry that there are no simple-to-follow instructions for the code, but feel free to contact me with questions. The toolbox is described in our LAC2014 paper.

Construct matrix according to the arrangement in another matrix

I have a matrix 'eff_tot' with dimension (m x n) which I want to rearrange according to a matrix called 'matches' (e.g. [n2 n3; n4 n5]) and put all the collumns not specified in 'matches' at the end.
That is, I want to have [eff_tot(:,n2) eff_tot(:,n3) ; eff_tot(:,n4) eff_tot(:,n5) ; eff_tot(:,n1)].
That's all folks!
Taking the example in the first answer, what I would like to have is:
eff_tot =
81 15 45 15 24
44 86 11 14 42
92 63 97 87 5
19 36 1 58 91
27 52 78 55 95
82 41 0 0 0
87 8 0 0 0
9 24 0 0 0
40 13 0 0 0
26 19 0 0 0
Regards.
Create a vector listing the indices of all the columns in eff_tot and then use SETDIFF to determine which columns do not occur in [n2 n3 n4 n5]. These columns are the unmatched ones. Now concatenate the matched and unmatched column indices to create your column-reordered eff_tot matrix.
>> eff_tot = randi(100, 5, 7)
eff_tot =
45 82 81 15 15 41 24
11 87 44 14 86 8 42
97 9 92 87 63 24 5
1 40 19 58 36 13 91
78 26 27 55 52 19 95
>> n2 = 3; n3 = 5; n4 = 2; n5 = 6;
>> missingColumn = setdiff(1:size(eff_tot, 2), [n2 n3 n4 n5])
missingColumn =
1 4 7
>> eff_tot = [eff_tot(:,n2) eff_tot(:,n3) eff_tot(:,missingIndex); eff_tot(:,n4) eff_tot(:,n5) zeros(size(eff_tot, 1), length(missingIndex))];
eff_tot =
81 15 45 15 24
44 86 11 14 42
92 63 97 87 5
19 36 1 58 91
27 52 78 55 95
82 41 0 0 0
87 8 0 0 0
9 24 0 0 0
40 13 0 0 0
26 19 0 0 0

Quantize dct cofficents in matlab

hello i need to perform quantization to dct cofficents for an image, for a block
size of 8*8 pixles in matlab. can you help me with the syntax, thank you.
There is a built-in function in MATLAB for DCT.
You need the signal processing tool box. Type 'ver' (without quotes) in the MATLAB command to see if you have it.
The code:
image = image; % define your image
[m,n] = size(image); % get size of your image
imvector = reshape(image, m*n, 1); % reshape your image to a vector to compute DCT
imdct = dct(imvector); % compute DCT
imagedct = reshape(imdct,m,n); \ reshape result back to original form of your image
There is an example in the help file as well which is very nice:
I = imread('cameraman.tif');
I = im2double(I);
T = dctmtx(8);
dct = #(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blockproc(B,[8 8],#(block_struct) mask .* block_struct.data);
invdct = #(block_struct) T' * block_struct.data * T;
I2 = blockproc(B2,[8 8],invdct);
imshow(I), figure, imshow(I2)
To quantize DCT coefficients, you simply divide each coefficient by a quantization term and round to integers. The quantization terms are often unique for each coefficient, and are stored in a quantization matrix.
Wikipedia has a nice example. Here is how to implement that example in Matlab.
coef = [
-415 -33 -58 35 58 -51 -15 -12;
5 -34 49 18 27 1 -5 3;
-46 14 80 -35 -50 19 7 -18;
-53 21 34 -20 2 34 36 12;
9 -2 9 -5 -32 -15 45 37;
-8 15 -16 7 -8 11 4 7;
19 -28 -2 -26 -2 7 -44 -21;
18 25 -12 -44 35 48 -37 -3
];
quant = [
16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99
];
quantCoef = round(coef ./ quant)
quantCoef =
-26 -3 -6 2 2 -1 0 0
0 -3 4 1 1 0 0 0
-3 1 5 -1 -1 0 0 0
-4 1 2 -1 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
clc
clear all
close all
image=imread('Water lilies.jpg');
Q=[8 36 36 36 39 45 52 65;
36 36 36 37 41 47 56 68;
36 36 38 42 47 54 64 78;
36 37 42 50 59 69 81 98;
39 41 47 54 73 89 108 130;
45 47 54 69 89 115 144 178;
53 56 64 81 108 144 190 243;
65 68 78 98 130 178 243 255];
GrayImage=rgb2gray(image);
NewImage=uint8(zeros(size(GrayImage)));
Q=uint32(Q);
for i=1:size(GrayImage,1)/8
for j=1:size(GrayImage,2)/8
block=GrayImage(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j-1)*8)+8);
dct=dct2(block);
dct=uint32(dct);
a=dct./Q;
z=a.*Q;
idct=idct2(z);
NewImage(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j-1)*8)+8)=uint8(idct);
end
end
imwrite(NewImage,'NewImage.jpg');
GrayImage=double(GrayImage);
NewImage=double(NewImage);
MSE=0;
for i=1:size(GrayImage,1)
for j=1:size(GrayImage,2)
d=(GrayImage(i,j)-NewImage(i,j))^2;
MSE=d+MSE;
end
end