Bug 338489 - multiple xcb_put_image calls required to upload "big" images -> client splitting of requests is required
Summary: multiple xcb_put_image calls required to upload "big" images -> client splitt...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: core (show other bugs)
Version: 4.11.10
Platform: Kubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
: 357232 388182 395066 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-08-23 05:24 UTC by Con Kolivas
Modified: 2023-01-19 13:17 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Con Kolivas 2014-08-23 05:24:45 UTC
I have a 4k monitor which acts as two pseudo virtual screens tiled side by side 1920x2160 which acts as a single screen 3840x2160 using the nvidia driver support for MST. This causes great confusion for many applications thanks to incomplete support on xrandr. See the associated discussion here:
http://lists.x.org/archives/xorg-devel/2014-January/039984.html

The problem with ksnapshot in this environment is if a window is maximised to either one virtual screen or the other, or the full desktop display, then taking a new snapshot of "window under cursor" leads to a crash every time, but it takes out the entire of the kde desktop management with all window decorations, the panel, application switching etc. being killed and not restarting. I have attempted to deploy the crash reporter but it complains about lack of debugging symbols and when I choose to install debugging symbols it says none can be found. I am on kubuntu 14.04

Reproducible: Always

Steps to Reproduce:
1.Maximised window on 4k display
2.Choose capture mode "window under cursor"
3.Select maximised window
Actual Results:  
Crash. I have to kill the X server afterwards to recreate a working desktop environment again.

Expected Results:  
Normal window snapshot.

Relevant package versions installed:

ii  kde-window-manager                          4:4.11.10-0ubuntu0.1                   amd64        K window manager (KWin)
ii  kdelibs5-data                               4:4.13.3-0ubuntu0.1                    all          core shared data for all KDE Applications
ii  ksnapshot                                   4:4.13.0-0ubuntu1                      amd64        screen capture tool
Comment 1 Christoph Feck 2014-08-23 10:55:30 UTC
Is the "Screenshot" KWin effect enabled? If yes, does disabling it help to resolve the issue?
Comment 2 Christoph Feck 2014-08-23 10:57:17 UTC
Also, please add backtraces, even if incomplete. Without this information, it is not even clear, which process(es) crash.
Comment 3 Con Kolivas 2014-08-23 11:07:03 UTC
Indeed, disabling kwin effects makes the crash go away. In fact, re-enabling effects afterwards the crash does not return.

Still here is what stacktrace there is from when the crash occurs:

Application: KSnapshot (ksnapshot), signal: Aborted
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[KCrash Handler]
#6  0x00007f6e13a6af89 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#7  0x00007f6e13a6e398 in __GI_abort () at abort.c:89
#8  0x00007f6e141606b5 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007f6e1415e836 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007f6e1415e863 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#11 0x00007f6e1415eaf6 in __cxa_rethrow () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#12 0x00007f6e14580596 in QEventLoop::exec (this=this@entry=0x7fff9a5028c0, flags=...) at kernel/qeventloop.cpp:218
#13 0x00007f6e14585b79 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1225
#14 0x0000000000411471 in ?? ()
#15 0x00007f6e13a55ec5 in __libc_start_main (main=0x410a00, argc=3, argv=0x7fff9a502af8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff9a502ae8) at libc-start.c:287
#16 0x00000000004116c6 in _start ()
Comment 4 Con Kolivas 2014-08-23 11:12:20 UTC
I tested further, and disabling all effects with alt-shift-F12 the crash goes away. Re-enabling all effects the crash does not return.

Logging in cleanly the crash returns. Disabling the ksnapshot effect only, the crash goes away. Re-enabling the ksnapshot effect the crash returns.
Comment 5 Con Kolivas 2014-08-23 11:25:45 UTC
Apologies, I mean the "screenshot" effect.
Comment 6 Thomas Lübking 2014-08-23 12:30:14 UTC
Description and ksnapshot backtrace (that exception is probably thrown by "new") smell like OOM.

The taken snapshot is ~32MB and KWin dumps it into /tmp (for ksnaphot to pick up) which is likely mounted tempfs and probably "too small" (ie. has some "size=10M" parameter) or you're actually running OOM and have no swap device either.

-> what's the output of "grep tmpfs /etc/mtab" and "free" ?
Comment 7 Con Kolivas 2014-08-23 12:33:48 UTC
mount

