Changes in 5.15.3
xhci: Fix USB 3.1 enumeration issues by increasing roothub power-on-good delay
usb: xhci: Enable runtime-pm by default on AMD Yellow Carp platform
Input: iforce - fix control-message timeout
Input: elantench - fix misreporting trackpoint coordinates
Input: i8042 - Add quirk for Fujitsu Lifebook T725
libata: fix read log timeout value
ocfs2: fix data corruption on truncate
scsi: scsi_ioctl: Validate command size
scsi: core: Avoid leaving shost->last_reset with stale value if EH does not run
scsi: core: Remove command size deduction from scsi_setup_scsi_cmnd()
scsi: lpfc: Don't release final kref on Fport node while ABTS outstanding
scsi: lpfc: Fix FCP I/O flush functionality for TMF routines
scsi: qla2xxx: Fix crash in NVMe abort path
scsi: qla2xxx: Fix kernel crash when accessing port_speed sysfs file
scsi: qla2xxx: Fix use after free in eh_abort path
ce/gf100: fix incorrect CE0 address calculation on some GPUs
char: xillybus: fix msg_ep UAF in xillyusb_probe()
mmc: mtk-sd: Add wait dma stop done flow
mmc: dw_mmc: Dont wait for DRTO on Write RSP error
exfat: fix incorrect loading of i_blocks for large files
io-wq: remove worker to owner tw dependency
parisc: Fix set_fixmap() on PA1.x CPUs
parisc: Fix ptrace check on syscall return
tpm: Check for integer overflow in tpm2_map_response_body()
firmware/psci: fix application of sizeof to pointer
crypto: s5p-sss - Add error handling in s5p_aes_probe()
media: rkvdec: Do not override sizeimage for output format
media: ite-cir: IR receiver stop working after receive overflow
media: rkvdec: Support dynamic resolution changes
media: ir-kbd-i2c: improve responsiveness of hauppauge zilog receivers
media: v4l2-ioctl: Fix check_ext_ctrls
ALSA: hda/realtek: Fix mic mute LED for the HP Spectre x360 14
ALSA: hda/realtek: Add a quirk for HP OMEN 15 mute LED
ALSA: hda/realtek: Add quirk for Clevo PC70HS
ALSA: hda/realtek: Headset fixup for Clevo NH77HJQ
ALSA: hda/realtek: Add a quirk for Acer Spin SP513-54N
ALSA: hda/realtek: Add quirk for ASUS UX550VE
ALSA: hda/realtek: Add quirk for HP EliteBook 840 G7 mute LED
ALSA: ua101: fix division by zero at probe
ALSA: 6fire: fix control and bulk message timeouts
ALSA: line6: fix control and interrupt message timeouts
ALSA: mixer: oss: Fix racy access to slots
ALSA: mixer: fix deadlock in snd_mixer_oss_set_volume
ALSA: usb-audio: Line6 HX-Stomp XL USB_ID for 48k-fixed quirk
ALSA: usb-audio: Add registration quirk for JBL Quantum 400
ALSA: hda: Free card instance properly at probe errors
ALSA: synth: missing check for possible NULL after the call to kstrdup
ALSA: pci: rme: Fix unaligned buffer addresses
ALSA: PCM: Fix NULL dereference at mmap checks
ALSA: timer: Fix use-after-free problem
ALSA: timer: Unconditionally unlink slave instances, too
Revert "ext4: enforce buffer head state assertion in ext4_da_map_blocks"
ext4: fix lazy initialization next schedule time computation in more granular unit
ext4: ensure enough credits in ext4_ext_shift_path_extents
ext4: refresh the ext4_ext_path struct after dropping i_data_sem.
fuse: fix page stealing
x86/sme: Use #define USE_EARLY_PGTABLE_L5 in mem_encrypt_identity.c
x86/cpu: Fix migration safety with X86_BUG_NULL_SEL
x86/irq: Ensure PI wakeup handler is unregistered before module unload
x86/iopl: Fake iopl(3) CLI/STI usage
btrfs: clear MISSING device status bit in btrfs_close_one_device
btrfs: fix lost error handling when replaying directory deletes
btrfs: call btrfs_check_rw_degradable only if there is a missing device
KVM: x86/mmu: Drop a redundant, broken remote TLB flush
KVM: VMX: Unregister posted interrupt wakeup handler on hardware unsetup
KVM: PPC: Tick accounting should defer vtime accounting 'til after IRQ handling
ia64: kprobes: Fix to pass correct trampoline address to the handler
selinux: fix race condition when computing ocontext SIDs
ipmi:watchdog: Set panic count to proper value on a panic
md/raid1: only allocate write behind bio for WriteMostly device
hwmon: (pmbus/lm25066) Add offset coefficients
regulator: s5m8767: do not use reset value as DVS voltage if GPIO DVS is disabled
regulator: dt-bindings: samsung,s5m8767: correct s5m8767,pmic-buck-default-dvs-idx property
EDAC/sb_edac: Fix top-of-high-memory value for Broadwell/Haswell
mwifiex: fix division by zero in fw download path
ath6kl: fix division by zero in send path
ath6kl: fix control-message timeout
ath10k: fix control-message timeout
ath10k: fix division by zero in send path
PCI: Mark Atheros QCA6174 to avoid bus reset
rtl8187: fix control-message timeouts
evm: mark evm_fixmode as __ro_after_init
ifb: Depend on netfilter alternatively to tc
platform/surface: aggregator_registry: Add support for Surface Laptop Studio
mt76: mt7615: fix skb use-after-free on mac reset
HID: surface-hid: Use correct event registry for managing HID events
HID: surface-hid: Allow driver matching for target ID 1 devices
wcn36xx: Fix HT40 capability for 2Ghz band
wcn36xx: Fix tx_status mechanism
wcn36xx: Fix (QoS) null data frame bitrate/modulation
PM: sleep: Do not let "syscore" devices runtime-suspend during system transitions
mwifiex: Read a PCI register after writing the TX ring write pointer
mwifiex: Try waking the firmware until we get an interrupt
libata: fix checking of DMA state
dma-buf: fix and rework dma_buf_poll v7
wcn36xx: handle connection loss indication
rsi: fix occasional initialisation failure with BT coex
rsi: fix key enabled check causing unwanted encryption for vap_id > 0
rsi: fix rate mask set leading to P2P failure
rsi: Fix module dev_oper_mode parameter description
perf/x86/intel/uncore: Support extra IMC channel on Ice Lake server
perf/x86/intel/uncore: Fix invalid unit check
perf/x86/intel/uncore: Fix Intel ICX IIO event constraints
RDMA/qedr: Fix NULL deref for query_qp on the GSI QP
ASoC: tegra: Set default card name for Trimslice
ASoC: tegra: Restore AC97 support
signal: Remove the bogus sigkill_pending in ptrace_stop
memory: renesas-rpc-if: Correct QSPI data transfer in Manual mode
signal/mips: Update (_save|_restore)_fp_context to fail with -EFAULT
signal: Add SA_IMMUTABLE to ensure forced siganls do not get changed
soc: samsung: exynos-pmu: Fix compilation when nothing selects CONFIG_MFD_CORE
soc: fsl: dpio: replace smp_processor_id with raw_smp_processor_id
soc: fsl: dpio: use the combined functions to protect critical zone
mtd: rawnand: socrates: Keep the driver compatible with on-die ECC engines
mctp: handle the struct sockaddr_mctp padding fields
power: supply: max17042_battery: Prevent int underflow in set_soc_threshold
power: supply: max17042_battery: use VFSOC for capacity when no rsns
iio: core: fix double free in iio_device_unregister_sysfs()
iio: core: check return value when calling dev_set_name()
KVM: arm64: Extract ESR_ELx.EC only
KVM: x86: Fix recording of guest steal time / preempted status
KVM: x86: Add helper to consolidate core logic of SET_CPUID{2} flows
KVM: nVMX: Query current VMCS when determining if MSR bitmaps are in use
KVM: nVMX: Handle dynamic MSR intercept toggling
can: peak_usb: always ask for BERR reporting for PCAN-USB devices
can: mcp251xfd: mcp251xfd_irq(): add missing can_rx_offload_threaded_irq_finish() in case of bus off
can: j1939: j1939_tp_cmd_recv(): ignore abort message in the BAM transport
can: j1939: j1939_can_recv(): ignore messages with invalid source address
can: j1939: j1939_tp_cmd_recv(): check the dst address of TP.CM_BAM
iio: adc: tsc2046: fix scan interval warning
powerpc/85xx: Fix oops when mpc85xx_smp_guts_ids node cannot be found
io_uring: honour zeroes as io-wq worker limits
ring-buffer: Protect ring_buffer_reset() from reentrancy
serial: core: Fix initializing and restoring termios speed
ifb: fix building without CONFIG_NET_CLS_ACT
xen/balloon: add late_initcall_sync() for initial ballooning done
ovl: fix use after free in struct ovl_aio_req
ovl: fix filattr copy-up failure
PCI: pci-bridge-emul: Fix emulation of W1C bits
PCI: cadence: Add cdns_plat_pcie_probe() missing return
cxl/pci: Fix NULL vs ERR_PTR confusion
PCI: aardvark: Do not clear status bits of masked interrupts
PCI: aardvark: Fix checking for link up via LTSSM state
PCI: aardvark: Do not unmask unused interrupts
PCI: aardvark: Fix reporting Data Link Layer Link Active
PCI: aardvark: Fix configuring Reference clock
PCI: aardvark: Fix return value of MSI domain .alloc() method
PCI: aardvark: Read all 16-bits from PCIE_MSI_PAYLOAD_REG
PCI: aardvark: Fix support for bus mastering and PCI_COMMAND on emulated bridge
PCI: aardvark: Fix support for PCI_BRIDGE_CTL_BUS_RESET on emulated bridge
PCI: aardvark: Set PCI Bridge Class Code to PCI Bridge
PCI: aardvark: Fix support for PCI_ROM_ADDRESS1 on emulated bridge
quota: check block number when reading the block in quota file
quota: correct error number in free_dqentry()
cifs: To match file servers, make sure the server hostname matches
cifs: set a minimum of 120s for next dns resolution
mfd: simple-mfd-i2c: Select MFD_CORE to fix build error
pinctrl: core: fix possible memory leak in pinctrl_enable()
coresight: cti: Correct the parameter for pm_runtime_put
coresight: trbe: Fix incorrect access of the sink specific data
coresight: trbe: Defer the probe on offline CPUs
iio: buffer: check return value of kstrdup_const()
iio: buffer: Fix memory leak in iio_buffers_alloc_sysfs_and_mask()
iio: buffer: Fix memory leak in __iio_buffer_alloc_sysfs_and_mask()
iio: buffer: Fix memory leak in iio_buffer_register_legacy_sysfs_groups()
drivers: iio: dac: ad5766: Fix dt property name
iio: dac: ad5446: Fix ad5622_write() return value
iio: ad5770r: make devicetree property reading consistent
Documentation:devicetree:bindings:iio:dac: Fix val
USB: serial: keyspan: fix memleak on probe errors
serial: 8250: fix racy uartclk update
ksmbd: set unique value to volume serial field in FS_VOLUME_INFORMATION
io-wq: serialize hash clear with wakeup
serial: 8250: Fix reporting real baudrate value in c_ospeed field
Revert "serial: 8250: Fix reporting real baudrate value in c_ospeed field"
most: fix control-message timeouts
USB: iowarrior: fix control-message timeouts
USB: chipidea: fix interrupt deadlock
power: supply: max17042_battery: Clear status bits in interrupt handler
component: do not leave master devres group open after bind
dma-buf: WARN on dmabuf release with pending attachments
drm: panel-orientation-quirks: Update the Lenovo Ideapad D330 quirk (v2)
drm: panel-orientation-quirks: Add quirk for KD Kurio Smart C15200 2-in-1
drm: panel-orientation-quirks: Add quirk for the Samsung Galaxy Book 10.6
Bluetooth: sco: Fix lock_sock() blockage by memcpy_from_msg()
Bluetooth: fix use-after-free error in lock_sock_nested()
Bluetooth: call sock_hold earlier in sco_conn_del
drm/panel-orientation-quirks: add Valve Steam Deck
rcutorture: Avoid problematic critical section nesting on PREEMPT_RT
platform/x86: wmi: do not fail if disabling fails
drm/amdgpu: move iommu_resume before ip init/resume
MIPS: lantiq: dma: add small delay after reset
MIPS: lantiq: dma: reset correct number of channel
locking/lockdep: Avoid RCU-induced noinstr fail
net: sched: update default qdisc visibility after Tx queue cnt changes
ACPI: resources: Add DMI-based legacy IRQ override quirk
rcu-tasks: Move RTGS_WAIT_CBS to beginning of rcu_tasks_kthread() loop
smackfs: Fix use-after-free in netlbl_catmap_walk()
ath11k: Align bss_chan_info structure with firmware
crypto: aesni - check walk.nbytes instead of err
x86/mm/64: Improve stack overflow warnings
x86: Increase exception stack sizes
mwifiex: Run SET_BSS_MODE when changing from P2P to STATION vif-type
mwifiex: Properly initialize private structure on interface type changes
spi: Check we have a spi_device_id for each DT compatible
fscrypt: allow 256-bit master keys with AES-256-XTS
drm/amdgpu: Fix MMIO access page fault
drm/amd/display: Fix null pointer dereference for encoders
selftests: net: fib_nexthops: Wait before checking reported idle time
ath11k: Avoid reg rules update during firmware recovery
ath11k: add handler for scan event WMI_SCAN_EVENT_DEQUEUED
ath11k: Change DMA_FROM_DEVICE to DMA_TO_DEVICE when map reinjected packets
ath10k: high latency fixes for beacon buffer
octeontx2-pf: Enable promisc/allmulti match MCAM entries.
media: mt9p031: Fix corrupted frame after restarting stream
media: netup_unidvb: handle interrupt properly according to the firmware
media: atomisp: Fix error handling in probe
media: stm32: Potential NULL pointer dereference in dcmi_irq_thread()
media: uvcvideo: Set capability in s_param
media: uvcvideo: Return -EIO for control errors
media: uvcvideo: Set unique vdev name based in type
media: vidtv: Fix memory leak in remove
media: s5p-mfc: fix possible null-pointer dereference in s5p_mfc_probe()
media: s5p-mfc: Add checking to s5p_mfc_probe().
media: videobuf2: rework vb2_mem_ops API
media: imx: set a media_device bus_info string
media: rcar-vin: Use user provided buffers when starting
media: mceusb: return without resubmitting URB in case of -EPROTO error.
ia64: don't do IA64_CMPXCHG_DEBUG without CONFIG_PRINTK
rtw88: fix RX clock gate setting while fifo dump
brcmfmac: Add DMI nvram filename quirk for Cyberbook T116 tablet
media: rcar-csi2: Add checking to rcsi2_start_receiver()
ipmi: Disable some operations during a panic
fs/proc/uptime.c: Fix idle time reporting in /proc/uptime
kselftests/sched: cleanup the child processes
ACPICA: Avoid evaluating methods too early during system resume
cpufreq: Make policy min/max hard requirements
ice: Move devlink port to PF/VF struct
media: imx-jpeg: Fix possible null pointer dereference
media: ipu3-imgu: imgu_fmt: Handle properly try
media: ipu3-imgu: VIDIOC_QUERYCAP: Fix bus_info
media: usb: dvd-usb: fix uninit-value bug in dibusb_read_eeprom_byte()
net-sysfs: try not to restart the syscall if it will fail eventually
drm/amdkfd: rm BO resv on validation to avoid deadlock
tracefs: Have tracefs directories not set OTH permission bits by default
tracing: Disable "other" permission bits in the tracefs files
ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create()
KVM: arm64: Propagate errors from __pkvm_prot_finalize hypercall
mmc: moxart: Fix reference count leaks in moxart_probe
iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value
ACPI: battery: Accept charges over the design capacity as full
ACPI: scan: Release PM resources blocked by unused objects
drm/amd/display: fix null pointer deref when plugging in display
drm/amdkfd: fix resume error when iommu disabled in Picasso
net: phy: micrel: make *-skew-ps check more lenient
leaking_addresses: Always print a trailing newline
thermal/core: Fix null pointer dereference in thermal_release()
drm/msm: prevent NULL dereference in msm_gpu_crashstate_capture()
thermal/drivers/tsens: Add timeout to get_temp_tsens_valid
block: bump max plugged deferred size from 16 to 32
floppy: fix calling platform_device_unregister() on invalid drives
md: update superblock after changing rdev flags in state_store
memstick: r592: Fix a UAF bug when removing the driver
locking/rwsem: Disable preemption for spinning region
lib/xz: Avoid overlapping memcpy() with invalid input with in-place decompression
lib/xz: Validate the value before assigning it to an enum variable
workqueue: make sysfs of unbound kworker cpumask more clever
tracing/cfi: Fix cmp_entries_* functions signature mismatch
mt76: mt7915: fix an off-by-one bound check
mwl8k: Fix use-after-free in mwl8k_fw_state_machine()
iwlwifi: change all JnP to NO-160 configuration
block: remove inaccurate requeue check
media: allegro: ignore interrupt if mailbox is not initialized
drm/amdgpu/pm: properly handle sclk for profiling modes on vangogh
nvmet: fix use-after-free when a port is removed
nvmet-rdma: fix use-after-free when a port is removed
nvmet-tcp: fix use-after-free when a port is removed
nvme: drop scan_lock and always kick requeue list when removing namespaces
samples/bpf: Fix application of sizeof to pointer
arm64: vdso32: suppress error message for 'make mrproper'
PM: hibernate: Get block device exclusively in swsusp_check()
selftests: kvm: fix mismatched fclose() after popen()
selftests/bpf: Fix perf_buffer test on system with offline cpus
iwlwifi: mvm: disable RX-diversity in powersave
smackfs: use __GFP_NOFAIL for smk_cipso_doi()
ARM: clang: Do not rely on lr register for stacktrace
gre/sit: Don't generate link-local addr if addr_gen_mode is IN6_ADDR_GEN_MODE_NONE
can: bittiming: can_fixup_bittiming(): change type of tseg1 and alltseg to unsigned int
gfs2: Cancel remote delete work asynchronously
gfs2: Fix glock_hash_walk bugs
ARM: 9136/1: ARMv7-M uses BE-8, not BE-32
tools/latency-collector: Use correct size when writing queue_full_warning
vrf: run conntrack only in context of lower/physdev for locally generated packets
net: annotate data-race in neigh_output()
ACPI: AC: Quirk GK45 to skip reading _PSR
ACPI: resources: Add one more Medion model in IRQ override quirk
btrfs: reflink: initialize return value to 0 in btrfs_extent_same()
btrfs: do not take the uuid_mutex in btrfs_rm_device
spi: bcm-qspi: Fix missing clk_disable_unprepare() on error in bcm_qspi_probe()
wcn36xx: Correct band/freq reporting on RX
wcn36xx: Fix packet drop on resume
Revert "wcn36xx: Enable firmware link monitoring"
ftrace: do CPU checking after preemption disabled
inet: remove races in inet{6}_getname()
x86/hyperv: Protect set_hv_tscchange_cb() against getting preempted
drm/amd/display: dcn20_resource_construct reduce scope of FPU enabled
selftests/core: fix conflicting types compile error for close_range()
perf/x86/intel: Fix ICL/SPR INST_RETIRED.PREC_DIST encodings
parisc: fix warning in flush_tlb_all
task_stack: Fix end_of_stack() for architectures with upwards-growing stack
erofs: don't trigger WARN() when decompression fails
parisc/unwind: fix unwinder when CONFIG_64BIT is enabled
parisc/kgdb: add kgdb_roundup() to make kgdb work with idle polling
netfilter: conntrack: set on IPS_ASSURED if flows enters internal stream state
selftests/bpf: Fix strobemeta selftest regression
fbdev/efifb: Release PCI device's runtime PM ref during FB destroy
drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()
perf/x86/intel/uncore: Fix Intel SPR CHA event constraints
perf/x86/intel/uncore: Fix Intel SPR IIO event constraints
perf/x86/intel/uncore: Fix Intel SPR M2PCIE event constraints
perf/x86/intel/uncore: Fix Intel SPR M3UPI event constraints
drm/bridge: it66121: Initialize {device,vendor}_ids
drm/bridge: it66121: Wait for next bridge to be probed
Bluetooth: fix init and cleanup of sco_conn.timeout_work
libbpf: Don't crash on object files with no symbol tables
Bluetooth: hci_uart: fix GPF in h5_recv
rcu: Fix existing exp request check in sync_sched_exp_online_cleanup()
MIPS: lantiq: dma: fix burst length for DEU
x86/xen: Mark cpu_bringup_and_idle() as dead_end_function
objtool: Handle __sanitize_cov*() tail calls
net/mlx5: Publish and unpublish all devlink parameters at once
drm/v3d: fix wait for TMU write combiner flush
crypto: sm4 - Do not change section of ck and sbox
virtio-gpu: fix possible memory allocation failure
lockdep: Let lock_is_held_type() detect recursive read as read
net: net_namespace: Fix undefined member in key_remove_domain()
net: phylink: don't call netif_carrier_off() with NULL netdev
drm: bridge: it66121: Fix return value it66121_probe
spi: Fixed division by zero warning
cgroup: Make rebind_subsystems() disable v2 controllers all at once
wcn36xx: Fix Antenna Diversity Switching
wilc1000: fix possible memory leak in cfg_scan_result()
Bluetooth: btmtkuart: fix a memleak in mtk_hci_wmt_sync
drm/amdgpu: Fix crash on device remove/driver unload
drm/amd/display: Pass display_pipe_params_st as const in DML
drm/amdgpu: move amdgpu_virt_release_full_gpu to fini_early stage
crypto: caam - disable pkc for non-E SoCs
crypto: qat - power up 4xxx device
Bluetooth: hci_h5: Fix (runtime)suspend issues on RTL8723BS HCIs
bnxt_en: Check devlink allocation and registration status
qed: Don't ignore devlink allocation failures
rxrpc: Fix _usecs_to_jiffies() by using usecs_to_jiffies()
mptcp: do not shrink snd_nxt when recovering
fortify: Fix dropped strcpy() compile-time write overflow check
mac80211: twt: don't use potentially unaligned pointer
cfg80211: always free wiphy specific regdomain
net/mlx5: Accept devlink user input after driver initialization complete
net: dsa: rtl8366rb: Fix off-by-one bug
net: dsa: rtl8366: Fix a bug in deleting VLANs
bpf/tests: Fix error in tail call limit tests
ath11k: fix some sleeping in atomic bugs
ath11k: Avoid race during regd updates
ath11k: fix packet drops due to incorrect 6 GHz freq value in rx status
ath11k: Fix memory leak in ath11k_qmi_driver_event_work
gve: DQO: avoid unused variable warnings
ath10k: Fix missing frame timestamp for beacon/probe-resp
ath10k: sdio: Add missing BH locking around napi_schdule()
drm/ttm: stop calling tt_swapin in vm_access
arm64: mm: update max_pfn after memory hotplug
drm/amdgpu: fix warning for overflow check
libbpf: Fix skel_internal.h to set errno on loader retval < 0
media: em28xx: add missing em28xx_close_extension
media: meson-ge2d: Fix rotation parameter changes detection in 'ge2d_s_ctrl()'
media: cxd2880-spi: Fix a null pointer dereference on error handling path
media: ttusb-dec: avoid release of non-acquired mutex
media: dvb-usb: fix ununit-value in az6027_rc_query
media: imx258: Fix getting clock frequency
media: v4l2-ioctl: S_CTRL output the right value
media: mtk-vcodec: venc: fix return value when start_streaming fails
media: TDA1997x: handle short reads of hdmi info frame.
media: mtk-vpu: Fix a resource leak in the error handling path of 'mtk_vpu_probe()'
media: imx-jpeg: Fix the error handling path of 'mxc_jpeg_probe()'
media: i2c: ths8200 needs V4L2_ASYNC
media: sun6i-csi: Allow the video device to be open multiple times
media: radio-wl1273: Avoid card name truncation
media: si470x: Avoid card name truncation
media: tm6000: Avoid card name truncation
media: cx23885: Fix snd_card_free call on null card pointer
media: atmel: fix the ispck initialization
scs: Release kasan vmalloc poison in scs_free process
kprobes: Do not use local variable when creating debugfs file
crypto: ecc - fix CRYPTO_DEFAULT_RNG dependency
drm: fb_helper: fix CONFIG_FB dependency
cpuidle: Fix kobject memory leaks in error paths
media: em28xx: Don't use ops->suspend if it is NULL
ath10k: Don't always treat modem stop events as crashes
ath9k: Fix potential interrupt storm on queue reset
PM: EM: Fix inefficient states detection
x86/insn: Use get_unaligned() instead of memcpy()
EDAC/amd64: Handle three rank interleaving mode
rcu: Always inline rcu_dynticks_task*_{enter,exit}()
rcu: Fix rcu_dynticks_curr_cpu_in_eqs() vs noinstr
netfilter: nft_dynset: relax superfluous check on set updates
media: venus: fix vpp frequency calculation for decoder
media: dvb-frontends: mn88443x: Handle errors of clk_prepare_enable()
crypto: ccree - avoid out-of-range warnings from clang
crypto: qat - detect PFVF collision after ACK
crypto: qat - disregard spurious PFVF interrupts
hwrng: mtk - Force runtime pm ops for sleep ops
ima: fix deadlock when traversing "ima_default_rules".
b43legacy: fix a lower bounds test
b43: fix a lower bounds test
gve: Recover from queue stall due to missed IRQ
gve: Track RX buffer allocation failures
mmc: sdhci-omap: Fix NULL pointer exception if regulator is not configured
mmc: sdhci-omap: Fix context restore
memstick: avoid out-of-range warning
memstick: jmb38x_ms: use appropriate free function in jmb38x_ms_alloc_host()
net, neigh: Fix NTF_EXT_LEARNED in combination with NTF_USE
hwmon: Fix possible memleak in __hwmon_device_register()
hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff
ath10k: fix max antenna gain unit
kernel/sched: Fix sched_fork() access an invalid sched_task_group
net: fealnx: fix build for UML
net: intel: igc_ptp: fix build for UML
net: tulip: winbond-840: fix build for UML
tcp: switch orphan_count to bare per-cpu counters
crypto: octeontx2 - set assoclen in aead_do_fallback()
thermal/core: fix a UAF bug in __thermal_cooling_device_register()
drm/msm/dsi: do not enable irq handler before powering up the host
drm/msm: Fix potential Oops in a6xx_gmu_rpmh_init()
drm/msm: potential error pointer dereference in init()
drm/msm: unlock on error in get_sched_entity()
drm/msm: fix potential NULL dereference in cleanup
drm/msm: uninitialized variable in msm_gem_import()
net: stream: don't purge sk_error_queue in sk_stream_kill_queues()
thermal/drivers/qcom/lmh: make QCOM_LMH depends on QCOM_SCM
mailbox: Remove WARN_ON for async_cb.cb in cmdq_exec_done
media: ivtv: fix build for UML
media: ir_toy: assignment to be16 should be of correct type
mmc: mxs-mmc: disable regulator on error and in the remove function
io-wq: Remove duplicate code in io_workqueue_create()
block: ataflop: fix breakage introduced at blk-mq refactoring
blk-wbt: prevent NULL pointer dereference in wb_timer_fn
platform/x86: thinkpad_acpi: Fix bitwise vs. logical warning
mailbox: mtk-cmdq: Validate alias_id on probe
mailbox: mtk-cmdq: Fix local clock ID usage
ACPI: PM: Turn off unused wakeup power resources
ACPI: PM: Fix sharing of wakeup power resources
drm/amdkfd: Fix an inappropriate error handling in allloc memory of gpu
mt76: mt7921: fix endianness in mt7921_mcu_tx_done_event
mt76: mt7915: fix endianness warning in mt7915_mac_add_txs_skb
mt76: mt7921: fix endianness warning in mt7921_update_txs
mt76: mt7615: fix endianness warning in mt7615_mac_write_txwi
mt76: mt7915: fix info leak in mt7915_mcu_set_pre_cal()
mt76: connac: fix mt76_connac_gtk_rekey_tlv usage
mt76: fix build error implicit enumeration conversion
mt76: mt7921: fix survey-dump reporting
mt76: mt76x02: fix endianness warnings in mt76x02_mac.c
mt76: mt7921: Fix out of order process by invalid event pkt
mt76: mt7915: fix potential overflow of eeprom page index
mt76: mt7915: fix bit fields for HT rate idx
mt76: mt7921: fix dma hang in rmmod
mt76: connac: fix GTK rekey offload failure on WPA mixed mode
mt76: overwrite default reg_ops if necessary
mt76: mt7921: report HE MU radiotap
mt76: mt7921: fix firmware usage of RA info using legacy rates
mt76: mt7921: fix kernel warning from cfg80211_calculate_bitrate
mt76: mt7921: always wake device if necessary in debugfs
mt76: mt7915: fix hwmon temp sensor mem use-after-free
mt76: mt7615: fix hwmon temp sensor mem use-after-free
mt76: mt7915: fix possible infinite loop release semaphore
mt76: mt7921: fix retrying release semaphore without end
mt76: mt7615: fix monitor mode tear down crash
mt76: connac: fix possible NULL pointer dereference in mt76_connac_get_phy_mode_v2
mt76: mt7915: fix sta_rec_wtbl tag len
mt76: mt7915: fix muar_idx in mt7915_mcu_alloc_sta_req()
rsi: stop thread firstly in rsi_91x_init() error handling
mwifiex: Send DELBA requests according to spec
iwlwifi: mvm: reset PM state on unsuccessful resume
iwlwifi: pnvm: don't kmemdup() more than we have
iwlwifi: pnvm: read EFI data only if long enough
net: enetc: unmap DMA in enetc_send_cmd()
phy: micrel: ksz8041nl: do not use power down mode
nbd: Fix use-after-free in pid_show
nvme-rdma: fix error code in nvme_rdma_setup_ctrl
PM: hibernate: fix sparse warnings
clocksource/drivers/timer-ti-dm: Select TIMER_OF
x86/sev: Fix stack type check in vc_switch_off_ist()
drm/msm: Fix potential NULL dereference in DPU SSPP
drm/msm/dsi: fix wrong type in msm_dsi_host
crypto: tcrypt - fix skcipher multi-buffer tests for 1420B blocks
smackfs: use netlbl_cfg_cipsov4_del() for deleting cipso_v4_doi
KVM: selftests: Fix nested SVM tests when built with clang
libbpf: Fix memory leak in btf__dedup()
bpftool: Avoid leaking the JSON writer prepared for program metadata
libbpf: Fix overflow in BTF sanity checks
libbpf: Fix BTF header parsing checks
mt76: mt7615: mt7622: fix ibss and meshpoint
s390/gmap: validate VMA in __gmap_zap()
s390/gmap: don't unconditionally call pte_unmap_unlock() in __gmap_zap()
s390/mm: validate VMA in PGSTE manipulation functions
s390/mm: fix VMA and page table handling code in storage key handling functions
s390/uv: fully validate the VMA before calling follow_page()
KVM: s390: pv: avoid double free of sida page
KVM: s390: pv: avoid stalls for kvm_s390_pv_init_vm
irq: mips: avoid nested irq_enter()
net: dsa: avoid refcount warnings when ->port_{fdb,mdb}_del returns error
ARM: 9142/1: kasan: work around LPAE build warning
ath10k: fix module load regression with iram-recovery feature
block: ataflop: more blk-mq refactoring fixes
blk-cgroup: synchronize blkg creation against policy deactivation
libbpf: Fix off-by-one bug in bpf_core_apply_relo()
tpm: fix Atmel TPM crash caused by too frequent queries
tpm_tis_spi: Add missing SPI ID
libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED()
tcp: don't free a FIN sk_buff in tcp_remove_empty_skb()
tracing: Fix missing trace_boot_init_histograms kstrdup NULL checks
cpufreq: intel_pstate: Fix cpu->pstate.turbo_freq initialization
spi: spi-rpc-if: Check return value of rpcif_sw_init()
samples/kretprobes: Fix return value if register_kretprobe() failed
KVM: s390: Fix handle_sske page fault handling
libertas_tf: Fix possible memory leak in probe and disconnect
libertas: Fix possible memory leak in probe and disconnect
wcn36xx: add proper DMA memory barriers in rx path
wcn36xx: Fix discarded frames due to wrong sequence number
bpf: Avoid races in __bpf_prog_run() for 32bit arches
bpf: Fixes possible race in update_prog_stats() for 32bit arches
wcn36xx: Channel list update before hardware scan
drm/amdgpu: fix a potential memory leak in amdgpu_device_fini_sw()
drm/amdgpu/gmc6: fix DMA mask from 44 to 40 bits
selftests/bpf: Fix fd cleanup in sk_lookup test
selftests/bpf: Fix memory leak in test_ima
sctp: allow IP fragmentation when PLPMTUD enters Error state
sctp: reset probe_timer in sctp_transport_pl_update
sctp: subtract sctphdr len in sctp_transport_pl_hlen
sctp: return true only for pathmtu update in sctp_transport_pl_toobig
net: amd-xgbe: Toggle PLL settings during rate change
ipmi: kcs_bmc: Fix a memory leak in the error handling path of 'kcs_bmc_serio_add_device()'
nfp: fix NULL pointer access when scheduling dim work
nfp: fix potential deadlock when canceling dim work
net: phylink: avoid mvneta warning when setting pause parameters
net: bridge: fix uninitialized variables when BRIDGE_CFM is disabled
selftests: net: bridge: update IGMP/MLD membership interval value
crypto: pcrypt - Delay write to padata->info
selftests/bpf: Fix fclose/pclose mismatch in test_progs
udp6: allow SO_MARK ctrl msg to affect routing
ibmvnic: don't stop queue in xmit
ibmvnic: Process crqs after enabling interrupts
ibmvnic: delay complete()
selftests: mptcp: fix proto type in link_failure tests
skmsg: Lose offset info in sk_psock_skb_ingress
cgroup: Fix rootcg cpu.stat guest double counting
bpf: Fix propagation of bounds from 64-bit min/max into 32-bit and var_off.
bpf: Fix propagation of signed bounds from 64-bit min/max into 32-bit.
of: unittest: fix EXPECT text for gpio hog errors
cpufreq: Fix parameter in parse_perf_domain()
staging: r8188eu: fix memory leak in rtw_set_key
arm64: dts: meson: sm1: add Ethernet PHY reset line for ODROID-C4/HC4
iio: st_sensors: disable regulators after device unregistration
RDMA/rxe: Fix wrong port_cap_flags
ARM: dts: BCM5301X: Fix memory nodes names
arm64: dts: broadcom: bcm4908: Fix UART clock name
clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
scsi: pm80xx: Fix lockup in outbound queue management
scsi: qla2xxx: edif: Use link event to wake up app
scsi: lpfc: Fix NVMe I/O failover to non-optimized path
ARM: s3c: irq-s3c24xx: Fix return value check for s3c24xx_init_intc()
arm64: dts: rockchip: Fix GPU register width for RK3328
ARM: dts: qcom: msm8974: Add xo_board reference clock to DSI0 PHY
RDMA/bnxt_re: Fix query SRQ failure
arm64: dts: ti: k3-j721e-main: Fix "max-virtual-functions" in PCIe EP nodes
arm64: dts: ti: k3-j721e-main: Fix "bus-range" upto 256 bus number for PCIe
arm64: dts: ti: j7200-main: Fix "vendor-id"/"device-id" properties of pcie node
arm64: dts: ti: j7200-main: Fix "bus-range" upto 256 bus number for PCIe
arm64: dts: meson-g12a: Fix the pwm regulator supply properties
arm64: dts: meson-g12b: Fix the pwm regulator supply properties
arm64: dts: meson-sm1: Fix the pwm regulator supply properties
bus: ti-sysc: Fix timekeeping_suspended warning on resume
ARM: dts: at91: tse850: the emac<->phy interface is rmii
arm64: dts: qcom: sc7180: Base dynamic CPU power coefficients in reality
soc: qcom: llcc: Disable MMUHWT retention
arm64: dts: qcom: sc7280: fix display port phy reg property
scsi: dc395: Fix error case unwinding
MIPS: loongson64: make CPU_LOONGSON64 depends on MIPS_FP_SUPPORT
JFS: fix memleak in jfs_mount
pinctrl: renesas: rzg2l: Fix missing port register 21h
ASoC: wcd9335: Use correct version to initialize Class H
arm64: dts: qcom: msm8916: Fix Secondary MI2S bit clock
arm64: dts: renesas: beacon: Fix Ethernet PHY mode
iommu/mediatek: Fix out-of-range warning with clang
arm64: dts: qcom: pm8916: Remove wrong reg-names for rtc@6000
iommu/dma: Fix sync_sg with swiotlb
iommu/dma: Fix arch_sync_dma for map
ALSA: hda: Reduce udelay() at SKL+ position reporting
ALSA: hda: Use position buffer for SKL+ again
ALSA: usb-audio: Fix possible race at sync of urb completions
soundwire: debugfs: use controller id and link_id for debugfs
power: reset: at91-reset: check properly the return value of devm_of_iomap
scsi: ufs: core: Fix ufshcd_probe_hba() prototype to match the definition
scsi: ufs: core: Stop clearing UNIT ATTENTIONS
scsi: megaraid_sas: Fix concurrent access to ISR between IRQ polling and real interrupt
scsi: pm80xx: Fix misleading log statement in pm8001_mpi_get_nvmd_resp()
driver core: Fix possible memory leak in device_link_add()
arm: dts: omap3-gta04a4: accelerometer irq fix
ASoC: SOF: topology: do not power down primary core during topology removal
iio: st_pressure_spi: Add missing entries SPI to device ID table
soc/tegra: Fix an error handling path in tegra_powergate_power_up()
memory: fsl_ifc: fix leak of irq and nand_irq in fsl_ifc_ctrl_probe
clk: at91: check pmc node status before registering syscore ops
powerpc/mem: Fix arch/powerpc/mm/mem.c:53:12: error: no previous prototype for 'create_section_mapping'
video: fbdev: chipsfb: use memset_io() instead of memset()
powerpc: fix unbalanced node refcount in check_kvm_guest()
powerpc/paravirt: correct preempt debug splat in vcpu_is_preempted()
serial: 8250_dw: Drop wrong use of ACPI_PTR()
usb: gadget: hid: fix error code in do_config()
power: supply: rt5033_battery: Change voltage values to µV
power: supply: max17040: fix null-ptr-deref in max17040_probe()
scsi: csiostor: Uninitialized data in csio_ln_vnp_read_cbfn()
RDMA/mlx4: Return missed an error if device doesn't support steering
usb: musb: select GENERIC_PHY instead of depending on it
staging: most: dim2: do not double-register the same device
staging: ks7010: select CRYPTO_HASH/CRYPTO_MICHAEL_MIC
RDMA/core: Set sgtable nents when using ib_dma_virt_map_sg()
dyndbg: make dyndbg a known cli param
powerpc/perf: Fix cycles/instructions as PM_CYC/PM_INST_CMPL in power10
pinctrl: renesas: checker: Fix off-by-one bug in drive register check
ARM: dts: stm32: Reduce DHCOR SPI NOR frequency to 50 MHz
ARM: dts: stm32: fix STUSB1600 Type-C irq level on stm32mp15xx-dkx
ARM: dts: stm32: fix SAI sub nodes register range
ARM: dts: stm32: fix AV96 board SAI2 pin muxing on stm32mp15
ASoC: cs42l42: Always configure both ASP TX channels
ASoC: cs42l42: Correct some register default values
ASoC: cs42l42: Defer probe if request_threaded_irq() returns EPROBE_DEFER
soc: qcom: rpmhpd: Make power_on actually enable the domain
soc: qcom: socinfo: add two missing PMIC IDs
iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask()
usb: typec: STUSB160X should select REGMAP_I2C
iio: adis: do not disabe IRQs in 'adis_init()'
soundwire: bus: stop dereferencing invalid slave pointer
scsi: ufs: ufshcd-pltfrm: Fix memory leak due to probe defer
scsi: lpfc: Wait for successful restart of SLI3 adapter during host sg_reset
serial: imx: fix detach/attach of serial console
usb: dwc2: drd: fix dwc2_force_mode call in dwc2_ovr_init
usb: dwc2: drd: fix dwc2_drd_role_sw_set when clock could be disabled
usb: dwc2: drd: reset current session before setting the new one
powerpc/booke: Disable STRICT_KERNEL_RWX, DEBUG_PAGEALLOC and KFENCE
usb: dwc3: gadget: Skip resizing EP's TX FIFO if already resized
firmware: qcom_scm: Fix error retval in __qcom_scm_is_call_available()
soc: qcom: rpmhpd: fix sm8350_mxc's peer domain
soc: qcom: apr: Add of_node_put() before return
arm64: dts: qcom: pmi8994: Fix "eternal"->"external" typo in WLED node
arm64: dts: qcom: sdm845: Use RPMH_CE_CLK macro directly
arm64: dts: qcom: sdm845: Fix Qualcomm crypto engine bus clock
pinctrl: equilibrium: Fix function addition in multiple groups
ASoC: topology: Fix stub for snd_soc_tplg_component_remove()
phy: qcom-qusb2: Fix a memory leak on probe
phy: ti: gmii-sel: check of_get_address() for failure
phy: qcom-qmp: another fix for the sc8180x PCIe definition
phy: qcom-snps: Correct the FSEL_MASK
phy: Sparx5 Eth SerDes: Fix return value check in sparx5_serdes_probe()
serial: xilinx_uartps: Fix race condition causing stuck TX
clk: at91: sam9x60-pll: use DIV_ROUND_CLOSEST_ULL
clk: at91: clk-master: check if div or pres is zero
clk: at91: clk-master: fix prescaler logic
HID: u2fzero: clarify error check and length calculations
HID: u2fzero: properly handle timeouts in usb_submit_urb
powerpc/nohash: Fix __ptep_set_access_flags() and ptep_set_wrprotect()
powerpc/book3e: Fix set_memory_x() and set_memory_nx()
powerpc/44x/fsp2: add missing of_node_put
powerpc/xmon: fix task state output
ALSA: oxfw: fix functional regression for Mackie Onyx 1640i in v5.14 or later
iommu/dma: Fix incorrect error return on iommu deferred attach
powerpc: Don't provide __kernel_map_pages() without ARCH_SUPPORTS_DEBUG_PAGEALLOC
ASoC: cs42l42: Correct configuring of switch inversion from ts-inv
RDMA/hns: Fix initial arm_st of CQ
RDMA/hns: Modify the value of MAX_LP_MSG_LEN to meet hardware compatibility
ASoC: rsnd: Fix an error handling path in 'rsnd_node_count()'
serial: cpm_uart: Protect udbg definitions by CONFIG_SERIAL_CPM_CONSOLE
virtio_ring: check desc == NULL when using indirect with packed
vdpa/mlx5: Fix clearing of VIRTIO_NET_F_MAC feature bit
mips: cm: Convert to bitfield API to fix out-of-bounds access
power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
RDMA/core: Require the driver to set the IOVA correctly during rereg_mr
apparmor: fix error check
rpmsg: Fix rpmsg_create_ept return when RPMSG config is not defined
mtd: rawnand: intel: Fix potential buffer overflow in probe
nfsd: don't alloc under spinlock in rpc_parse_scope_id
rtc: ds1302: Add SPI ID table
rtc: ds1390: Add SPI ID table
rtc: pcf2123: Add SPI ID table
remoteproc: imx_rproc: Fix TCM io memory type
i2c: i801: Use PCI bus rescan mutex to protect P2SB access
dmaengine: idxd: move out percpu_ref_exit() to ensure it's outside submission
rtc: mcp795: Add SPI ID table
Input: ariel-pwrbutton - add SPI device ID table
i2c: mediatek: fixing the incorrect register offset
NFS: Default change_attr_type to NFS4_CHANGE_TYPE_IS_UNDEFINED
NFS: Don't set NFS_INO_DATA_INVAL_DEFER and NFS_INO_INVALID_DATA
NFS: Ignore the directory size when marking for revalidation
NFS: Fix dentry verifier races
pnfs/flexfiles: Fix misplaced barrier in nfs4_ff_layout_prepare_ds
drm/bridge/lontium-lt9611uxc: fix provided connector suport
drm/plane-helper: fix uninitialized variable reference
PCI: aardvark: Don't spam about PIO Response Status
PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated bridge
opp: Fix return in _opp_add_static_v2()
NFS: Fix deadlocks in nfs_scan_commit_list()
sparc: Add missing "FORCE" target when using if_changed
fs: orangefs: fix error return code of orangefs_revalidate_lookup()
Input: st1232 - increase "wait ready" timeout
drm/bridge: nwl-dsi: Add atomic_get_input_bus_fmts
mtd: spi-nor: hisi-sfc: Remove excessive clk_disable_unprepare()
PCI: uniphier: Serialize INTx masking/unmasking and fix the bit operation
mtd: rawnand: arasan: Prevent an unsupported configuration
mtd: core: don't remove debugfs directory if device is in use
remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
rtc: rv3032: fix error handling in rv3032_clkout_set_rate()
dmaengine: at_xdmac: call at_xdmac_axi_config() on resume path
dmaengine: at_xdmac: fix AT_XDMAC_CC_PERID() macro
dmaengine: stm32-dma: fix stm32_dma_get_max_width
NFS: Fix up commit deadlocks
NFS: Fix an Oops in pnfs_mark_request_commit()
Fix user namespace leak
auxdisplay: img-ascii-lcd: Fix lock-up when displaying empty string
auxdisplay: ht16k33: Connect backlight to fbdev
auxdisplay: ht16k33: Fix frame buffer device blanking
soc: fsl: dpaa2-console: free buffer before returning from dpaa2_console_read
netfilter: nfnetlink_queue: fix OOB when mac header was cleared
dmaengine: dmaengine_desc_callback_valid(): Check for `callback_result`
dmaengine: tegra210-adma: fix pm runtime unbalance
dmanegine: idxd: fix resource free ordering on driver removal
dmaengine: idxd: reconfig device after device reset command
signal/sh: Use force_sig(SIGKILL) instead of do_group_exit(SIGKILL)
m68k: set a default value for MEMORY_RESERVE
watchdog: f71808e_wdt: fix inaccurate report in WDIOC_GETTIMEOUT
ar7: fix kernel builds for compiler test
scsi: target: core: Remove from tmr_list during LUN unlink
scsi: qla2xxx: Relogin during fabric disturbance
scsi: qla2xxx: Fix gnl list corruption
scsi: qla2xxx: Turn off target reset during issue_lip
scsi: qla2xxx: edif: Fix app start fail
scsi: qla2xxx: edif: Fix app start delay
scsi: qla2xxx: edif: Flush stale events and msgs on session down
scsi: qla2xxx: edif: Increase ELS payload
scsi: qla2xxx: edif: Fix EDIF bsg
NFSv4: Fix a regression in nfs_set_open_stateid_locked()
dmaengine: idxd: fix resource leak on dmaengine driver disable
i2c: xlr: Fix a resource leak in the error handling path of 'xlr_i2c_probe()'
gpio: realtek-otto: fix GPIO line IRQ offset
xen-pciback: Fix return in pm_ctrl_init()
nbd: fix max value for 'first_minor'
nbd: fix possible overflow for 'first_minor' in nbd_dev_add()
io-wq: fix max-workers not correctly set on multi-node system
net: davinci_emac: Fix interrupt pacing disable
kselftests/net: add missed icmp.sh test to Makefile
kselftests/net: add missed setup_loopback.sh/setup_veth.sh to Makefile
kselftests/net: add missed SRv6 tests
kselftests/net: add missed vrf_strict_mode_test.sh test to Makefile
kselftests/net: add missed toeplitz.sh/toeplitz_client.sh to Makefile
ethtool: fix ethtool msg len calculation for pause stats
openrisc: fix SMP tlb flush NULL pointer dereference
net: vlan: fix a UAF in vlan_dev_real_dev()
net: dsa: felix: fix broken VLAN-tagged PTP under VLAN-aware bridge
ice: Fix replacing VF hardware MAC to existing MAC filter
ice: Fix not stopping Tx queues for VFs
kdb: Adopt scheduler's task classification
ACPI: PMIC: Fix intel_pmic_regs_handler() read accesses
PCI: j721e: Fix j721e_pcie_probe() error path
nvdimm/btt: do not call del_gendisk() if not needed
scsi: bsg: Fix errno when scsi_bsg_register_queue() fails
scsi: ufs: ufshpb: Use proper power management API
scsi: ufs: core: Fix NULL pointer dereference
scsi: ufs: ufshpb: Properly handle max-single-cmd
selftests: net: properly support IPv6 in GSO GRE test
drm/nouveau/svm: Fix refcount leak bug and missing check against null bug
nvdimm/pmem: cleanup the disk if pmem_release_disk() is yet assigned
block/ataflop: use the blk_cleanup_disk() helper
block/ataflop: add registration bool before calling del_gendisk()
block/ataflop: provide a helper for cleanup up an atari disk
ataflop: remove ataflop_probe_lock mutex
PCI: Do not enable AtomicOps on VFs
cpufreq: intel_pstate: Clear HWP desired on suspend/shutdown and offline
net: phy: fix duplex out of sync problem while changing settings
block: fix device_add_disk() kobject_create_and_add() error handling
drm/ttm: remove ttm_bo_vm_insert_huge()
bonding: Fix a use-after-free problem when bond_sysfs_slave_add() failed
octeontx2-pf: select CONFIG_NET_DEVLINK
ALSA: memalloc: Catch call with NULL snd_dma_buffer pointer
mfd: core: Add missing of_node_put for loop iteration
mfd: cpcap: Add SPI device ID table
mfd: sprd: Add SPI device ID table
mfd: altera-sysmgr: Fix a mistake caused by resource_size conversion
ACPI: PM: Fix device wakeup power reference counting error
libbpf: Fix lookup_and_delete_elem_flags error reporting
selftests/bpf/xdp_redirect_multi: Put the logs to tmp folder
selftests/bpf/xdp_redirect_multi: Use arping to accurate the arp number
selftests/bpf/xdp_redirect_multi: Give tcpdump a chance to terminate cleanly
selftests/bpf/xdp_redirect_multi: Limit the tests in netns
drm: fb_helper: improve CONFIG_FB dependency
Revert "drm/imx: Annotate dma-fence critical section in commit path"
drm/amdgpu/powerplay: fix sysfs_emit/sysfs_emit_at handling
can: etas_es58x: es58x_rx_err_msg(): fix memory leak in error path
can: mcp251xfd: mcp251xfd_chip_start(): fix error handling for mcp251xfd_chip_rx_int_enable()
mm/zsmalloc.c: close race window between zs_pool_dec_isolated() and zs_unregister_migration()
zram: off by one in read_block_state()
perf bpf: Add missing free to bpf_event__print_bpf_prog_info()
llc: fix out-of-bound array index in llc_sk_dev_hash()
nfc: pn533: Fix double free when pn533_fill_fragment_skbs() fails
litex_liteeth: Fix a double free in the remove function
arm64: arm64_ftr_reg->name may not be a human-readable string
arm64: pgtable: make __pte_to_phys/__phys_to_pte_val inline functions
bpf, sockmap: Remove unhash handler for BPF sockmap usage
bpf, sockmap: Fix race in ingress receive verdict with redirect to self
bpf: sockmap, strparser, and tls are reusing qdisc_skb_cb and colliding
bpf, sockmap: sk_skb data_end access incorrect when src_reg = dst_reg
dmaengine: stm32-dma: fix burst in case of unaligned memory address
dmaengine: stm32-dma: avoid 64-bit division in stm32_dma_get_max_width
gve: Fix off by one in gve_tx_timeout()
drm/i915/fb: Fix rounding error in subsampled plane size calculation
init: make unknown command line param message clearer
seq_file: fix passing wrong private data
drm/amdgpu: fix uvd crash on Polaris12 during driver unloading
net: dsa: mv88e6xxx: Don't support >1G speeds on 6191X on ports other than 10
net/sched: sch_taprio: fix undefined behavior in ktime_mono_to_any
net: hns3: fix ROCE base interrupt vector initialization bug
net: hns3: fix pfc packet number incorrect after querying pfc parameters
net: hns3: fix kernel crash when unload VF while it is being reset
net: hns3: allow configure ETS bandwidth of all TCs
net: stmmac: allow a tc-taprio base-time of zero
net: ethernet: ti: cpsw_ale: Fix access to un-initialized memory
net: marvell: mvpp2: Fix wrong SerDes reconfiguration order
vsock: prevent unnecessary refcnt inc for nonblocking connect
net/smc: fix sk_refcnt underflow on linkdown and fallback
cxgb4: fix eeprom len when diagnostics not implemented
selftests/net: udpgso_bench_rx: fix port argument
thermal: int340x: fix build on 32-bit targets
smb3: do not error on fsync when readonly
ARM: 9155/1: fix early early_iounmap()
ARM: 9156/1: drop cc-option fallbacks for architecture selection
parisc: Fix backtrace to always include init funtion names
parisc: Flush kernel data mapping in set_pte_at() when installing pte for user page
MIPS: fix duplicated slashes for Platform file path
MIPS: fix *-pkg builds for loongson2ef platform
MIPS: Fix assembly error from MIPSr2 code used within MIPS_ISA_ARCH_LEVEL
x86/mce: Add errata workaround for Skylake SKX37
PCI/MSI: Move non-mask check back into low level accessors
PCI/MSI: Destroy sysfs before freeing entries
KVM: x86: move guest_pv_has out of user_access section
posix-cpu-timers: Clear task::posix_cputimers_work in copy_process()
irqchip/sifive-plic: Fixup EOI failed when masked
f2fs: should use GFP_NOFS for directory inodes
f2fs: include non-compressed blocks in compr_written_block
f2fs: fix UAF in f2fs_available_free_memory
ceph: fix mdsmap decode when there are MDS's beyond max_mds
erofs: fix unsafe pagevec reuse of hooked pclusters
drm/i915/guc: Fix blocked context accounting
block: Hold invalidate_lock in BLKDISCARD ioctl
block: Hold invalidate_lock in BLKZEROOUT ioctl
block: Hold invalidate_lock in BLKRESETZONE ioctl
ksmbd: Fix buffer length check in fsctl_validate_negotiate_info()
ksmbd: don't need 8byte alignment for request length in ksmbd_check_message
dmaengine: ti: k3-udma: Set bchan to NULL if a channel request fail
dmaengine: ti: k3-udma: Set r/tchan or rflow to NULL if request fail
dmaengine: bestcomm: fix system boot lockups
net, neigh: Enable state migration between NUD_PERMANENT and NTF_USE
9p/net: fix missing error check in p9_check_errors
mm/filemap.c: remove bogus VM_BUG_ON
memcg: prohibit unconditional exceeding the limit of dying tasks
mm, oom: pagefault_out_of_memory: don't force global OOM for dying tasks
mm, oom: do not trigger out_of_memory from the #PF
mm, thp: lock filemap when truncating page cache
mm, thp: fix incorrect unmap behavior for private pages
mfd: dln2: Add cell for initializing DLN2 ADC
video: backlight: Drop maximum brightness override for brightness zero
bcache: fix use-after-free problem in bcache_device_free()
bcache: Revert "bcache: use bvec_virt"
PM: sleep: Avoid calling put_device() under dpm_list_mtx
s390/cpumf: cpum_cf PMU displays invalid value after hotplug remove
s390/cio: check the subchannel validity for dev_busid
s390/tape: fix timer initialization in tape_std_assign()
s390/ap: Fix hanging ioctl caused by orphaned replies
s390/cio: make ccw_device_dma_* more robust
remoteproc: elf_loader: Fix loading segment when is_iomem true
remoteproc: Fix the wrong default value of is_iomem
remoteproc: imx_rproc: Fix ignoring mapping vdev regions
remoteproc: imx_rproc: Fix rsc-table name
mtd: rawnand: fsmc: Fix use of SM ORDER
mtd: rawnand: ams-delta: Keep the driver compatible with on-die ECC engines
mtd: rawnand: xway: Keep the driver compatible with on-die ECC engines
mtd: rawnand: mpc5121: Keep the driver compatible with on-die ECC engines
mtd: rawnand: gpio: Keep the driver compatible with on-die ECC engines
mtd: rawnand: pasemi: Keep the driver compatible with on-die ECC engines
mtd: rawnand: orion: Keep the driver compatible with on-die ECC engines
mtd: rawnand: plat_nand: Keep the driver compatible with on-die ECC engines
mtd: rawnand: au1550nd: Keep the driver compatible with on-die ECC engines
powerpc/vas: Fix potential NULL pointer dereference
powerpc/bpf: Fix write protecting JIT code
powerpc/32e: Ignore ESR in instruction storage interrupt handler
powerpc/powernv/prd: Unregister OPAL_MSG_PRD2 notifier during module unload
powerpc/security: Use a mutex for interrupt exit code patching
powerpc/64s/interrupt: Fix check_return_regs_valid() false positive
powerpc/pseries/mobility: ignore ibm, platform-facilities updates
powerpc/85xx: fix timebase sync issue when CONFIG_HOTPLUG_CPU=n
drm/sun4i: Fix macros in sun8i_csc.h
PCI: Add PCI_EXP_DEVCTL_PAYLOAD_* macros
PCI: aardvark: Fix PCIe Max Payload Size setting
SUNRPC: Partial revert of commit 6f9f17287e
drm/amd/display: Look at firmware version to determine using dmub on dcn21
media: vidtv: move kfree(dvb) to vidtv_bridge_dev_release()
cifs: fix memory leak of smb3_fs_context_dup::server_hostname
ath10k: fix invalid dma_addr_t token assignment
mmc: moxart: Fix null pointer dereference on pointer host
selftests/x86/iopl: Adjust to the faked iopl CLI/STI usage
selftests/bpf: Fix also no-alu32 strobemeta selftest
arch/cc: Introduce a function to check for confidential computing features
x86/sev: Add an x86 version of cc_platform_has()
x86/sev: Make the #VC exception stacks part of the default stacks storage
media: videobuf2: always set buffer vb2 pointer
media: videobuf2-dma-sg: Fix buf->vb NULL pointer dereference
Linux 5.15.3
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I09574eb6b4fbe930bd13f932cc618846972fcc27
2546 lines
61 KiB
C
2546 lines
61 KiB
C
/*
|
|
* zsmalloc memory allocator
|
|
*
|
|
* Copyright (C) 2011 Nitin Gupta
|
|
* Copyright (C) 2012, 2013 Minchan Kim
|
|
*
|
|
* This code is released using a dual license strategy: BSD/GPL
|
|
* You can choose the license that better fits your requirements.
|
|
*
|
|
* Released under the terms of 3-clause BSD License
|
|
* Released under the terms of GNU General Public License Version 2.0
|
|
*/
|
|
|
|
/*
|
|
* Following is how we use various fields and flags of underlying
|
|
* struct page(s) to form a zspage.
|
|
*
|
|
* Usage of struct page fields:
|
|
* page->private: points to zspage
|
|
* page->freelist(index): links together all component pages of a zspage
|
|
* For the huge page, this is always 0, so we use this field
|
|
* to store handle.
|
|
* page->units: first object offset in a subpage of zspage
|
|
*
|
|
* Usage of struct page flags:
|
|
* PG_private: identifies the first component page
|
|
* PG_owner_priv_1: identifies the huge component page
|
|
*
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/magic.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/string.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/pgtable.h>
|
|
#include <asm/tlbflush.h>
|
|
#include <linux/cpumask.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/preempt.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/shrinker.h>
|
|
#include <linux/types.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/zsmalloc.h>
|
|
#include <linux/zpool.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/pseudo_fs.h>
|
|
#include <linux/migrate.h>
|
|
#include <linux/wait.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/fs.h>
|
|
|
|
#define ZSPAGE_MAGIC 0x58
|
|
|
|
/*
|
|
* This must be power of 2 and greater than or equal to sizeof(link_free).
|
|
* These two conditions ensure that any 'struct link_free' itself doesn't
|
|
* span more than 1 page which avoids complex case of mapping 2 pages simply
|
|
* to restore link_free pointer values.
|
|
*/
|
|
#define ZS_ALIGN 8
|
|
|
|
/*
|
|
* A single 'zspage' is composed of up to 2^N discontiguous 0-order (single)
|
|
* pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N.
|
|
*/
|
|
#define ZS_MAX_ZSPAGE_ORDER 2
|
|
#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
|
|
|
|
#define ZS_HANDLE_SIZE (sizeof(unsigned long))
|
|
|
|
/*
|
|
* Object location (<PFN>, <obj_idx>) is encoded as
|
|
* a single (unsigned long) handle value.
|
|
*
|
|
* Note that object index <obj_idx> starts from 0.
|
|
*
|
|
* This is made more complicated by various memory models and PAE.
|
|
*/
|
|
|
|
#ifndef MAX_POSSIBLE_PHYSMEM_BITS
|
|
#ifdef MAX_PHYSMEM_BITS
|
|
#define MAX_POSSIBLE_PHYSMEM_BITS MAX_PHYSMEM_BITS
|
|
#else
|
|
/*
|
|
* If this definition of MAX_PHYSMEM_BITS is used, OBJ_INDEX_BITS will just
|
|
* be PAGE_SHIFT
|
|
*/
|
|
#define MAX_POSSIBLE_PHYSMEM_BITS BITS_PER_LONG
|
|
#endif
|
|
#endif
|
|
|
|
#define _PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT)
|
|
|
|
/*
|
|
* Memory for allocating for handle keeps object position by
|
|
* encoding <page, obj_idx> and the encoded value has a room
|
|
* in least bit(ie, look at obj_to_location).
|
|
* We use the bit to synchronize between object access by
|
|
* user and migration.
|
|
*/
|
|
#define HANDLE_PIN_BIT 0
|
|
|
|
/*
|
|
* Head in allocated object should have OBJ_ALLOCATED_TAG
|
|
* to identify the object was allocated or not.
|
|
* It's okay to add the status bit in the least bit because
|
|
* header keeps handle which is 4byte-aligned address so we
|
|
* have room for two bit at least.
|
|
*/
|
|
#define OBJ_ALLOCATED_TAG 1
|
|
#define OBJ_TAG_BITS 1
|
|
#define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS)
|
|
#define OBJ_INDEX_MASK ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
|
|
|
|
#define FULLNESS_BITS 2
|
|
#define CLASS_BITS 8
|
|
#define ISOLATED_BITS 3
|
|
#define MAGIC_VAL_BITS 8
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
|
|
/* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
|
|
#define ZS_MIN_ALLOC_SIZE \
|
|
MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))
|
|
/* each chunk includes extra space to keep handle */
|
|
#define ZS_MAX_ALLOC_SIZE PAGE_SIZE
|
|
|
|
/*
|
|
* On systems with 4K page size, this gives 255 size classes! There is a
|
|
* trader-off here:
|
|
* - Large number of size classes is potentially wasteful as free page are
|
|
* spread across these classes
|
|
* - Small number of size classes causes large internal fragmentation
|
|
* - Probably its better to use specific size classes (empirically
|
|
* determined). NOTE: all those class sizes must be set as multiple of
|
|
* ZS_ALIGN to make sure link_free itself never has to span 2 pages.
|
|
*
|
|
* ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN
|
|
* (reason above)
|
|
*/
|
|
#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> CLASS_BITS)
|
|
#define ZS_SIZE_CLASSES (DIV_ROUND_UP(ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE, \
|
|
ZS_SIZE_CLASS_DELTA) + 1)
|
|
|
|
enum fullness_group {
|
|
ZS_EMPTY,
|
|
ZS_ALMOST_EMPTY,
|
|
ZS_ALMOST_FULL,
|
|
ZS_FULL,
|
|
NR_ZS_FULLNESS,
|
|
};
|
|
|
|
enum zs_stat_type {
|
|
CLASS_EMPTY,
|
|
CLASS_ALMOST_EMPTY,
|
|
CLASS_ALMOST_FULL,
|
|
CLASS_FULL,
|
|
OBJ_ALLOCATED,
|
|
OBJ_USED,
|
|
NR_ZS_STAT_TYPE,
|
|
};
|
|
|
|
struct zs_size_stat {
|
|
unsigned long objs[NR_ZS_STAT_TYPE];
|
|
};
|
|
|
|
#ifdef CONFIG_ZSMALLOC_STAT
|
|
static struct dentry *zs_stat_root;
|
|
#endif
|
|
|
|
#ifdef CONFIG_COMPACTION
|
|
static struct vfsmount *zsmalloc_mnt;
|
|
#endif
|
|
|
|
/*
|
|
* We assign a page to ZS_ALMOST_EMPTY fullness group when:
|
|
* n <= N / f, where
|
|
* n = number of allocated objects
|
|
* N = total number of objects zspage can store
|
|
* f = fullness_threshold_frac
|
|
*
|
|
* Similarly, we assign zspage to:
|
|
* ZS_ALMOST_FULL when n > N / f
|
|
* ZS_EMPTY when n == 0
|
|
* ZS_FULL when n == N
|
|
*
|
|
* (see: fix_fullness_group())
|
|
*/
|
|
static const int fullness_threshold_frac = 4;
|
|
static size_t huge_class_size;
|
|
|
|
struct size_class {
|
|
spinlock_t lock;
|
|
struct list_head fullness_list[NR_ZS_FULLNESS];
|
|
/*
|
|
* Size of objects stored in this class. Must be multiple
|
|
* of ZS_ALIGN.
|
|
*/
|
|
int size;
|
|
int objs_per_zspage;
|
|
/* Number of PAGE_SIZE sized pages to combine to form a 'zspage' */
|
|
int pages_per_zspage;
|
|
|
|
unsigned int index;
|
|
struct zs_size_stat stats;
|
|
};
|
|
|
|
/* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */
|
|
static void SetPageHugeObject(struct page *page)
|
|
{
|
|
SetPageOwnerPriv1(page);
|
|
}
|
|
|
|
static void ClearPageHugeObject(struct page *page)
|
|
{
|
|
ClearPageOwnerPriv1(page);
|
|
}
|
|
|
|
static int PageHugeObject(struct page *page)
|
|
{
|
|
return PageOwnerPriv1(page);
|
|
}
|
|
|
|
/*
|
|
* Placed within free objects to form a singly linked list.
|
|
* For every zspage, zspage->freeobj gives head of this list.
|
|
*
|
|
* This must be power of 2 and less than or equal to ZS_ALIGN
|
|
*/
|
|
struct link_free {
|
|
union {
|
|
/*
|
|
* Free object index;
|
|
* It's valid for non-allocated object
|
|
*/
|
|
unsigned long next;
|
|
/*
|
|
* Handle of allocated object.
|
|
*/
|
|
unsigned long handle;
|
|
};
|
|
};
|
|
|
|
struct zs_pool {
|
|
const char *name;
|
|
|
|
struct size_class *size_class[ZS_SIZE_CLASSES];
|
|
struct kmem_cache *handle_cachep;
|
|
struct kmem_cache *zspage_cachep;
|
|
|
|
atomic_long_t pages_allocated;
|
|
|
|
struct zs_pool_stats stats;
|
|
|
|
/* Compact classes */
|
|
struct shrinker shrinker;
|
|
|
|
#ifdef CONFIG_ZSMALLOC_STAT
|
|
struct dentry *stat_dentry;
|
|
#endif
|
|
#ifdef CONFIG_COMPACTION
|
|
struct inode *inode;
|
|
struct work_struct free_work;
|
|
/* A wait queue for when migration races with async_free_zspage() */
|
|
struct wait_queue_head migration_wait;
|
|
atomic_long_t isolated_pages;
|
|
bool destroying;
|
|
#endif
|
|
};
|
|
|
|
struct zspage {
|
|
struct {
|
|
unsigned int fullness:FULLNESS_BITS;
|
|
unsigned int class:CLASS_BITS + 1;
|
|
unsigned int isolated:ISOLATED_BITS;
|
|
unsigned int magic:MAGIC_VAL_BITS;
|
|
};
|
|
unsigned int inuse;
|
|
unsigned int freeobj;
|
|
struct page *first_page;
|
|
struct list_head list; /* fullness list */
|
|
#ifdef CONFIG_COMPACTION
|
|
rwlock_t lock;
|
|
#endif
|
|
};
|
|
|
|
struct mapping_area {
|
|
char *vm_buf; /* copy buffer for objects that span pages */
|
|
char *vm_addr; /* address of kmap_atomic()'ed pages */
|
|
enum zs_mapmode vm_mm; /* mapping mode */
|
|
};
|
|
|
|
#ifdef CONFIG_COMPACTION
|
|
static int zs_register_migration(struct zs_pool *pool);
|
|
static void zs_unregister_migration(struct zs_pool *pool);
|
|
static void migrate_lock_init(struct zspage *zspage);
|
|
static void migrate_read_lock(struct zspage *zspage);
|
|
static void migrate_read_unlock(struct zspage *zspage);
|
|
static void kick_deferred_free(struct zs_pool *pool);
|
|
static void init_deferred_free(struct zs_pool *pool);
|
|
static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage);
|
|
#else
|
|
static int zsmalloc_mount(void) { return 0; }
|
|
static void zsmalloc_unmount(void) {}
|
|
static int zs_register_migration(struct zs_pool *pool) { return 0; }
|
|
static void zs_unregister_migration(struct zs_pool *pool) {}
|
|
static void migrate_lock_init(struct zspage *zspage) {}
|
|
static void migrate_read_lock(struct zspage *zspage) {}
|
|
static void migrate_read_unlock(struct zspage *zspage) {}
|
|
static void kick_deferred_free(struct zs_pool *pool) {}
|
|
static void init_deferred_free(struct zs_pool *pool) {}
|
|
static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {}
|
|
#endif
|
|
|
|
static int create_cache(struct zs_pool *pool)
|
|
{
|
|
pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,
|
|
0, 0, NULL);
|
|
if (!pool->handle_cachep)
|
|
return 1;
|
|
|
|
pool->zspage_cachep = kmem_cache_create("zspage", sizeof(struct zspage),
|
|
0, 0, NULL);
|
|
if (!pool->zspage_cachep) {
|
|
kmem_cache_destroy(pool->handle_cachep);
|
|
pool->handle_cachep = NULL;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void destroy_cache(struct zs_pool *pool)
|
|
{
|
|
kmem_cache_destroy(pool->handle_cachep);
|
|
kmem_cache_destroy(pool->zspage_cachep);
|
|
}
|
|
|
|
static unsigned long cache_alloc_handle(struct zs_pool *pool, gfp_t gfp)
|
|
{
|
|
return (unsigned long)kmem_cache_alloc(pool->handle_cachep,
|
|
gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE|__GFP_CMA));
|
|
}
|
|
|
|
static void cache_free_handle(struct zs_pool *pool, unsigned long handle)
|
|
{
|
|
kmem_cache_free(pool->handle_cachep, (void *)handle);
|
|
}
|
|
|
|
static struct zspage *cache_alloc_zspage(struct zs_pool *pool, gfp_t flags)
|
|
{
|
|
return kmem_cache_zalloc(pool->zspage_cachep,
|
|
flags & ~(__GFP_HIGHMEM|__GFP_MOVABLE|__GFP_CMA));
|
|
}
|
|
|
|
static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage)
|
|
{
|
|
kmem_cache_free(pool->zspage_cachep, zspage);
|
|
}
|
|
|
|
static void record_obj(unsigned long handle, unsigned long obj)
|
|
{
|
|
/*
|
|
* lsb of @obj represents handle lock while other bits
|
|
* represent object value the handle is pointing so
|
|
* updating shouldn't do store tearing.
|
|
*/
|
|
WRITE_ONCE(*(unsigned long *)handle, obj);
|
|
}
|
|
|
|
/* zpool driver */
|
|
|
|
#ifdef CONFIG_ZPOOL
|
|
|
|
static void *zs_zpool_create(const char *name, gfp_t gfp,
|
|
const struct zpool_ops *zpool_ops,
|
|
struct zpool *zpool)
|
|
{
|
|
/*
|
|
* Ignore global gfp flags: zs_malloc() may be invoked from
|
|
* different contexts and its caller must provide a valid
|
|
* gfp mask.
|
|
*/
|
|
return zs_create_pool(name);
|
|
}
|
|
|
|
static void zs_zpool_destroy(void *pool)
|
|
{
|
|
zs_destroy_pool(pool);
|
|
}
|
|
|
|
static int zs_zpool_malloc(void *pool, size_t size, gfp_t gfp,
|
|
unsigned long *handle)
|
|
{
|
|
*handle = zs_malloc(pool, size, gfp);
|
|
return *handle ? 0 : -1;
|
|
}
|
|
static void zs_zpool_free(void *pool, unsigned long handle)
|
|
{
|
|
zs_free(pool, handle);
|
|
}
|
|
|
|
static void *zs_zpool_map(void *pool, unsigned long handle,
|
|
enum zpool_mapmode mm)
|
|
{
|
|
enum zs_mapmode zs_mm;
|
|
|
|
switch (mm) {
|
|
case ZPOOL_MM_RO:
|
|
zs_mm = ZS_MM_RO;
|
|
break;
|
|
case ZPOOL_MM_WO:
|
|
zs_mm = ZS_MM_WO;
|
|
break;
|
|
case ZPOOL_MM_RW:
|
|
default:
|
|
zs_mm = ZS_MM_RW;
|
|
break;
|
|
}
|
|
|
|
return zs_map_object(pool, handle, zs_mm);
|
|
}
|
|
static void zs_zpool_unmap(void *pool, unsigned long handle)
|
|
{
|
|
zs_unmap_object(pool, handle);
|
|
}
|
|
|
|
static u64 zs_zpool_total_size(void *pool)
|
|
{
|
|
return zs_get_total_pages(pool) << PAGE_SHIFT;
|
|
}
|
|
|
|
static struct zpool_driver zs_zpool_driver = {
|
|
.type = "zsmalloc",
|
|
.owner = THIS_MODULE,
|
|
.create = zs_zpool_create,
|
|
.destroy = zs_zpool_destroy,
|
|
.malloc_support_movable = true,
|
|
.malloc = zs_zpool_malloc,
|
|
.free = zs_zpool_free,
|
|
.map = zs_zpool_map,
|
|
.unmap = zs_zpool_unmap,
|
|
.total_size = zs_zpool_total_size,
|
|
};
|
|
|
|
MODULE_ALIAS("zpool-zsmalloc");
|
|
#endif /* CONFIG_ZPOOL */
|
|
|
|
/* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
|
|
static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
|
|
|
|
static bool is_zspage_isolated(struct zspage *zspage)
|
|
{
|
|
return zspage->isolated;
|
|
}
|
|
|
|
static __maybe_unused int is_first_page(struct page *page)
|
|
{
|
|
return PagePrivate(page);
|
|
}
|
|
|
|
/* Protected by class->lock */
|
|
static inline int get_zspage_inuse(struct zspage *zspage)
|
|
{
|
|
return zspage->inuse;
|
|
}
|
|
|
|
|
|
static inline void mod_zspage_inuse(struct zspage *zspage, int val)
|
|
{
|
|
zspage->inuse += val;
|
|
}
|
|
|
|
static inline struct page *get_first_page(struct zspage *zspage)
|
|
{
|
|
struct page *first_page = zspage->first_page;
|
|
|
|
VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
|
|
return first_page;
|
|
}
|
|
|
|
static inline int get_first_obj_offset(struct page *page)
|
|
{
|
|
return page->units;
|
|
}
|
|
|
|
static inline void set_first_obj_offset(struct page *page, int offset)
|
|
{
|
|
page->units = offset;
|
|
}
|
|
|
|
static inline unsigned int get_freeobj(struct zspage *zspage)
|
|
{
|
|
return zspage->freeobj;
|
|
}
|
|
|
|
static inline void set_freeobj(struct zspage *zspage, unsigned int obj)
|
|
{
|
|
zspage->freeobj = obj;
|
|
}
|
|
|
|
static void get_zspage_mapping(struct zspage *zspage,
|
|
unsigned int *class_idx,
|
|
enum fullness_group *fullness)
|
|
{
|
|
BUG_ON(zspage->magic != ZSPAGE_MAGIC);
|
|
|
|
*fullness = zspage->fullness;
|
|
*class_idx = zspage->class;
|
|
}
|
|
|
|
static void set_zspage_mapping(struct zspage *zspage,
|
|
unsigned int class_idx,
|
|
enum fullness_group fullness)
|
|
{
|
|
zspage->class = class_idx;
|
|
zspage->fullness = fullness;
|
|
}
|
|
|
|
/*
|
|
* zsmalloc divides the pool into various size classes where each
|
|
* class maintains a list of zspages where each zspage is divided
|
|
* into equal sized chunks. Each allocation falls into one of these
|
|
* classes depending on its size. This function returns index of the
|
|
* size class which has chunk size big enough to hold the given size.
|
|
*/
|
|
static int get_size_class_index(int size)
|
|
{
|
|
int idx = 0;
|
|
|
|
if (likely(size > ZS_MIN_ALLOC_SIZE))
|
|
idx = DIV_ROUND_UP(size - ZS_MIN_ALLOC_SIZE,
|
|
ZS_SIZE_CLASS_DELTA);
|
|
|
|
return min_t(int, ZS_SIZE_CLASSES - 1, idx);
|
|
}
|
|
|
|
/* type can be of enum type zs_stat_type or fullness_group */
|
|
static inline void zs_stat_inc(struct size_class *class,
|
|
int type, unsigned long cnt)
|
|
{
|
|
class->stats.objs[type] += cnt;
|
|
}
|
|
|
|
/* type can be of enum type zs_stat_type or fullness_group */
|
|
static inline void zs_stat_dec(struct size_class *class,
|
|
int type, unsigned long cnt)
|
|
{
|
|
class->stats.objs[type] -= cnt;
|
|
}
|
|
|
|
/* type can be of enum type zs_stat_type or fullness_group */
|
|
static inline unsigned long zs_stat_get(struct size_class *class,
|
|
int type)
|
|
{
|
|
return class->stats.objs[type];
|
|
}
|
|
|
|
#ifdef CONFIG_ZSMALLOC_STAT
|
|
|
|
static void __init zs_stat_init(void)
|
|
{
|
|
if (!debugfs_initialized()) {
|
|
pr_warn("debugfs not available, stat dir not created\n");
|
|
return;
|
|
}
|
|
|
|
zs_stat_root = debugfs_create_dir("zsmalloc", NULL);
|
|
}
|
|
|
|
static void __exit zs_stat_exit(void)
|
|
{
|
|
debugfs_remove_recursive(zs_stat_root);
|
|
}
|
|
|
|
static unsigned long zs_can_compact(struct size_class *class);
|
|
|
|
static int zs_stats_size_show(struct seq_file *s, void *v)
|
|
{
|
|
int i;
|
|
struct zs_pool *pool = s->private;
|
|
struct size_class *class;
|
|
int objs_per_zspage;
|
|
unsigned long class_almost_full, class_almost_empty;
|
|
unsigned long obj_allocated, obj_used, pages_used, freeable;
|
|
unsigned long total_class_almost_full = 0, total_class_almost_empty = 0;
|
|
unsigned long total_objs = 0, total_used_objs = 0, total_pages = 0;
|
|
unsigned long total_freeable = 0;
|
|
|
|
seq_printf(s, " %5s %5s %11s %12s %13s %10s %10s %16s %8s\n",
|
|
"class", "size", "almost_full", "almost_empty",
|
|
"obj_allocated", "obj_used", "pages_used",
|
|
"pages_per_zspage", "freeable");
|
|
|
|
for (i = 0; i < ZS_SIZE_CLASSES; i++) {
|
|
class = pool->size_class[i];
|
|
|
|
if (class->index != i)
|
|
continue;
|
|
|
|
spin_lock(&class->lock);
|
|
class_almost_full = zs_stat_get(class, CLASS_ALMOST_FULL);
|
|
class_almost_empty = zs_stat_get(class, CLASS_ALMOST_EMPTY);
|
|
obj_allocated = zs_stat_get(class, OBJ_ALLOCATED);
|
|
obj_used = zs_stat_get(class, OBJ_USED);
|
|
freeable = zs_can_compact(class);
|
|
spin_unlock(&class->lock);
|
|
|
|
objs_per_zspage = class->objs_per_zspage;
|
|
pages_used = obj_allocated / objs_per_zspage *
|
|
class->pages_per_zspage;
|
|
|
|
seq_printf(s, " %5u %5u %11lu %12lu %13lu"
|
|
" %10lu %10lu %16d %8lu\n",
|
|
i, class->size, class_almost_full, class_almost_empty,
|
|
obj_allocated, obj_used, pages_used,
|
|
class->pages_per_zspage, freeable);
|
|
|
|
total_class_almost_full += class_almost_full;
|
|
total_class_almost_empty += class_almost_empty;
|
|
total_objs += obj_allocated;
|
|
total_used_objs += obj_used;
|
|
total_pages += pages_used;
|
|
total_freeable += freeable;
|
|
}
|
|
|
|
seq_puts(s, "\n");
|
|
seq_printf(s, " %5s %5s %11lu %12lu %13lu %10lu %10lu %16s %8lu\n",
|
|
"Total", "", total_class_almost_full,
|
|
total_class_almost_empty, total_objs,
|
|
total_used_objs, total_pages, "", total_freeable);
|
|
|
|
return 0;
|
|
}
|
|
DEFINE_SHOW_ATTRIBUTE(zs_stats_size);
|
|
|
|
static void zs_pool_stat_create(struct zs_pool *pool, const char *name)
|
|
{
|
|
if (!zs_stat_root) {
|
|
pr_warn("no root stat dir, not creating <%s> stat dir\n", name);
|
|
return;
|
|
}
|
|
|
|
pool->stat_dentry = debugfs_create_dir(name, zs_stat_root);
|
|
|
|
debugfs_create_file("classes", S_IFREG | 0444, pool->stat_dentry, pool,
|
|
&zs_stats_size_fops);
|
|
}
|
|
|
|
static void zs_pool_stat_destroy(struct zs_pool *pool)
|
|
{
|
|
debugfs_remove_recursive(pool->stat_dentry);
|
|
}
|
|
|
|
#else /* CONFIG_ZSMALLOC_STAT */
|
|
static void __init zs_stat_init(void)
|
|
{
|
|
}
|
|
|
|
static void __exit zs_stat_exit(void)
|
|
{
|
|
}
|
|
|
|
static inline void zs_pool_stat_create(struct zs_pool *pool, const char *name)
|
|
{
|
|
}
|
|
|
|
static inline void zs_pool_stat_destroy(struct zs_pool *pool)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
|
|
/*
|
|
* For each size class, zspages are divided into different groups
|
|
* depending on how "full" they are. This was done so that we could
|
|
* easily find empty or nearly empty zspages when we try to shrink
|
|
* the pool (not yet implemented). This function returns fullness
|
|
* status of the given page.
|
|
*/
|
|
static enum fullness_group get_fullness_group(struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
int inuse, objs_per_zspage;
|
|
enum fullness_group fg;
|
|
|
|
inuse = get_zspage_inuse(zspage);
|
|
objs_per_zspage = class->objs_per_zspage;
|
|
|
|
if (inuse == 0)
|
|
fg = ZS_EMPTY;
|
|
else if (inuse == objs_per_zspage)
|
|
fg = ZS_FULL;
|
|
else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
|
|
fg = ZS_ALMOST_EMPTY;
|
|
else
|
|
fg = ZS_ALMOST_FULL;
|
|
|
|
return fg;
|
|
}
|
|
|
|
/*
|
|
* Each size class maintains various freelists and zspages are assigned
|
|
* to one of these freelists based on the number of live objects they
|
|
* have. This functions inserts the given zspage into the freelist
|
|
* identified by <class, fullness_group>.
|
|
*/
|
|
static void insert_zspage(struct size_class *class,
|
|
struct zspage *zspage,
|
|
enum fullness_group fullness)
|
|
{
|
|
struct zspage *head;
|
|
|
|
zs_stat_inc(class, fullness, 1);
|
|
head = list_first_entry_or_null(&class->fullness_list[fullness],
|
|
struct zspage, list);
|
|
/*
|
|
* We want to see more ZS_FULL pages and less almost empty/full.
|
|
* Put pages with higher ->inuse first.
|
|
*/
|
|
if (head && get_zspage_inuse(zspage) < get_zspage_inuse(head))
|
|
list_add(&zspage->list, &head->list);
|
|
else
|
|
list_add(&zspage->list, &class->fullness_list[fullness]);
|
|
}
|
|
|
|
/*
|
|
* This function removes the given zspage from the freelist identified
|
|
* by <class, fullness_group>.
|
|
*/
|
|
static void remove_zspage(struct size_class *class,
|
|
struct zspage *zspage,
|
|
enum fullness_group fullness)
|
|
{
|
|
VM_BUG_ON(list_empty(&class->fullness_list[fullness]));
|
|
VM_BUG_ON(is_zspage_isolated(zspage));
|
|
|
|
list_del_init(&zspage->list);
|
|
zs_stat_dec(class, fullness, 1);
|
|
}
|
|
|
|
/*
|
|
* Each size class maintains zspages in different fullness groups depending
|
|
* on the number of live objects they contain. When allocating or freeing
|
|
* objects, the fullness status of the page can change, say, from ALMOST_FULL
|
|
* to ALMOST_EMPTY when freeing an object. This function checks if such
|
|
* a status change has occurred for the given page and accordingly moves the
|
|
* page from the freelist of the old fullness group to that of the new
|
|
* fullness group.
|
|
*/
|
|
static enum fullness_group fix_fullness_group(struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
int class_idx;
|
|
enum fullness_group currfg, newfg;
|
|
|
|
get_zspage_mapping(zspage, &class_idx, &currfg);
|
|
newfg = get_fullness_group(class, zspage);
|
|
if (newfg == currfg)
|
|
goto out;
|
|
|
|
if (!is_zspage_isolated(zspage)) {
|
|
remove_zspage(class, zspage, currfg);
|
|
insert_zspage(class, zspage, newfg);
|
|
}
|
|
|
|
set_zspage_mapping(zspage, class_idx, newfg);
|
|
|
|
out:
|
|
return newfg;
|
|
}
|
|
|
|
/*
|
|
* We have to decide on how many pages to link together
|
|
* to form a zspage for each size class. This is important
|
|
* to reduce wastage due to unusable space left at end of
|
|
* each zspage which is given as:
|
|
* wastage = Zp % class_size
|
|
* usage = Zp - wastage
|
|
* where Zp = zspage size = k * PAGE_SIZE where k = 1, 2, ...
|
|
*
|
|
* For example, for size class of 3/8 * PAGE_SIZE, we should
|
|
* link together 3 PAGE_SIZE sized pages to form a zspage
|
|
* since then we can perfectly fit in 8 such objects.
|
|
*/
|
|
static int get_pages_per_zspage(int class_size)
|
|
{
|
|
int i, max_usedpc = 0;
|
|
/* zspage order which gives maximum used size per KB */
|
|
int max_usedpc_order = 1;
|
|
|
|
for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
|
|
int zspage_size;
|
|
int waste, usedpc;
|
|
|
|
zspage_size = i * PAGE_SIZE;
|
|
waste = zspage_size % class_size;
|
|
usedpc = (zspage_size - waste) * 100 / zspage_size;
|
|
|
|
if (usedpc > max_usedpc) {
|
|
max_usedpc = usedpc;
|
|
max_usedpc_order = i;
|
|
}
|
|
}
|
|
|
|
return max_usedpc_order;
|
|
}
|
|
|
|
static struct zspage *get_zspage(struct page *page)
|
|
{
|
|
struct zspage *zspage = (struct zspage *)page_private(page);
|
|
|
|
BUG_ON(zspage->magic != ZSPAGE_MAGIC);
|
|
return zspage;
|
|
}
|
|
|
|
static struct page *get_next_page(struct page *page)
|
|
{
|
|
if (unlikely(PageHugeObject(page)))
|
|
return NULL;
|
|
|
|
return page->freelist;
|
|
}
|
|
|
|
/**
|
|
* obj_to_location - get (<page>, <obj_idx>) from encoded object value
|
|
* @obj: the encoded object value
|
|
* @page: page object resides in zspage
|
|
* @obj_idx: object index
|
|
*/
|
|
static void obj_to_location(unsigned long obj, struct page **page,
|
|
unsigned int *obj_idx)
|
|
{
|
|
obj >>= OBJ_TAG_BITS;
|
|
*page = pfn_to_page(obj >> OBJ_INDEX_BITS);
|
|
*obj_idx = (obj & OBJ_INDEX_MASK);
|
|
}
|
|
|
|
/**
|
|
* location_to_obj - get obj value encoded from (<page>, <obj_idx>)
|
|
* @page: page object resides in zspage
|
|
* @obj_idx: object index
|
|
*/
|
|
static unsigned long location_to_obj(struct page *page, unsigned int obj_idx)
|
|
{
|
|
unsigned long obj;
|
|
|
|
obj = page_to_pfn(page) << OBJ_INDEX_BITS;
|
|
obj |= obj_idx & OBJ_INDEX_MASK;
|
|
obj <<= OBJ_TAG_BITS;
|
|
|
|
return obj;
|
|
}
|
|
|
|
static unsigned long handle_to_obj(unsigned long handle)
|
|
{
|
|
return *(unsigned long *)handle;
|
|
}
|
|
|
|
static unsigned long obj_to_head(struct page *page, void *obj)
|
|
{
|
|
if (unlikely(PageHugeObject(page))) {
|
|
VM_BUG_ON_PAGE(!is_first_page(page), page);
|
|
return page->index;
|
|
} else
|
|
return *(unsigned long *)obj;
|
|
}
|
|
|
|
static inline int testpin_tag(unsigned long handle)
|
|
{
|
|
return bit_spin_is_locked(HANDLE_PIN_BIT, (unsigned long *)handle);
|
|
}
|
|
|
|
static inline int trypin_tag(unsigned long handle)
|
|
{
|
|
return bit_spin_trylock(HANDLE_PIN_BIT, (unsigned long *)handle);
|
|
}
|
|
|
|
static void pin_tag(unsigned long handle) __acquires(bitlock)
|
|
{
|
|
bit_spin_lock(HANDLE_PIN_BIT, (unsigned long *)handle);
|
|
}
|
|
|
|
static void unpin_tag(unsigned long handle) __releases(bitlock)
|
|
{
|
|
bit_spin_unlock(HANDLE_PIN_BIT, (unsigned long *)handle);
|
|
}
|
|
|
|
static void reset_page(struct page *page)
|
|
{
|
|
__ClearPageMovable(page);
|
|
ClearPagePrivate(page);
|
|
set_page_private(page, 0);
|
|
page_mapcount_reset(page);
|
|
ClearPageHugeObject(page);
|
|
page->freelist = NULL;
|
|
}
|
|
|
|
static int trylock_zspage(struct zspage *zspage)
|
|
{
|
|
struct page *cursor, *fail;
|
|
|
|
for (cursor = get_first_page(zspage); cursor != NULL; cursor =
|
|
get_next_page(cursor)) {
|
|
if (!trylock_page(cursor)) {
|
|
fail = cursor;
|
|
goto unlock;
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
unlock:
|
|
for (cursor = get_first_page(zspage); cursor != fail; cursor =
|
|
get_next_page(cursor))
|
|
unlock_page(cursor);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void __free_zspage(struct zs_pool *pool, struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
struct page *page, *next;
|
|
enum fullness_group fg;
|
|
unsigned int class_idx;
|
|
|
|
get_zspage_mapping(zspage, &class_idx, &fg);
|
|
|
|
assert_spin_locked(&class->lock);
|
|
|
|
VM_BUG_ON(get_zspage_inuse(zspage));
|
|
VM_BUG_ON(fg != ZS_EMPTY);
|
|
|
|
next = page = get_first_page(zspage);
|
|
do {
|
|
VM_BUG_ON_PAGE(!PageLocked(page), page);
|
|
next = get_next_page(page);
|
|
reset_page(page);
|
|
unlock_page(page);
|
|
dec_zone_page_state(page, NR_ZSPAGES);
|
|
put_page(page);
|
|
page = next;
|
|
} while (page != NULL);
|
|
|
|
cache_free_zspage(pool, zspage);
|
|
|
|
zs_stat_dec(class, OBJ_ALLOCATED, class->objs_per_zspage);
|
|
atomic_long_sub(class->pages_per_zspage,
|
|
&pool->pages_allocated);
|
|
}
|
|
|
|
static void free_zspage(struct zs_pool *pool, struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
VM_BUG_ON(get_zspage_inuse(zspage));
|
|
VM_BUG_ON(list_empty(&zspage->list));
|
|
|
|
if (!trylock_zspage(zspage)) {
|
|
kick_deferred_free(pool);
|
|
return;
|
|
}
|
|
|
|
remove_zspage(class, zspage, ZS_EMPTY);
|
|
__free_zspage(pool, class, zspage);
|
|
}
|
|
|
|
/* Initialize a newly allocated zspage */
|
|
static void init_zspage(struct size_class *class, struct zspage *zspage)
|
|
{
|
|
unsigned int freeobj = 1;
|
|
unsigned long off = 0;
|
|
struct page *page = get_first_page(zspage);
|
|
|
|
while (page) {
|
|
struct page *next_page;
|
|
struct link_free *link;
|
|
void *vaddr;
|
|
|
|
set_first_obj_offset(page, off);
|
|
|
|
vaddr = kmap_atomic(page);
|
|
link = (struct link_free *)vaddr + off / sizeof(*link);
|
|
|
|
while ((off += class->size) < PAGE_SIZE) {
|
|
link->next = freeobj++ << OBJ_TAG_BITS;
|
|
link += class->size / sizeof(*link);
|
|
}
|
|
|
|
/*
|
|
* We now come to the last (full or partial) object on this
|
|
* page, which must point to the first object on the next
|
|
* page (if present)
|
|
*/
|
|
next_page = get_next_page(page);
|
|
if (next_page) {
|
|
link->next = freeobj++ << OBJ_TAG_BITS;
|
|
} else {
|
|
/*
|
|
* Reset OBJ_TAG_BITS bit to last link to tell
|
|
* whether it's allocated object or not.
|
|
*/
|
|
link->next = -1UL << OBJ_TAG_BITS;
|
|
}
|
|
kunmap_atomic(vaddr);
|
|
page = next_page;
|
|
off %= PAGE_SIZE;
|
|
}
|
|
|
|
set_freeobj(zspage, 0);
|
|
}
|
|
|
|
static void create_page_chain(struct size_class *class, struct zspage *zspage,
|
|
struct page *pages[])
|
|
{
|
|
int i;
|
|
struct page *page;
|
|
struct page *prev_page = NULL;
|
|
int nr_pages = class->pages_per_zspage;
|
|
|
|
/*
|
|
* Allocate individual pages and link them together as:
|
|
* 1. all pages are linked together using page->freelist
|
|
* 2. each sub-page point to zspage using page->private
|
|
*
|
|
* we set PG_private to identify the first page (i.e. no other sub-page
|
|
* has this flag set).
|
|
*/
|
|
for (i = 0; i < nr_pages; i++) {
|
|
page = pages[i];
|
|
set_page_private(page, (unsigned long)zspage);
|
|
page->freelist = NULL;
|
|
if (i == 0) {
|
|
zspage->first_page = page;
|
|
SetPagePrivate(page);
|
|
if (unlikely(class->objs_per_zspage == 1 &&
|
|
class->pages_per_zspage == 1))
|
|
SetPageHugeObject(page);
|
|
} else {
|
|
prev_page->freelist = page;
|
|
}
|
|
prev_page = page;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Allocate a zspage for the given size class
|
|
*/
|
|
static struct zspage *alloc_zspage(struct zs_pool *pool,
|
|
struct size_class *class,
|
|
gfp_t gfp)
|
|
{
|
|
int i;
|
|
struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE];
|
|
struct zspage *zspage = cache_alloc_zspage(pool, gfp);
|
|
|
|
if (!zspage)
|
|
return NULL;
|
|
|
|
zspage->magic = ZSPAGE_MAGIC;
|
|
migrate_lock_init(zspage);
|
|
|
|
for (i = 0; i < class->pages_per_zspage; i++) {
|
|
struct page *page;
|
|
|
|
page = alloc_page(gfp);
|
|
if (!page) {
|
|
while (--i >= 0) {
|
|
dec_zone_page_state(pages[i], NR_ZSPAGES);
|
|
__free_page(pages[i]);
|
|
}
|
|
cache_free_zspage(pool, zspage);
|
|
return NULL;
|
|
}
|
|
|
|
inc_zone_page_state(page, NR_ZSPAGES);
|
|
pages[i] = page;
|
|
}
|
|
|
|
create_page_chain(class, zspage, pages);
|
|
init_zspage(class, zspage);
|
|
|
|
return zspage;
|
|
}
|
|
|
|
static struct zspage *find_get_zspage(struct size_class *class)
|
|
{
|
|
int i;
|
|
struct zspage *zspage;
|
|
|
|
for (i = ZS_ALMOST_FULL; i >= ZS_EMPTY; i--) {
|
|
zspage = list_first_entry_or_null(&class->fullness_list[i],
|
|
struct zspage, list);
|
|
if (zspage)
|
|
break;
|
|
}
|
|
|
|
return zspage;
|
|
}
|
|
|
|
static inline int __zs_cpu_up(struct mapping_area *area)
|
|
{
|
|
/*
|
|
* Make sure we don't leak memory if a cpu UP notification
|
|
* and zs_init() race and both call zs_cpu_up() on the same cpu
|
|
*/
|
|
if (area->vm_buf)
|
|
return 0;
|
|
area->vm_buf = kmalloc(ZS_MAX_ALLOC_SIZE, GFP_KERNEL);
|
|
if (!area->vm_buf)
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
|
|
static inline void __zs_cpu_down(struct mapping_area *area)
|
|
{
|
|
kfree(area->vm_buf);
|
|
area->vm_buf = NULL;
|
|
}
|
|
|
|
static void *__zs_map_object(struct mapping_area *area,
|
|
struct page *pages[2], int off, int size)
|
|
{
|
|
int sizes[2];
|
|
void *addr;
|
|
char *buf = area->vm_buf;
|
|
|
|
/* disable page faults to match kmap_atomic() return conditions */
|
|
pagefault_disable();
|
|
|
|
/* no read fastpath */
|
|
if (area->vm_mm == ZS_MM_WO)
|
|
goto out;
|
|
|
|
sizes[0] = PAGE_SIZE - off;
|
|
sizes[1] = size - sizes[0];
|
|
|
|
/* copy object to per-cpu buffer */
|
|
addr = kmap_atomic(pages[0]);
|
|
memcpy(buf, addr + off, sizes[0]);
|
|
kunmap_atomic(addr);
|
|
addr = kmap_atomic(pages[1]);
|
|
memcpy(buf + sizes[0], addr, sizes[1]);
|
|
kunmap_atomic(addr);
|
|
out:
|
|
return area->vm_buf;
|
|
}
|
|
|
|
static void __zs_unmap_object(struct mapping_area *area,
|
|
struct page *pages[2], int off, int size)
|
|
{
|
|
int sizes[2];
|
|
void *addr;
|
|
char *buf;
|
|
|
|
/* no write fastpath */
|
|
if (area->vm_mm == ZS_MM_RO)
|
|
goto out;
|
|
|
|
buf = area->vm_buf;
|
|
buf = buf + ZS_HANDLE_SIZE;
|
|
size -= ZS_HANDLE_SIZE;
|
|
off += ZS_HANDLE_SIZE;
|
|
|
|
sizes[0] = PAGE_SIZE - off;
|
|
sizes[1] = size - sizes[0];
|
|
|
|
/* copy per-cpu buffer to object */
|
|
addr = kmap_atomic(pages[0]);
|
|
memcpy(addr + off, buf, sizes[0]);
|
|
kunmap_atomic(addr);
|
|
addr = kmap_atomic(pages[1]);
|
|
memcpy(addr, buf + sizes[0], sizes[1]);
|
|
kunmap_atomic(addr);
|
|
|
|
out:
|
|
/* enable page faults to match kunmap_atomic() return conditions */
|
|
pagefault_enable();
|
|
}
|
|
|
|
static int zs_cpu_prepare(unsigned int cpu)
|
|
{
|
|
struct mapping_area *area;
|
|
|
|
area = &per_cpu(zs_map_area, cpu);
|
|
return __zs_cpu_up(area);
|
|
}
|
|
|
|
static int zs_cpu_dead(unsigned int cpu)
|
|
{
|
|
struct mapping_area *area;
|
|
|
|
area = &per_cpu(zs_map_area, cpu);
|
|
__zs_cpu_down(area);
|
|
return 0;
|
|
}
|
|
|
|
static bool can_merge(struct size_class *prev, int pages_per_zspage,
|
|
int objs_per_zspage)
|
|
{
|
|
if (prev->pages_per_zspage == pages_per_zspage &&
|
|
prev->objs_per_zspage == objs_per_zspage)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool zspage_full(struct size_class *class, struct zspage *zspage)
|
|
{
|
|
return get_zspage_inuse(zspage) == class->objs_per_zspage;
|
|
}
|
|
|
|
unsigned long zs_get_total_pages(struct zs_pool *pool)
|
|
{
|
|
return atomic_long_read(&pool->pages_allocated);
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_get_total_pages);
|
|
|
|
/**
|
|
* zs_map_object - get address of allocated object from handle.
|
|
* @pool: pool from which the object was allocated
|
|
* @handle: handle returned from zs_malloc
|
|
* @mm: mapping mode to use
|
|
*
|
|
* Before using an object allocated from zs_malloc, it must be mapped using
|
|
* this function. When done with the object, it must be unmapped using
|
|
* zs_unmap_object.
|
|
*
|
|
* Only one object can be mapped per cpu at a time. There is no protection
|
|
* against nested mappings.
|
|
*
|
|
* This function returns with preemption and page faults disabled.
|
|
*/
|
|
void *zs_map_object(struct zs_pool *pool, unsigned long handle,
|
|
enum zs_mapmode mm)
|
|
{
|
|
struct zspage *zspage;
|
|
struct page *page;
|
|
unsigned long obj, off;
|
|
unsigned int obj_idx;
|
|
|
|
unsigned int class_idx;
|
|
enum fullness_group fg;
|
|
struct size_class *class;
|
|
struct mapping_area *area;
|
|
struct page *pages[2];
|
|
void *ret;
|
|
|
|
/*
|
|
* Because we use per-cpu mapping areas shared among the
|
|
* pools/users, we can't allow mapping in interrupt context
|
|
* because it can corrupt another users mappings.
|
|
*/
|
|
BUG_ON(in_interrupt());
|
|
|
|
/* From now on, migration cannot move the object */
|
|
pin_tag(handle);
|
|
|
|
obj = handle_to_obj(handle);
|
|
obj_to_location(obj, &page, &obj_idx);
|
|
zspage = get_zspage(page);
|
|
|
|
/* migration cannot move any subpage in this zspage */
|
|
migrate_read_lock(zspage);
|
|
|
|
get_zspage_mapping(zspage, &class_idx, &fg);
|
|
class = pool->size_class[class_idx];
|
|
off = (class->size * obj_idx) & ~PAGE_MASK;
|
|
|
|
area = &get_cpu_var(zs_map_area);
|
|
area->vm_mm = mm;
|
|
if (off + class->size <= PAGE_SIZE) {
|
|
/* this object is contained entirely within a page */
|
|
area->vm_addr = kmap_atomic(page);
|
|
ret = area->vm_addr + off;
|
|
goto out;
|
|
}
|
|
|
|
/* this object spans two pages */
|
|
pages[0] = page;
|
|
pages[1] = get_next_page(page);
|
|
BUG_ON(!pages[1]);
|
|
|
|
ret = __zs_map_object(area, pages, off, class->size);
|
|
out:
|
|
if (likely(!PageHugeObject(page)))
|
|
ret += ZS_HANDLE_SIZE;
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_map_object);
|
|
|
|
void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
|
|
{
|
|
struct zspage *zspage;
|
|
struct page *page;
|
|
unsigned long obj, off;
|
|
unsigned int obj_idx;
|
|
|
|
unsigned int class_idx;
|
|
enum fullness_group fg;
|
|
struct size_class *class;
|
|
struct mapping_area *area;
|
|
|
|
obj = handle_to_obj(handle);
|
|
obj_to_location(obj, &page, &obj_idx);
|
|
zspage = get_zspage(page);
|
|
get_zspage_mapping(zspage, &class_idx, &fg);
|
|
class = pool->size_class[class_idx];
|
|
off = (class->size * obj_idx) & ~PAGE_MASK;
|
|
|
|
area = this_cpu_ptr(&zs_map_area);
|
|
if (off + class->size <= PAGE_SIZE)
|
|
kunmap_atomic(area->vm_addr);
|
|
else {
|
|
struct page *pages[2];
|
|
|
|
pages[0] = page;
|
|
pages[1] = get_next_page(page);
|
|
BUG_ON(!pages[1]);
|
|
|
|
__zs_unmap_object(area, pages, off, class->size);
|
|
}
|
|
put_cpu_var(zs_map_area);
|
|
|
|
migrate_read_unlock(zspage);
|
|
unpin_tag(handle);
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_unmap_object);
|
|
|
|
/**
|
|
* zs_huge_class_size() - Returns the size (in bytes) of the first huge
|
|
* zsmalloc &size_class.
|
|
* @pool: zsmalloc pool to use
|
|
*
|
|
* The function returns the size of the first huge class - any object of equal
|
|
* or bigger size will be stored in zspage consisting of a single physical
|
|
* page.
|
|
*
|
|
* Context: Any context.
|
|
*
|
|
* Return: the size (in bytes) of the first huge zsmalloc &size_class.
|
|
*/
|
|
size_t zs_huge_class_size(struct zs_pool *pool)
|
|
{
|
|
return huge_class_size;
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_huge_class_size);
|
|
|
|
static unsigned long obj_malloc(struct size_class *class,
|
|
struct zspage *zspage, unsigned long handle)
|
|
{
|
|
int i, nr_page, offset;
|
|
unsigned long obj;
|
|
struct link_free *link;
|
|
|
|
struct page *m_page;
|
|
unsigned long m_offset;
|
|
void *vaddr;
|
|
|
|
handle |= OBJ_ALLOCATED_TAG;
|
|
obj = get_freeobj(zspage);
|
|
|
|
offset = obj * class->size;
|
|
nr_page = offset >> PAGE_SHIFT;
|
|
m_offset = offset & ~PAGE_MASK;
|
|
m_page = get_first_page(zspage);
|
|
|
|
for (i = 0; i < nr_page; i++)
|
|
m_page = get_next_page(m_page);
|
|
|
|
vaddr = kmap_atomic(m_page);
|
|
link = (struct link_free *)vaddr + m_offset / sizeof(*link);
|
|
set_freeobj(zspage, link->next >> OBJ_TAG_BITS);
|
|
if (likely(!PageHugeObject(m_page)))
|
|
/* record handle in the header of allocated chunk */
|
|
link->handle = handle;
|
|
else
|
|
/* record handle to page->index */
|
|
zspage->first_page->index = handle;
|
|
|
|
kunmap_atomic(vaddr);
|
|
mod_zspage_inuse(zspage, 1);
|
|
zs_stat_inc(class, OBJ_USED, 1);
|
|
|
|
obj = location_to_obj(m_page, obj);
|
|
|
|
return obj;
|
|
}
|
|
|
|
|
|
/**
|
|
* zs_malloc - Allocate block of given size from pool.
|
|
* @pool: pool to allocate from
|
|
* @size: size of block to allocate
|
|
* @gfp: gfp flags when allocating object
|
|
*
|
|
* On success, handle to the allocated object is returned,
|
|
* otherwise 0.
|
|
* Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.
|
|
*/
|
|
unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp)
|
|
{
|
|
unsigned long handle, obj;
|
|
struct size_class *class;
|
|
enum fullness_group newfg;
|
|
struct zspage *zspage;
|
|
|
|
if (unlikely(!size || size > ZS_MAX_ALLOC_SIZE))
|
|
return 0;
|
|
|
|
handle = cache_alloc_handle(pool, gfp);
|
|
if (!handle)
|
|
return 0;
|
|
|
|
/* extra space in chunk to keep the handle */
|
|
size += ZS_HANDLE_SIZE;
|
|
class = pool->size_class[get_size_class_index(size)];
|
|
|
|
spin_lock(&class->lock);
|
|
zspage = find_get_zspage(class);
|
|
if (likely(zspage)) {
|
|
obj = obj_malloc(class, zspage, handle);
|
|
/* Now move the zspage to another fullness group, if required */
|
|
fix_fullness_group(class, zspage);
|
|
record_obj(handle, obj);
|
|
spin_unlock(&class->lock);
|
|
|
|
return handle;
|
|
}
|
|
|
|
spin_unlock(&class->lock);
|
|
|
|
zspage = alloc_zspage(pool, class, gfp);
|
|
if (!zspage) {
|
|
cache_free_handle(pool, handle);
|
|
return 0;
|
|
}
|
|
|
|
spin_lock(&class->lock);
|
|
obj = obj_malloc(class, zspage, handle);
|
|
newfg = get_fullness_group(class, zspage);
|
|
insert_zspage(class, zspage, newfg);
|
|
set_zspage_mapping(zspage, class->index, newfg);
|
|
record_obj(handle, obj);
|
|
atomic_long_add(class->pages_per_zspage,
|
|
&pool->pages_allocated);
|
|
zs_stat_inc(class, OBJ_ALLOCATED, class->objs_per_zspage);
|
|
|
|
/* We completely set up zspage so mark them as movable */
|
|
SetZsPageMovable(pool, zspage);
|
|
spin_unlock(&class->lock);
|
|
|
|
return handle;
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_malloc);
|
|
|
|
static void obj_free(struct size_class *class, unsigned long obj)
|
|
{
|
|
struct link_free *link;
|
|
struct zspage *zspage;
|
|
struct page *f_page;
|
|
unsigned long f_offset;
|
|
unsigned int f_objidx;
|
|
void *vaddr;
|
|
|
|
obj_to_location(obj, &f_page, &f_objidx);
|
|
f_offset = (class->size * f_objidx) & ~PAGE_MASK;
|
|
zspage = get_zspage(f_page);
|
|
|
|
vaddr = kmap_atomic(f_page);
|
|
|
|
/* Insert this object in containing zspage's freelist */
|
|
link = (struct link_free *)(vaddr + f_offset);
|
|
link->next = get_freeobj(zspage) << OBJ_TAG_BITS;
|
|
kunmap_atomic(vaddr);
|
|
set_freeobj(zspage, f_objidx);
|
|
mod_zspage_inuse(zspage, -1);
|
|
zs_stat_dec(class, OBJ_USED, 1);
|
|
}
|
|
|
|
void zs_free(struct zs_pool *pool, unsigned long handle)
|
|
{
|
|
struct zspage *zspage;
|
|
struct page *f_page;
|
|
unsigned long obj;
|
|
unsigned int f_objidx;
|
|
int class_idx;
|
|
struct size_class *class;
|
|
enum fullness_group fullness;
|
|
bool isolated;
|
|
|
|
if (unlikely(!handle))
|
|
return;
|
|
|
|
pin_tag(handle);
|
|
obj = handle_to_obj(handle);
|
|
obj_to_location(obj, &f_page, &f_objidx);
|
|
zspage = get_zspage(f_page);
|
|
|
|
migrate_read_lock(zspage);
|
|
|
|
get_zspage_mapping(zspage, &class_idx, &fullness);
|
|
class = pool->size_class[class_idx];
|
|
|
|
spin_lock(&class->lock);
|
|
obj_free(class, obj);
|
|
fullness = fix_fullness_group(class, zspage);
|
|
if (fullness != ZS_EMPTY) {
|
|
migrate_read_unlock(zspage);
|
|
goto out;
|
|
}
|
|
|
|
isolated = is_zspage_isolated(zspage);
|
|
migrate_read_unlock(zspage);
|
|
/* If zspage is isolated, zs_page_putback will free the zspage */
|
|
if (likely(!isolated))
|
|
free_zspage(pool, class, zspage);
|
|
out:
|
|
|
|
spin_unlock(&class->lock);
|
|
unpin_tag(handle);
|
|
cache_free_handle(pool, handle);
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_free);
|
|
|
|
static void zs_object_copy(struct size_class *class, unsigned long dst,
|
|
unsigned long src)
|
|
{
|
|
struct page *s_page, *d_page;
|
|
unsigned int s_objidx, d_objidx;
|
|
unsigned long s_off, d_off;
|
|
void *s_addr, *d_addr;
|
|
int s_size, d_size, size;
|
|
int written = 0;
|
|
|
|
s_size = d_size = class->size;
|
|
|
|
obj_to_location(src, &s_page, &s_objidx);
|
|
obj_to_location(dst, &d_page, &d_objidx);
|
|
|
|
s_off = (class->size * s_objidx) & ~PAGE_MASK;
|
|
d_off = (class->size * d_objidx) & ~PAGE_MASK;
|
|
|
|
if (s_off + class->size > PAGE_SIZE)
|
|
s_size = PAGE_SIZE - s_off;
|
|
|
|
if (d_off + class->size > PAGE_SIZE)
|
|
d_size = PAGE_SIZE - d_off;
|
|
|
|
s_addr = kmap_atomic(s_page);
|
|
d_addr = kmap_atomic(d_page);
|
|
|
|
while (1) {
|
|
size = min(s_size, d_size);
|
|
memcpy(d_addr + d_off, s_addr + s_off, size);
|
|
written += size;
|
|
|
|
if (written == class->size)
|
|
break;
|
|
|
|
s_off += size;
|
|
s_size -= size;
|
|
d_off += size;
|
|
d_size -= size;
|
|
|
|
if (s_off >= PAGE_SIZE) {
|
|
kunmap_atomic(d_addr);
|
|
kunmap_atomic(s_addr);
|
|
s_page = get_next_page(s_page);
|
|
s_addr = kmap_atomic(s_page);
|
|
d_addr = kmap_atomic(d_page);
|
|
s_size = class->size - written;
|
|
s_off = 0;
|
|
}
|
|
|
|
if (d_off >= PAGE_SIZE) {
|
|
kunmap_atomic(d_addr);
|
|
d_page = get_next_page(d_page);
|
|
d_addr = kmap_atomic(d_page);
|
|
d_size = class->size - written;
|
|
d_off = 0;
|
|
}
|
|
}
|
|
|
|
kunmap_atomic(d_addr);
|
|
kunmap_atomic(s_addr);
|
|
}
|
|
|
|
/*
|
|
* Find alloced object in zspage from index object and
|
|
* return handle.
|
|
*/
|
|
static unsigned long find_alloced_obj(struct size_class *class,
|
|
struct page *page, int *obj_idx)
|
|
{
|
|
unsigned long head;
|
|
int offset = 0;
|
|
int index = *obj_idx;
|
|
unsigned long handle = 0;
|
|
void *addr = kmap_atomic(page);
|
|
|
|
offset = get_first_obj_offset(page);
|
|
offset += class->size * index;
|
|
|
|
while (offset < PAGE_SIZE) {
|
|
head = obj_to_head(page, addr + offset);
|
|
if (head & OBJ_ALLOCATED_TAG) {
|
|
handle = head & ~OBJ_ALLOCATED_TAG;
|
|
if (trypin_tag(handle))
|
|
break;
|
|
handle = 0;
|
|
}
|
|
|
|
offset += class->size;
|
|
index++;
|
|
}
|
|
|
|
kunmap_atomic(addr);
|
|
|
|
*obj_idx = index;
|
|
|
|
return handle;
|
|
}
|
|
|
|
struct zs_compact_control {
|
|
/* Source spage for migration which could be a subpage of zspage */
|
|
struct page *s_page;
|
|
/* Destination page for migration which should be a first page
|
|
* of zspage. */
|
|
struct page *d_page;
|
|
/* Starting object index within @s_page which used for live object
|
|
* in the subpage. */
|
|
int obj_idx;
|
|
};
|
|
|
|
static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
|
|
struct zs_compact_control *cc)
|
|
{
|
|
unsigned long used_obj, free_obj;
|
|
unsigned long handle;
|
|
struct page *s_page = cc->s_page;
|
|
struct page *d_page = cc->d_page;
|
|
int obj_idx = cc->obj_idx;
|
|
int ret = 0;
|
|
|
|
while (1) {
|
|
handle = find_alloced_obj(class, s_page, &obj_idx);
|
|
if (!handle) {
|
|
s_page = get_next_page(s_page);
|
|
if (!s_page)
|
|
break;
|
|
obj_idx = 0;
|
|
continue;
|
|
}
|
|
|
|
/* Stop if there is no more space */
|
|
if (zspage_full(class, get_zspage(d_page))) {
|
|
unpin_tag(handle);
|
|
ret = -ENOMEM;
|
|
break;
|
|
}
|
|
|
|
used_obj = handle_to_obj(handle);
|
|
free_obj = obj_malloc(class, get_zspage(d_page), handle);
|
|
zs_object_copy(class, free_obj, used_obj);
|
|
obj_idx++;
|
|
/*
|
|
* record_obj updates handle's value to free_obj and it will
|
|
* invalidate lock bit(ie, HANDLE_PIN_BIT) of handle, which
|
|
* breaks synchronization using pin_tag(e,g, zs_free) so
|
|
* let's keep the lock bit.
|
|
*/
|
|
free_obj |= BIT(HANDLE_PIN_BIT);
|
|
record_obj(handle, free_obj);
|
|
unpin_tag(handle);
|
|
obj_free(class, used_obj);
|
|
}
|
|
|
|
/* Remember last position in this iteration */
|
|
cc->s_page = s_page;
|
|
cc->obj_idx = obj_idx;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct zspage *isolate_zspage(struct size_class *class, bool source)
|
|
{
|
|
int i;
|
|
struct zspage *zspage;
|
|
enum fullness_group fg[2] = {ZS_ALMOST_EMPTY, ZS_ALMOST_FULL};
|
|
|
|
if (!source) {
|
|
fg[0] = ZS_ALMOST_FULL;
|
|
fg[1] = ZS_ALMOST_EMPTY;
|
|
}
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
zspage = list_first_entry_or_null(&class->fullness_list[fg[i]],
|
|
struct zspage, list);
|
|
if (zspage) {
|
|
VM_BUG_ON(is_zspage_isolated(zspage));
|
|
remove_zspage(class, zspage, fg[i]);
|
|
return zspage;
|
|
}
|
|
}
|
|
|
|
return zspage;
|
|
}
|
|
|
|
/*
|
|
* putback_zspage - add @zspage into right class's fullness list
|
|
* @class: destination class
|
|
* @zspage: target page
|
|
*
|
|
* Return @zspage's fullness_group
|
|
*/
|
|
static enum fullness_group putback_zspage(struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
enum fullness_group fullness;
|
|
|
|
VM_BUG_ON(is_zspage_isolated(zspage));
|
|
|
|
fullness = get_fullness_group(class, zspage);
|
|
insert_zspage(class, zspage, fullness);
|
|
set_zspage_mapping(zspage, class->index, fullness);
|
|
|
|
return fullness;
|
|
}
|
|
|
|
#ifdef CONFIG_COMPACTION
|
|
/*
|
|
* To prevent zspage destroy during migration, zspage freeing should
|
|
* hold locks of all pages in the zspage.
|
|
*/
|
|
static void lock_zspage(struct zspage *zspage)
|
|
{
|
|
struct page *page = get_first_page(zspage);
|
|
|
|
do {
|
|
lock_page(page);
|
|
} while ((page = get_next_page(page)) != NULL);
|
|
}
|
|
|
|
static int zs_init_fs_context(struct fs_context *fc)
|
|
{
|
|
return init_pseudo(fc, ZSMALLOC_MAGIC) ? 0 : -ENOMEM;
|
|
}
|
|
|
|
static struct file_system_type zsmalloc_fs = {
|
|
.name = "zsmalloc",
|
|
.init_fs_context = zs_init_fs_context,
|
|
.kill_sb = kill_anon_super,
|
|
};
|
|
|
|
static int zsmalloc_mount(void)
|
|
{
|
|
int ret = 0;
|
|
|
|
zsmalloc_mnt = kern_mount(&zsmalloc_fs);
|
|
if (IS_ERR(zsmalloc_mnt))
|
|
ret = PTR_ERR(zsmalloc_mnt);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void zsmalloc_unmount(void)
|
|
{
|
|
kern_unmount(zsmalloc_mnt);
|
|
}
|
|
|
|
static void migrate_lock_init(struct zspage *zspage)
|
|
{
|
|
rwlock_init(&zspage->lock);
|
|
}
|
|
|
|
static void migrate_read_lock(struct zspage *zspage) __acquires(&zspage->lock)
|
|
{
|
|
read_lock(&zspage->lock);
|
|
}
|
|
|
|
static void migrate_read_unlock(struct zspage *zspage) __releases(&zspage->lock)
|
|
{
|
|
read_unlock(&zspage->lock);
|
|
}
|
|
|
|
static void migrate_write_lock(struct zspage *zspage)
|
|
{
|
|
write_lock(&zspage->lock);
|
|
}
|
|
|
|
static void migrate_write_unlock(struct zspage *zspage)
|
|
{
|
|
write_unlock(&zspage->lock);
|
|
}
|
|
|
|
/* Number of isolated subpage for *page migration* in this zspage */
|
|
static void inc_zspage_isolation(struct zspage *zspage)
|
|
{
|
|
zspage->isolated++;
|
|
}
|
|
|
|
static void dec_zspage_isolation(struct zspage *zspage)
|
|
{
|
|
zspage->isolated--;
|
|
}
|
|
|
|
static void putback_zspage_deferred(struct zs_pool *pool,
|
|
struct size_class *class,
|
|
struct zspage *zspage)
|
|
{
|
|
enum fullness_group fg;
|
|
|
|
fg = putback_zspage(class, zspage);
|
|
if (fg == ZS_EMPTY)
|
|
schedule_work(&pool->free_work);
|
|
|
|
}
|
|
|
|
static inline void zs_pool_dec_isolated(struct zs_pool *pool)
|
|
{
|
|
VM_BUG_ON(atomic_long_read(&pool->isolated_pages) <= 0);
|
|
atomic_long_dec(&pool->isolated_pages);
|
|
/*
|
|
* Checking pool->destroying must happen after atomic_long_dec()
|
|
* for pool->isolated_pages above. Paired with the smp_mb() in
|
|
* zs_unregister_migration().
|
|
*/
|
|
smp_mb__after_atomic();
|
|
if (atomic_long_read(&pool->isolated_pages) == 0 && pool->destroying)
|
|
wake_up_all(&pool->migration_wait);
|
|
}
|
|
|
|
static void replace_sub_page(struct size_class *class, struct zspage *zspage,
|
|
struct page *newpage, struct page *oldpage)
|
|
{
|
|
struct page *page;
|
|
struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE] = {NULL, };
|
|
int idx = 0;
|
|
|
|
page = get_first_page(zspage);
|
|
do {
|
|
if (page == oldpage)
|
|
pages[idx] = newpage;
|
|
else
|
|
pages[idx] = page;
|
|
idx++;
|
|
} while ((page = get_next_page(page)) != NULL);
|
|
|
|
create_page_chain(class, zspage, pages);
|
|
set_first_obj_offset(newpage, get_first_obj_offset(oldpage));
|
|
if (unlikely(PageHugeObject(oldpage)))
|
|
newpage->index = oldpage->index;
|
|
__SetPageMovable(newpage, page_mapping(oldpage));
|
|
}
|
|
|
|
static bool zs_page_isolate(struct page *page, isolate_mode_t mode)
|
|
{
|
|
struct zs_pool *pool;
|
|
struct size_class *class;
|
|
int class_idx;
|
|
enum fullness_group fullness;
|
|
struct zspage *zspage;
|
|
struct address_space *mapping;
|
|
|
|
/*
|
|
* Page is locked so zspage couldn't be destroyed. For detail, look at
|
|
* lock_zspage in free_zspage.
|
|
*/
|
|
VM_BUG_ON_PAGE(!PageMovable(page), page);
|
|
VM_BUG_ON_PAGE(PageIsolated(page), page);
|
|
|
|
zspage = get_zspage(page);
|
|
|
|
/*
|
|
* Without class lock, fullness could be stale while class_idx is okay
|
|
* because class_idx is constant unless page is freed so we should get
|
|
* fullness again under class lock.
|
|
*/
|
|
get_zspage_mapping(zspage, &class_idx, &fullness);
|
|
mapping = page_mapping(page);
|
|
pool = mapping->private_data;
|
|
class = pool->size_class[class_idx];
|
|
|
|
spin_lock(&class->lock);
|
|
if (get_zspage_inuse(zspage) == 0) {
|
|
spin_unlock(&class->lock);
|
|
return false;
|
|
}
|
|
|
|
/* zspage is isolated for object migration */
|
|
if (list_empty(&zspage->list) && !is_zspage_isolated(zspage)) {
|
|
spin_unlock(&class->lock);
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* If this is first time isolation for the zspage, isolate zspage from
|
|
* size_class to prevent further object allocation from the zspage.
|
|
*/
|
|
if (!list_empty(&zspage->list) && !is_zspage_isolated(zspage)) {
|
|
get_zspage_mapping(zspage, &class_idx, &fullness);
|
|
atomic_long_inc(&pool->isolated_pages);
|
|
remove_zspage(class, zspage, fullness);
|
|
}
|
|
|
|
inc_zspage_isolation(zspage);
|
|
spin_unlock(&class->lock);
|
|
|
|
return true;
|
|
}
|
|
|
|
static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
|
|
struct page *page, enum migrate_mode mode)
|
|
{
|
|
struct zs_pool *pool;
|
|
struct size_class *class;
|
|
int class_idx;
|
|
enum fullness_group fullness;
|
|
struct zspage *zspage;
|
|
struct page *dummy;
|
|
void *s_addr, *d_addr, *addr;
|
|
int offset, pos;
|
|
unsigned long handle, head;
|
|
unsigned long old_obj, new_obj;
|
|
unsigned int obj_idx;
|
|
int ret = -EAGAIN;
|
|
|
|
/*
|
|
* We cannot support the _NO_COPY case here, because copy needs to
|
|
* happen under the zs lock, which does not work with
|
|
* MIGRATE_SYNC_NO_COPY workflow.
|
|
*/
|
|
if (mode == MIGRATE_SYNC_NO_COPY)
|
|
return -EINVAL;
|
|
|
|
VM_BUG_ON_PAGE(!PageMovable(page), page);
|
|
VM_BUG_ON_PAGE(!PageIsolated(page), page);
|
|
|
|
zspage = get_zspage(page);
|
|
|
|
/* Concurrent compactor cannot migrate any subpage in zspage */
|
|
migrate_write_lock(zspage);
|
|
get_zspage_mapping(zspage, &class_idx, &fullness);
|
|
pool = mapping->private_data;
|
|
class = pool->size_class[class_idx];
|
|
offset = get_first_obj_offset(page);
|
|
|
|
spin_lock(&class->lock);
|
|
if (!get_zspage_inuse(zspage)) {
|
|
/*
|
|
* Set "offset" to end of the page so that every loops
|
|
* skips unnecessary object scanning.
|
|
*/
|
|
offset = PAGE_SIZE;
|
|
}
|
|
|
|
pos = offset;
|
|
s_addr = kmap_atomic(page);
|
|
while (pos < PAGE_SIZE) {
|
|
head = obj_to_head(page, s_addr + pos);
|
|
if (head & OBJ_ALLOCATED_TAG) {
|
|
handle = head & ~OBJ_ALLOCATED_TAG;
|
|
if (!trypin_tag(handle))
|
|
goto unpin_objects;
|
|
}
|
|
pos += class->size;
|
|
}
|
|
|
|
/*
|
|
* Here, any user cannot access all objects in the zspage so let's move.
|
|
*/
|
|
d_addr = kmap_atomic(newpage);
|
|
memcpy(d_addr, s_addr, PAGE_SIZE);
|
|
kunmap_atomic(d_addr);
|
|
|
|
for (addr = s_addr + offset; addr < s_addr + pos;
|
|
addr += class->size) {
|
|
head = obj_to_head(page, addr);
|
|
if (head & OBJ_ALLOCATED_TAG) {
|
|
handle = head & ~OBJ_ALLOCATED_TAG;
|
|
BUG_ON(!testpin_tag(handle));
|
|
|
|
old_obj = handle_to_obj(handle);
|
|
obj_to_location(old_obj, &dummy, &obj_idx);
|
|
new_obj = (unsigned long)location_to_obj(newpage,
|
|
obj_idx);
|
|
new_obj |= BIT(HANDLE_PIN_BIT);
|
|
record_obj(handle, new_obj);
|
|
}
|
|
}
|
|
|
|
replace_sub_page(class, zspage, newpage, page);
|
|
get_page(newpage);
|
|
|
|
dec_zspage_isolation(zspage);
|
|
|
|
/*
|
|
* Page migration is done so let's putback isolated zspage to
|
|
* the list if @page is final isolated subpage in the zspage.
|
|
*/
|
|
if (!is_zspage_isolated(zspage)) {
|
|
/*
|
|
* We cannot race with zs_destroy_pool() here because we wait
|
|
* for isolation to hit zero before we start destroying.
|
|
* Also, we ensure that everyone can see pool->destroying before
|
|
* we start waiting.
|
|
*/
|
|
putback_zspage_deferred(pool, class, zspage);
|
|
zs_pool_dec_isolated(pool);
|
|
}
|
|
|
|
if (page_zone(newpage) != page_zone(page)) {
|
|
dec_zone_page_state(page, NR_ZSPAGES);
|
|
inc_zone_page_state(newpage, NR_ZSPAGES);
|
|
}
|
|
|
|
reset_page(page);
|
|
put_page(page);
|
|
page = newpage;
|
|
|
|
ret = MIGRATEPAGE_SUCCESS;
|
|
unpin_objects:
|
|
for (addr = s_addr + offset; addr < s_addr + pos;
|
|
addr += class->size) {
|
|
head = obj_to_head(page, addr);
|
|
if (head & OBJ_ALLOCATED_TAG) {
|
|
handle = head & ~OBJ_ALLOCATED_TAG;
|
|
BUG_ON(!testpin_tag(handle));
|
|
unpin_tag(handle);
|
|
}
|
|
}
|
|
kunmap_atomic(s_addr);
|
|
spin_unlock(&class->lock);
|
|
migrate_write_unlock(zspage);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void zs_page_putback(struct page *page)
|
|
{
|
|
struct zs_pool *pool;
|
|
struct size_class *class;
|
|
int class_idx;
|
|
enum fullness_group fg;
|
|
struct address_space *mapping;
|
|
struct zspage *zspage;
|
|
|
|
VM_BUG_ON_PAGE(!PageMovable(page), page);
|
|
VM_BUG_ON_PAGE(!PageIsolated(page), page);
|
|
|
|
zspage = get_zspage(page);
|
|
get_zspage_mapping(zspage, &class_idx, &fg);
|
|
mapping = page_mapping(page);
|
|
pool = mapping->private_data;
|
|
class = pool->size_class[class_idx];
|
|
|
|
spin_lock(&class->lock);
|
|
dec_zspage_isolation(zspage);
|
|
if (!is_zspage_isolated(zspage)) {
|
|
/*
|
|
* Due to page_lock, we cannot free zspage immediately
|
|
* so let's defer.
|
|
*/
|
|
putback_zspage_deferred(pool, class, zspage);
|
|
zs_pool_dec_isolated(pool);
|
|
}
|
|
spin_unlock(&class->lock);
|
|
}
|
|
|
|
static const struct address_space_operations zsmalloc_aops = {
|
|
.isolate_page = zs_page_isolate,
|
|
.migratepage = zs_page_migrate,
|
|
.putback_page = zs_page_putback,
|
|
};
|
|
|
|
static int zs_register_migration(struct zs_pool *pool)
|
|
{
|
|
pool->inode = alloc_anon_inode(zsmalloc_mnt->mnt_sb);
|
|
if (IS_ERR(pool->inode)) {
|
|
pool->inode = NULL;
|
|
return 1;
|
|
}
|
|
|
|
pool->inode->i_mapping->private_data = pool;
|
|
pool->inode->i_mapping->a_ops = &zsmalloc_aops;
|
|
return 0;
|
|
}
|
|
|
|
static bool pool_isolated_are_drained(struct zs_pool *pool)
|
|
{
|
|
return atomic_long_read(&pool->isolated_pages) == 0;
|
|
}
|
|
|
|
/* Function for resolving migration */
|
|
static void wait_for_isolated_drain(struct zs_pool *pool)
|
|
{
|
|
|
|
/*
|
|
* We're in the process of destroying the pool, so there are no
|
|
* active allocations. zs_page_isolate() fails for completely free
|
|
* zspages, so we need only wait for the zs_pool's isolated
|
|
* count to hit zero.
|
|
*/
|
|
wait_event(pool->migration_wait,
|
|
pool_isolated_are_drained(pool));
|
|
}
|
|
|
|
static void zs_unregister_migration(struct zs_pool *pool)
|
|
{
|
|
pool->destroying = true;
|
|
/*
|
|
* We need a memory barrier here to ensure global visibility of
|
|
* pool->destroying. Thus pool->isolated pages will either be 0 in which
|
|
* case we don't care, or it will be > 0 and pool->destroying will
|
|
* ensure that we wake up once isolation hits 0.
|
|
*/
|
|
smp_mb();
|
|
wait_for_isolated_drain(pool); /* This can block */
|
|
flush_work(&pool->free_work);
|
|
iput(pool->inode);
|
|
}
|
|
|
|
/*
|
|
* Caller should hold page_lock of all pages in the zspage
|
|
* In here, we cannot use zspage meta data.
|
|
*/
|
|
static void async_free_zspage(struct work_struct *work)
|
|
{
|
|
int i;
|
|
struct size_class *class;
|
|
unsigned int class_idx;
|
|
enum fullness_group fullness;
|
|
struct zspage *zspage, *tmp;
|
|
LIST_HEAD(free_pages);
|
|
struct zs_pool *pool = container_of(work, struct zs_pool,
|
|
free_work);
|
|
|
|
for (i = 0; i < ZS_SIZE_CLASSES; i++) {
|
|
class = pool->size_class[i];
|
|
if (class->index != i)
|
|
continue;
|
|
|
|
spin_lock(&class->lock);
|
|
list_splice_init(&class->fullness_list[ZS_EMPTY], &free_pages);
|
|
spin_unlock(&class->lock);
|
|
}
|
|
|
|
|
|
list_for_each_entry_safe(zspage, tmp, &free_pages, list) {
|
|
list_del(&zspage->list);
|
|
lock_zspage(zspage);
|
|
|
|
get_zspage_mapping(zspage, &class_idx, &fullness);
|
|
VM_BUG_ON(fullness != ZS_EMPTY);
|
|
class = pool->size_class[class_idx];
|
|
spin_lock(&class->lock);
|
|
__free_zspage(pool, class, zspage);
|
|
spin_unlock(&class->lock);
|
|
}
|
|
};
|
|
|
|
static void kick_deferred_free(struct zs_pool *pool)
|
|
{
|
|
schedule_work(&pool->free_work);
|
|
}
|
|
|
|
static void init_deferred_free(struct zs_pool *pool)
|
|
{
|
|
INIT_WORK(&pool->free_work, async_free_zspage);
|
|
}
|
|
|
|
static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
|
|
{
|
|
struct page *page = get_first_page(zspage);
|
|
|
|
do {
|
|
WARN_ON(!trylock_page(page));
|
|
__SetPageMovable(page, pool->inode->i_mapping);
|
|
unlock_page(page);
|
|
} while ((page = get_next_page(page)) != NULL);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
*
|
|
* Based on the number of unused allocated objects calculate
|
|
* and return the number of pages that we can free.
|
|
*/
|
|
static unsigned long zs_can_compact(struct size_class *class)
|
|
{
|
|
unsigned long obj_wasted;
|
|
unsigned long obj_allocated = zs_stat_get(class, OBJ_ALLOCATED);
|
|
unsigned long obj_used = zs_stat_get(class, OBJ_USED);
|
|
|
|
if (obj_allocated <= obj_used)
|
|
return 0;
|
|
|
|
obj_wasted = obj_allocated - obj_used;
|
|
obj_wasted /= class->objs_per_zspage;
|
|
|
|
return obj_wasted * class->pages_per_zspage;
|
|
}
|
|
|
|
static unsigned long __zs_compact(struct zs_pool *pool,
|
|
struct size_class *class)
|
|
{
|
|
struct zs_compact_control cc;
|
|
struct zspage *src_zspage;
|
|
struct zspage *dst_zspage = NULL;
|
|
unsigned long pages_freed = 0;
|
|
|
|
spin_lock(&class->lock);
|
|
while ((src_zspage = isolate_zspage(class, true))) {
|
|
|
|
if (!zs_can_compact(class))
|
|
break;
|
|
|
|
cc.obj_idx = 0;
|
|
cc.s_page = get_first_page(src_zspage);
|
|
|
|
while ((dst_zspage = isolate_zspage(class, false))) {
|
|
cc.d_page = get_first_page(dst_zspage);
|
|
/*
|
|
* If there is no more space in dst_page, resched
|
|
* and see if anyone had allocated another zspage.
|
|
*/
|
|
if (!migrate_zspage(pool, class, &cc))
|
|
break;
|
|
|
|
putback_zspage(class, dst_zspage);
|
|
}
|
|
|
|
/* Stop if we couldn't find slot */
|
|
if (dst_zspage == NULL)
|
|
break;
|
|
|
|
putback_zspage(class, dst_zspage);
|
|
if (putback_zspage(class, src_zspage) == ZS_EMPTY) {
|
|
free_zspage(pool, class, src_zspage);
|
|
pages_freed += class->pages_per_zspage;
|
|
}
|
|
spin_unlock(&class->lock);
|
|
cond_resched();
|
|
spin_lock(&class->lock);
|
|
}
|
|
|
|
if (src_zspage)
|
|
putback_zspage(class, src_zspage);
|
|
|
|
spin_unlock(&class->lock);
|
|
|
|
return pages_freed;
|
|
}
|
|
|
|
unsigned long zs_compact(struct zs_pool *pool)
|
|
{
|
|
int i;
|
|
struct size_class *class;
|
|
unsigned long pages_freed = 0;
|
|
|
|
for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
|
|
class = pool->size_class[i];
|
|
if (!class)
|
|
continue;
|
|
if (class->index != i)
|
|
continue;
|
|
pages_freed += __zs_compact(pool, class);
|
|
}
|
|
atomic_long_add(pages_freed, &pool->stats.pages_compacted);
|
|
|
|
return pages_freed;
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_compact);
|
|
|
|
void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats)
|
|
{
|
|
memcpy(stats, &pool->stats, sizeof(struct zs_pool_stats));
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_pool_stats);
|
|
|
|
static unsigned long zs_shrinker_scan(struct shrinker *shrinker,
|
|
struct shrink_control *sc)
|
|
{
|
|
unsigned long pages_freed;
|
|
struct zs_pool *pool = container_of(shrinker, struct zs_pool,
|
|
shrinker);
|
|
|
|
/*
|
|
* Compact classes and calculate compaction delta.
|
|
* Can run concurrently with a manually triggered
|
|
* (by user) compaction.
|
|
*/
|
|
pages_freed = zs_compact(pool);
|
|
|
|
return pages_freed ? pages_freed : SHRINK_STOP;
|
|
}
|
|
|
|
static unsigned long zs_shrinker_count(struct shrinker *shrinker,
|
|
struct shrink_control *sc)
|
|
{
|
|
int i;
|
|
struct size_class *class;
|
|
unsigned long pages_to_free = 0;
|
|
struct zs_pool *pool = container_of(shrinker, struct zs_pool,
|
|
shrinker);
|
|
|
|
for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
|
|
class = pool->size_class[i];
|
|
if (!class)
|
|
continue;
|
|
if (class->index != i)
|
|
continue;
|
|
|
|
pages_to_free += zs_can_compact(class);
|
|
}
|
|
|
|
return pages_to_free;
|
|
}
|
|
|
|
static void zs_unregister_shrinker(struct zs_pool *pool)
|
|
{
|
|
unregister_shrinker(&pool->shrinker);
|
|
}
|
|
|
|
static int zs_register_shrinker(struct zs_pool *pool)
|
|
{
|
|
pool->shrinker.scan_objects = zs_shrinker_scan;
|
|
pool->shrinker.count_objects = zs_shrinker_count;
|
|
pool->shrinker.batch = 0;
|
|
pool->shrinker.seeks = DEFAULT_SEEKS;
|
|
|
|
return register_shrinker(&pool->shrinker);
|
|
}
|
|
|
|
/**
|
|
* zs_create_pool - Creates an allocation pool to work from.
|
|
* @name: pool name to be created
|
|
*
|
|
* This function must be called before anything when using
|
|
* the zsmalloc allocator.
|
|
*
|
|
* On success, a pointer to the newly created pool is returned,
|
|
* otherwise NULL.
|
|
*/
|
|
struct zs_pool *zs_create_pool(const char *name)
|
|
{
|
|
int i;
|
|
struct zs_pool *pool;
|
|
struct size_class *prev_class = NULL;
|
|
|
|
pool = kzalloc(sizeof(*pool), GFP_KERNEL);
|
|
if (!pool)
|
|
return NULL;
|
|
|
|
init_deferred_free(pool);
|
|
|
|
pool->name = kstrdup(name, GFP_KERNEL);
|
|
if (!pool->name)
|
|
goto err;
|
|
|
|
#ifdef CONFIG_COMPACTION
|
|
init_waitqueue_head(&pool->migration_wait);
|
|
#endif
|
|
|
|
if (create_cache(pool))
|
|
goto err;
|
|
|
|
/*
|
|
* Iterate reversely, because, size of size_class that we want to use
|
|
* for merging should be larger or equal to current size.
|
|
*/
|
|
for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
|
|
int size;
|
|
int pages_per_zspage;
|
|
int objs_per_zspage;
|
|
struct size_class *class;
|
|
int fullness = 0;
|
|
|
|
size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
|
|
if (size > ZS_MAX_ALLOC_SIZE)
|
|
size = ZS_MAX_ALLOC_SIZE;
|
|
pages_per_zspage = get_pages_per_zspage(size);
|
|
objs_per_zspage = pages_per_zspage * PAGE_SIZE / size;
|
|
|
|
/*
|
|
* We iterate from biggest down to smallest classes,
|
|
* so huge_class_size holds the size of the first huge
|
|
* class. Any object bigger than or equal to that will
|
|
* endup in the huge class.
|
|
*/
|
|
if (pages_per_zspage != 1 && objs_per_zspage != 1 &&
|
|
!huge_class_size) {
|
|
huge_class_size = size;
|
|
/*
|
|
* The object uses ZS_HANDLE_SIZE bytes to store the
|
|
* handle. We need to subtract it, because zs_malloc()
|
|
* unconditionally adds handle size before it performs
|
|
* size class search - so object may be smaller than
|
|
* huge class size, yet it still can end up in the huge
|
|
* class because it grows by ZS_HANDLE_SIZE extra bytes
|
|
* right before class lookup.
|
|
*/
|
|
huge_class_size -= (ZS_HANDLE_SIZE - 1);
|
|
}
|
|
|
|
/*
|
|
* size_class is used for normal zsmalloc operation such
|
|
* as alloc/free for that size. Although it is natural that we
|
|
* have one size_class for each size, there is a chance that we
|
|
* can get more memory utilization if we use one size_class for
|
|
* many different sizes whose size_class have same
|
|
* characteristics. So, we makes size_class point to
|
|
* previous size_class if possible.
|
|
*/
|
|
if (prev_class) {
|
|
if (can_merge(prev_class, pages_per_zspage, objs_per_zspage)) {
|
|
pool->size_class[i] = prev_class;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
class = kzalloc(sizeof(struct size_class), GFP_KERNEL);
|
|
if (!class)
|
|
goto err;
|
|
|
|
class->size = size;
|
|
class->index = i;
|
|
class->pages_per_zspage = pages_per_zspage;
|
|
class->objs_per_zspage = objs_per_zspage;
|
|
spin_lock_init(&class->lock);
|
|
pool->size_class[i] = class;
|
|
for (fullness = ZS_EMPTY; fullness < NR_ZS_FULLNESS;
|
|
fullness++)
|
|
INIT_LIST_HEAD(&class->fullness_list[fullness]);
|
|
|
|
prev_class = class;
|
|
}
|
|
|
|
/* debug only, don't abort if it fails */
|
|
zs_pool_stat_create(pool, name);
|
|
|
|
if (zs_register_migration(pool))
|
|
goto err;
|
|
|
|
/*
|
|
* Not critical since shrinker is only used to trigger internal
|
|
* defragmentation of the pool which is pretty optional thing. If
|
|
* registration fails we still can use the pool normally and user can
|
|
* trigger compaction manually. Thus, ignore return code.
|
|
*/
|
|
zs_register_shrinker(pool);
|
|
|
|
return pool;
|
|
|
|
err:
|
|
zs_destroy_pool(pool);
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_create_pool);
|
|
|
|
void zs_destroy_pool(struct zs_pool *pool)
|
|
{
|
|
int i;
|
|
|
|
zs_unregister_shrinker(pool);
|
|
zs_unregister_migration(pool);
|
|
zs_pool_stat_destroy(pool);
|
|
|
|
for (i = 0; i < ZS_SIZE_CLASSES; i++) {
|
|
int fg;
|
|
struct size_class *class = pool->size_class[i];
|
|
|
|
if (!class)
|
|
continue;
|
|
|
|
if (class->index != i)
|
|
continue;
|
|
|
|
for (fg = ZS_EMPTY; fg < NR_ZS_FULLNESS; fg++) {
|
|
if (!list_empty(&class->fullness_list[fg])) {
|
|
pr_info("Freeing non-empty class with size %db, fullness group %d\n",
|
|
class->size, fg);
|
|
}
|
|
}
|
|
kfree(class);
|
|
}
|
|
|
|
destroy_cache(pool);
|
|
kfree(pool->name);
|
|
kfree(pool);
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_destroy_pool);
|
|
|
|
static int __init zs_init(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = zsmalloc_mount();
|
|
if (ret)
|
|
goto out;
|
|
|
|
ret = cpuhp_setup_state(CPUHP_MM_ZS_PREPARE, "mm/zsmalloc:prepare",
|
|
zs_cpu_prepare, zs_cpu_dead);
|
|
if (ret)
|
|
goto hp_setup_fail;
|
|
|
|
#ifdef CONFIG_ZPOOL
|
|
zpool_register_driver(&zs_zpool_driver);
|
|
#endif
|
|
|
|
zs_stat_init();
|
|
|
|
return 0;
|
|
|
|
hp_setup_fail:
|
|
zsmalloc_unmount();
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static void __exit zs_exit(void)
|
|
{
|
|
#ifdef CONFIG_ZPOOL
|
|
zpool_unregister_driver(&zs_zpool_driver);
|
|
#endif
|
|
zsmalloc_unmount();
|
|
cpuhp_remove_state(CPUHP_MM_ZS_PREPARE);
|
|
|
|
zs_stat_exit();
|
|
}
|
|
|
|
module_init(zs_init);
|
|
module_exit(zs_exit);
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
MODULE_AUTHOR("Nitin Gupta <ngupta@vflare.org>");
|