mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-29 04:45:05 +00:00
beca3ec71f
Existing zram (zcomp) implementation has only one compression stream (buffer and algorithm private part), so in order to prevent data corruption only one write (compress operation) can use this compression stream, forcing all concurrent write operations to wait for stream lock to be released. This patch changes zcomp to keep a compression streams list of user-defined size (via sysfs device attr). Each write operation still exclusively holds compression stream, the difference is that we can have N write operations (depending on size of streams list) executing in parallel. See TEST section later in commit message for performance data. Introduce struct zcomp_strm_multi and a set of functions to manage zcomp_strm stream access. zcomp_strm_multi has a list of idle zcomp_strm structs, spinlock to protect idle list and wait queue, making it possible to perform parallel compressions. The following set of functions added: - zcomp_strm_multi_find()/zcomp_strm_multi_release() find and release a compression stream, implement required locking - zcomp_strm_multi_create()/zcomp_strm_multi_destroy() create and destroy zcomp_strm_multi zcomp ->strm_find() and ->strm_release() callbacks are set during initialisation to zcomp_strm_multi_find()/zcomp_strm_multi_release() correspondingly. Each time zcomp issues a zcomp_strm_multi_find() call, the following set of operations performed: - spin lock strm_lock - if idle list is not empty, remove zcomp_strm from idle list, spin unlock and return zcomp stream pointer to caller - if idle list is empty, current adds itself to wait queue. it will be awaken by zcomp_strm_multi_release() caller. zcomp_strm_multi_release(): - spin lock strm_lock - add zcomp stream to idle list - spin unlock, wake up sleeper Minchan Kim reported that spinlock-based locking scheme has demonstrated a severe perfomance regression for single compression stream case, comparing to mutex-based (see https://lkml.org/lkml/2014/2/18/16) base spinlock mutex ==Initial write ==Initial write ==Initial write records: 5 records: 5 records: 5 avg: 1642424.35 avg: 699610.40 avg: 1655583.71 std: 39890.95(2.43%) std: 232014.19(33.16%) std: 52293.96 max: 1690170.94 max: 1163473.45 max: 1697164.75 min: 1568669.52 min: 573429.88 min: 1553410.23 ==Rewrite ==Rewrite ==Rewrite records: 5 records: 5 records: 5 avg: 1611775.39 avg: 501406.64 avg: 1684419.11 std: 17144.58(1.06%) std: 15354.41(3.06%) std: 18367.42 max: 1641800.95 max: 531356.78 max: 1706445.84 min: 1593515.27 min: 488817.78 min: 1655335.73 When only one compression stream available, mutex with spin on owner tends to perform much better than frequent wait_event()/wake_up(). This is why single stream implemented as a special case with mutex locking. Introduce and document zram device attribute max_comp_streams. This attr shows and stores current zcomp's max number of zcomp streams (max_strm). Extend zcomp's zcomp_create() with `max_strm' parameter. `max_strm' limits the number of zcomp_strm structs in compression backend's idle list (max_comp_streams). max_comp_streams used during initialisation as follows: -- passing to zcomp_create() max_strm equals to 1 will initialise zcomp using single compression stream zcomp_strm_single (mutex-based locking). -- passing to zcomp_create() max_strm greater than 1 will initialise zcomp using multi compression stream zcomp_strm_multi (spinlock-based locking). default max_comp_streams value is 1, meaning that zram with single stream will be initialised. Later patch will introduce configuration knob to change max_comp_streams on already initialised and used zcomp. TEST iozone -t 3 -R -r 16K -s 60M -I +Z test base 1 strm (mutex) 3 strm (spinlock) ----------------------------------------------------------------------- Initial write 589286.78 583518.39 718011.05 Rewrite 604837.97 596776.38 1515125.72 Random write 584120.11 595714.58 1388850.25 Pwrite 535731.17 541117.38 739295.27 Fwrite 1418083.88 1478612.72 1484927.06 Usage example: set max_comp_streams to 4 echo 4 > /sys/block/zram0/max_comp_streams show current max_comp_streams (default value is 1). cat /sys/block/zram0/max_comp_streams Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> |
||
---|---|---|
.. | ||
configfs-spear-pcie-gadget | ||
configfs-usb-gadget | ||
configfs-usb-gadget-acm | ||
configfs-usb-gadget-ecm | ||
configfs-usb-gadget-eem | ||
configfs-usb-gadget-ffs | ||
configfs-usb-gadget-loopback | ||
configfs-usb-gadget-mass-storage | ||
configfs-usb-gadget-ncm | ||
configfs-usb-gadget-obex | ||
configfs-usb-gadget-phonet | ||
configfs-usb-gadget-rndis | ||
configfs-usb-gadget-serial | ||
configfs-usb-gadget-sourcesink | ||
configfs-usb-gadget-subset | ||
debugfs-driver-genwqe | ||
debugfs-ec | ||
debugfs-ideapad | ||
debugfs-olpc | ||
debugfs-pfo-nx-crypto | ||
debugfs-pktcdvd | ||
dev-kmsg | ||
evm | ||
ima_policy | ||
procfs-diskstats | ||
pstore | ||
sysfs-ata | ||
sysfs-block | ||
sysfs-block-bcache | ||
sysfs-block-dm | ||
sysfs-block-rssd | ||
sysfs-block-zram | ||
sysfs-bus-acpi | ||
sysfs-bus-bcma | ||
sysfs-bus-css | ||
sysfs-bus-event_source-devices-events | ||
sysfs-bus-event_source-devices-format | ||
sysfs-bus-event_source-devices-hv_24x7 | ||
sysfs-bus-event_source-devices-hv_gpci | ||
sysfs-bus-fcoe | ||
sysfs-bus-hsi | ||
sysfs-bus-i2c-devices-fsa9480 | ||
sysfs-bus-i2c-devices-hm6352 | ||
sysfs-bus-i2c-devices-lm3533 | ||
sysfs-bus-iio | ||
sysfs-bus-iio-frequency-ad9523 | ||
sysfs-bus-iio-frequency-adf4350 | ||
sysfs-bus-iio-light-lm3533-als | ||
sysfs-bus-iio-mpu6050 | ||
sysfs-bus-mdio | ||
sysfs-bus-media | ||
sysfs-bus-mei | ||
sysfs-bus-pci | ||
sysfs-bus-pci-devices-cciss | ||
sysfs-bus-pci-drivers-ehci_hcd | ||
sysfs-bus-rbd | ||
sysfs-bus-rpmsg | ||
sysfs-bus-umc | ||
sysfs-bus-usb | ||
sysfs-bus-usb-devices-usbsevseg | ||
sysfs-c2port | ||
sysfs-cfq-target-latency | ||
sysfs-class | ||
sysfs-class-backlight-driver-adp8870 | ||
sysfs-class-backlight-driver-lm3533 | ||
sysfs-class-bdi | ||
sysfs-class-devfreq | ||
sysfs-class-extcon | ||
sysfs-class-lcd | ||
sysfs-class-led | ||
sysfs-class-led-driver-lm3533 | ||
sysfs-class-mic.txt | ||
sysfs-class-mtd | ||
sysfs-class-net | ||
sysfs-class-net-batman-adv | ||
sysfs-class-net-grcan | ||
sysfs-class-net-mesh | ||
sysfs-class-pktcdvd | ||
sysfs-class-power | ||
sysfs-class-powercap | ||
sysfs-class-pwm | ||
sysfs-class-rc | ||
sysfs-class-regulator | ||
sysfs-class-rtc-rtc0-device-rtc_calibration | ||
sysfs-class-scsi_host | ||
sysfs-class-uwb_rc | ||
sysfs-class-uwb_rc-wusbhc | ||
sysfs-dev | ||
sysfs-devices | ||
sysfs-devices-edac | ||
sysfs-devices-firmware_node | ||
sysfs-devices-lpss_ltr | ||
sysfs-devices-memory | ||
sysfs-devices-mmc | ||
sysfs-devices-online | ||
sysfs-devices-platform-_UDC_-gadget | ||
sysfs-devices-platform-docg3 | ||
sysfs-devices-platform-sh_mobile_lcdc_fb | ||
sysfs-devices-power | ||
sysfs-devices-power_resources_D0 | ||
sysfs-devices-power_resources_D1 | ||
sysfs-devices-power_resources_D2 | ||
sysfs-devices-power_resources_D3hot | ||
sysfs-devices-power_resources_wakeup | ||
sysfs-devices-power_state | ||
sysfs-devices-real_power_state | ||
sysfs-devices-resource_in_use | ||
sysfs-devices-soc | ||
sysfs-devices-sun | ||
sysfs-devices-system-cpu | ||
sysfs-devices-system-ibm-rtl | ||
sysfs-devices-system-xen_cpu | ||
sysfs-driver-genwqe | ||
sysfs-driver-hid | ||
sysfs-driver-hid-lenovo-tpkbd | ||
sysfs-driver-hid-logitech-lg4ff | ||
sysfs-driver-hid-multitouch | ||
sysfs-driver-hid-picolcd | ||
sysfs-driver-hid-prodikeys | ||
sysfs-driver-hid-roccat-arvo | ||
sysfs-driver-hid-roccat-isku | ||
sysfs-driver-hid-roccat-kone | ||
sysfs-driver-hid-roccat-koneplus | ||
sysfs-driver-hid-roccat-konepure | ||
sysfs-driver-hid-roccat-kovaplus | ||
sysfs-driver-hid-roccat-lua | ||
sysfs-driver-hid-roccat-pyra | ||
sysfs-driver-hid-roccat-ryos | ||
sysfs-driver-hid-roccat-savu | ||
sysfs-driver-hid-srws1 | ||
sysfs-driver-hid-thingm | ||
sysfs-driver-hid-wiimote | ||
sysfs-driver-intel-rapid-start | ||
sysfs-driver-ppi | ||
sysfs-driver-samsung-laptop | ||
sysfs-driver-sunxi-sid | ||
sysfs-driver-wacom | ||
sysfs-driver-xen-blkback | ||
sysfs-driver-xen-blkfront | ||
sysfs-firmware-acpi | ||
sysfs-firmware-dmi | ||
sysfs-firmware-efi | ||
sysfs-firmware-efi-runtime-map | ||
sysfs-firmware-gsmi | ||
sysfs-firmware-log | ||
sysfs-firmware-memmap | ||
sysfs-firmware-ofw | ||
sysfs-firmware-sfi | ||
sysfs-firmware-sgi_uv | ||
sysfs-fs-ext4 | ||
sysfs-fs-f2fs | ||
sysfs-gpio | ||
sysfs-i2c-bmp085 | ||
sysfs-ibft | ||
sysfs-kernel-boot_params | ||
sysfs-kernel-fscaps | ||
sysfs-kernel-iommu_groups | ||
sysfs-kernel-mm | ||
sysfs-kernel-mm-hugepages | ||
sysfs-kernel-mm-ksm | ||
sysfs-kernel-slab | ||
sysfs-kernel-uids | ||
sysfs-kernel-vmcoreinfo | ||
sysfs-memory-page-offline | ||
sysfs-module | ||
sysfs-ocfs2 | ||
sysfs-platform-asus-laptop | ||
sysfs-platform-asus-wmi | ||
sysfs-platform-at91 | ||
sysfs-platform-eeepc-laptop | ||
sysfs-platform-ideapad-laptop | ||
sysfs-platform-kim | ||
sysfs-platform-msi-laptop | ||
sysfs-platform-tahvo-usb | ||
sysfs-platform-ts5500 | ||
sysfs-power | ||
sysfs-pps | ||
sysfs-profiling | ||
sysfs-ptp | ||
sysfs-tty | ||
sysfs-wusb_cbaf |