/dev/sda2 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /sys/firmware/efi/efivars type efivarfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
/dev/sda1 on /boot/efi type vfat (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
/dev/sdb1 on /media/backup type ext4 (rw)

 df

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda2      394850732 193111156 181659244  52% /
none                   4         0         4   0% /sys/fs/cgroup
udev            32835812         4  32835808   1% /dev
tmpfs            6568744      1948   6566796   1% /run
none                5120         0      5120   0% /run/lock
none            32843700      1804  32841896   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/sda1         523248      3428    519820   1% /boot/efi
/dev/sdb1      461360136 243525384 194375888  56% /media/backup

grep tmpfs /etc/mtab

none /sys/fs/cgroup tmpfs rw 0 0
udev /dev devtmpfs rw,mode=0755 0 0
tmpfs /run tmpfs rw,noexec,nosuid,size=10%,mode=0755 0 0
none /run/lock tmpfs rw,noexec,nosuid,nodev,size=5242880 0 0
none /run/shm tmpfs rw,nosuid,nodev 0 0
none /run/user tmpfs rw,noexec,nosuid,nodev,size=104857600,mode=0755 0 0

cat /proc/meminfo 

MemTotal:       65687404 kB
MemFree:        41145856 kB
MemAvailable:   61921180 kB
Buffers:         1176904 kB
Cached:         19515448 kB
SwapCached:            0 kB
Active:          8724932 kB
Inactive:       14744708 kB
Active(anon):    2781884 kB
Inactive(anon):   194480 kB
Active(file):    5943048 kB
Inactive(file): 14550228 kB
Unevictable:          32 kB
Mlocked:              32 kB
SwapTotal:      67046396 kB
SwapFree:       67046396 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:       2777400 kB
Mapped:           810204 kB
Shmem:            199080 kB
Slab:             627908 kB
SReclaimable:     535464 kB
SUnreclaim:        92444 kB
KernelStack:       12880 kB
PageTables:        57276 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    99890096 kB
Committed_AS:    7401088 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      325880 kB
VmallocChunk:   34359405052 kB
HardwareCorrupted:     0 kB
AnonHugePages:    434176 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      660516 kB
DirectMap2M:    12908544 kB
DirectMap1G:    53477376 kB
Comment 8 Thomas Lübking 2014-08-23 12:40:03 UTC
Häh?

$ kde4-config --path tmp
$ realpath `kde4-config --path tmp`
Comment 9 Con Kolivas 2014-08-23 12:45:01 UTC
Häh indeed :D

kde4-config --path tmp
/tmp/kde-con/

realpath `kde4-config --path tmp`
/tmp/kde-con
Comment 10 Thomas Lübking 2014-08-23 13:44:36 UTC
/tmp is apparently on sda2

However, "window under cursor" actually (looked up the code ;-) puts the screenshot as pixmap onto the server and either that or rendering to an texture gets kwin killed (no stack, no log, no message) - ksnapshot might just segfault on trying to resolve the pixmap (that goes with kwin)

I'll debug out the effect to get an idea where it fails, but assume we're hitting a limit or bug in the driver (should be not the texture size, though - i can load 16k² textures)
Comment 11 Thomas Lübking 2014-08-23 18:51:20 UTC
Screenshot::postPaintScreen() exits in m_scheduledScreenshot before kwin gets killed - it must happen later :-\
Comment 12 Martin Flöser 2014-08-25 07:09:49 UTC
I assume we hit a max request size failure for the XPutImage call. I know that Qt splits calls.
Comment 13 Thomas Lübking 2014-08-25 10:34:52 UTC
Seems, I checked and skipping the put prevents the crash (for simplicity, one can just hardcode the screenshot size in the effect)

But it is rather xcb_put_image - XPutImage implicitly split up the data to XMaxRequestSize()

http://tronche.com/gui/x/xlib/display/display-macros.html

   "Xlib automatically breaks data up into multiple protocol requests as necessary for the following functions: XDrawPoints(), XDrawRectangles(), XDrawSegments(), XFillArcs(), XFillRectangles(), and XPutImage()."


In the particular case I'd suggest to just store that image in /tmp as well
Esp. here the to-be-saved filetype is -for now- clear.

-> We could break the interface for 5.1 and store the fullsize PNG and hand ksnapshot only a thumbnail along.


However:
since xcb_put_image is not size-safe, we've to conditionally split uploads.

NB:
w/o the BIG_REQUESTS extension, the max request size is 256kB! w/ it raises to 16MB
Comment 14 Martin Flöser 2014-08-25 10:45:14 UTC
> -> We could break the interface for 5.1 and store the fullsize PNG and hand
> ksnapshot only a thumbnail along.

this would in fact be fine and also a good change for Wayland. But it needs a 
ksnapshot release for Qt 5 - I have code mostly there and should finish it. It 
would also need to have ksnapshot moved to kde-workspace (which is where it 
belongs IMHO) otherwise it would break existing code till the 14.12 release.
Comment 15 Martin Flöser 2015-01-05 15:43:45 UTC
ksnapshot is ported AFAIK so we could change the interaction. My latest idea is to create a pipe from ksnapshot, pass the file descriptor to KWin via DBus and KWin writing into the fd and then closing it.
Comment 16 Thomas Lübking 2015-12-27 22:11:12 UTC
*** Bug 357232 has been marked as a duplicate of this bug. ***
Comment 17 Daniel Miranda 2017-01-02 04:35:53 UTC
I still what I believe is this same issue with Spectacle and KWin in Plasma 5.8.4. Attempting to screenshot a single window crashes both applications.
Comment 18 Vlad Zahorodnii 2019-05-27 14:43:04 UTC
Git commit 67444e36592e78d46b757a6c72be1d50bdae19e6 by Vlad Zagorodniy.
Committed on 27/05/2019 at 14:30.
Pushed by vladz into branch 'Plasma/5.12'.

[effects/screenshot] Upload data to xpixmap in chunks

Summary:
xcb_put_image doesn't handle big images well. Contrary to XPutImage, the
caller must manually split the data in such a way that each xcb_put_image
request doesn't exceed the maximum request length. Not doing so will result
in libxcb shutting down the connection.
Related: bug 388182

Test Plan: Take a screenshot of an active fullscreen client on a 4K monitor.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D21370

M  +70   -10   effects/screenshot/screenshot.cpp

https://commits.kde.org/kwin/67444e36592e78d46b757a6c72be1d50bdae19e6
Comment 19 Vlad Zahorodnii 2019-05-27 14:46:02 UTC
*** Bug 388182 has been marked as a duplicate of this bug. ***
Comment 20 Vlad Zahorodnii 2019-05-27 14:50:59 UTC
Even though 67444e36592 fixed this bug, I think it's still worth to have this bug report open because solution proposed in comment 15 is the right way to go.
Comment 21 Vlad Zahorodnii 2019-07-16 08:49:58 UTC
*** Bug 395066 has been marked as a duplicate of this bug. ***
Comment 22 Vlad Zahorodnii 2023-01-19 13:17:25 UTC
org.kde.KWin.ScreenShot2 uses pipes exclusively.