OSDN Git Service

sagit-ice-cold/kernel_xiaomi_msm8998.git
4 years agof2fs: fix to use more generic EOPNOTSUPP
Chao Yu [Thu, 15 Aug 2019 11:45:36 +0000 (19:45 +0800)]
f2fs: fix to use more generic EOPNOTSUPP

EOPNOTSUPP is widely used as error number indicating operation is
not supported in syscall, and ENOTSUPP was defined and only used
for NFSv3 protocol, so use EOPNOTSUPP instead.

Fixes: 0a2aa8fbb969 ("f2fs: refactor __exchange_data_block for speed up")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: use wrapped IS_SWAPFILE()
Chao Yu [Thu, 15 Aug 2019 11:45:34 +0000 (19:45 +0800)]
f2fs: use wrapped IS_SWAPFILE()

Just cleanup, no logic change.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix to avoid call kvfree under spinlock
Chao Yu [Fri, 26 Jul 2019 07:43:17 +0000 (15:43 +0800)]
f2fs: fix to avoid call kvfree under spinlock

vfree() don't wish to be called from interrupt context, move it
out of spin_lock_irqsave() coverage.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agofs: f2fs: Remove unnecessary checks of SM_I(sbi) in update_general_status()
Jia-Ju Bai [Fri, 26 Jul 2019 03:45:12 +0000 (11:45 +0800)]
fs: f2fs: Remove unnecessary checks of SM_I(sbi) in update_general_status()

In fill_super() and put_super(), f2fs_destroy_stats() is called
in prior to f2fs_destroy_segment_manager(), so if current
sbi can still be visited in global stat list, SM_I(sbi) should be
released yet.
For this reason, SM_I(sbi) does not need to be checked in
update_general_status().
Thank Chao Yu for advice.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: disallow direct IO in atomic write
Chao Yu [Thu, 25 Jul 2019 14:39:11 +0000 (22:39 +0800)]
f2fs: disallow direct IO in atomic write

Atomic write needs page cache to cache data of transaction,
direct IO should never be allowed in atomic write, detect
and deny it when open atomic write file.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix to handle quota_{on,off} correctly
Chao Yu [Thu, 25 Jul 2019 09:33:37 +0000 (17:33 +0800)]
f2fs: fix to handle quota_{on,off} correctly

With quota_ino feature on, generic/232 reports an inconsistence issue
on the image.

The root cause is that the testcase tries to:
- use quotactl to shutdown journalled quota based on sysfile;
- and then use quotactl to enable/turn on quota based on specific file
(aquota.user or aquota.group).

Eventually, quota sysfile will be out-of-update due to following specific
file creation.

Change as below to fix this issue:
- deny enabling quota based on specific file if quota sysfile exists.
- set SBI_QUOTA_NEED_REPAIR once sysfile based quota shutdowns via
ioctl.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix to detect cp error in f2fs_setxattr()
Chao Yu [Mon, 22 Jul 2019 09:57:06 +0000 (17:57 +0800)]
f2fs: fix to detect cp error in f2fs_setxattr()

It needs to return -EIO if filesystem has been shutdown, fix the
miss case in f2fs_setxattr().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix to spread f2fs_is_checkpoint_ready()
Chao Yu [Mon, 22 Jul 2019 09:57:05 +0000 (17:57 +0800)]
f2fs: fix to spread f2fs_is_checkpoint_ready()

We missed to call f2fs_is_checkpoint_ready() in several places, it may
allow space allocation even when free space was exhausted during
checkpoint is disabled, fix to add them.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: support fiemap() for directory inode
Chao Yu [Mon, 22 Jul 2019 10:03:50 +0000 (18:03 +0800)]
f2fs: support fiemap() for directory inode

Adjust f2fs_fiemap() to support fiemap() on directory inode.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix to avoid discard command leak
Chao Yu [Fri, 19 Jul 2019 07:18:44 +0000 (15:18 +0800)]
f2fs: fix to avoid discard command leak

 =============================================================================
 BUG discard_cmd (Tainted: G    B      OE  ): Objects remaining in discard_cmd on __kmem_cache_shutdown()
 -----------------------------------------------------------------------------

 INFO: Slab 0xffffe1ac481d22c0 objects=36 used=2 fp=0xffff936b4748bf50 flags=0x2ffff0000000100
 Call Trace:
  dump_stack+0x63/0x87
  slab_err+0xa1/0xb0
  __kmem_cache_shutdown+0x183/0x390
  shutdown_cache+0x14/0x110
  kmem_cache_destroy+0x195/0x1c0
  f2fs_destroy_segment_manager_caches+0x21/0x40 [f2fs]
  exit_f2fs_fs+0x35/0x641 [f2fs]
  SyS_delete_module+0x155/0x230
  ? vtime_user_exit+0x29/0x70
  do_syscall_64+0x6e/0x160
  entry_SYSCALL64_slow_path+0x25/0x25

 INFO: Object 0xffff936b4748b000 @offset=0
 INFO: Object 0xffff936b4748b070 @offset=112
 kmem_cache_destroy discard_cmd: Slab cache still has objects
 Call Trace:
  dump_stack+0x63/0x87
  kmem_cache_destroy+0x1b4/0x1c0
  f2fs_destroy_segment_manager_caches+0x21/0x40 [f2fs]
  exit_f2fs_fs+0x35/0x641 [f2fs]
  SyS_delete_module+0x155/0x230
  do_syscall_64+0x6e/0x160
  entry_SYSCALL64_slow_path+0x25/0x25

Recovery can cache discard commands, so in error path of fill_super(),
we need give a chance to handle them, otherwise it will lead to leak
of discard_cmd slab cache.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: disallow switching io_bits option during remount
Chao Yu [Fri, 12 Jul 2019 08:57:00 +0000 (16:57 +0800)]
f2fs: disallow switching io_bits option during remount

If IO alignment feature is turned on after remount, we didn't
initialize mempool of it, it turns out we will encounter panic
during IO submission due to access NULL mempool pointer.

This feature should be set only at mount time, so simply deny
configuring during remount.

This fixes bug reported in bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=204135

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix panic of IO alignment feature
Chao Yu [Fri, 12 Jul 2019 08:55:42 +0000 (16:55 +0800)]
f2fs: fix panic of IO alignment feature

Since 07173c3ec276 ("block: enable multipage bvecs"), one bio vector
can store multi pages, so that we can not calculate max IO size of
bio as PAGE_SIZE * bio->bi_max_vecs. However IO alignment feature of
f2fs always has that assumption, so finally, it may cause panic during
IO submission as below stack.

 kernel BUG at fs/f2fs/data.c:317!
 RIP: 0010:__submit_merged_bio+0x8b0/0x8c0
 Call Trace:
  f2fs_submit_page_write+0x3cd/0xdd0
  do_write_page+0x15d/0x360
  f2fs_outplace_write_data+0xd7/0x210
  f2fs_do_write_data_page+0x43b/0xf30
  __write_data_page+0xcf6/0x1140
  f2fs_write_cache_pages+0x3ba/0xb40
  f2fs_write_data_pages+0x3dd/0x8b0
  do_writepages+0xbb/0x1e0
  __writeback_single_inode+0xb6/0x800
  writeback_sb_inodes+0x441/0x910
  wb_writeback+0x261/0x650
  wb_workfn+0x1f9/0x7a0
  process_one_work+0x503/0x970
  worker_thread+0x7d/0x820
  kthread+0x1ad/0x210
  ret_from_fork+0x35/0x40

This patch adds one extra condition to check left space in bio while
trying merging page to bio, to avoid panic.

This bug was reported in bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=204043

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: introduce {page,io}_is_mergeable() for readability
Chao Yu [Fri, 12 Jul 2019 08:55:41 +0000 (16:55 +0800)]
f2fs: introduce {page,io}_is_mergeable() for readability

Wrap merge condition into function for readability, no logic change.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: fix livelock in swapfile writes
Jaegeuk Kim [Wed, 31 Jul 2019 20:27:05 +0000 (13:27 -0700)]
f2fs: fix livelock in swapfile writes

This patch fixes livelock in the below call path when writing swap pages.

[46374.617256] c2    701  __switch_to+0xe4/0x100
[46374.617265] c2    701  __schedule+0x80c/0xbc4
[46374.617273] c2    701  schedule+0x74/0x98
[46374.617281] c2    701  rwsem_down_read_failed+0x190/0x234
[46374.617291] c2    701  down_read+0x58/0x5c
[46374.617300] c2    701  f2fs_map_blocks+0x138/0x9a8
[46374.617310] c2    701  get_data_block_dio_write+0x74/0x104
[46374.617320] c2    701  __blockdev_direct_IO+0x1350/0x3930
[46374.617331] c2    701  f2fs_direct_IO+0x55c/0x8bc
[46374.617341] c2    701  __swap_writepage+0x1d0/0x3e8
[46374.617351] c2    701  swap_writepage+0x44/0x54
[46374.617360] c2    701  shrink_page_list+0x140/0xe80
[46374.617371] c2    701  shrink_inactive_list+0x510/0x918
[46374.617381] c2    701  shrink_node_memcg+0x2d4/0x804
[46374.617391] c2    701  shrink_node+0x10c/0x2f8
[46374.617400] c2    701  do_try_to_free_pages+0x178/0x38c
[46374.617410] c2    701  try_to_free_pages+0x348/0x4b8
[46374.617419] c2    701  __alloc_pages_nodemask+0x7f8/0x1014
[46374.617429] c2    701  pagecache_get_page+0x184/0x2cc
[46374.617438] c2    701  f2fs_new_node_page+0x60/0x41c
[46374.617449] c2    701  f2fs_new_inode_page+0x50/0x7c
[46374.617460] c2    701  f2fs_init_inode_metadata+0x128/0x530
[46374.617472] c2    701  f2fs_add_inline_entry+0x138/0xd64
[46374.617480] c2    701  f2fs_do_add_link+0xf4/0x178
[46374.617488] c2    701  f2fs_create+0x1e4/0x3ac
[46374.617497] c2    701  path_openat+0xdc0/0x1308
[46374.617507] c2    701  do_filp_open+0x78/0x124
[46374.617516] c2    701  do_sys_open+0x134/0x248
[46374.617525] c2    701  SyS_openat+0x14/0x20

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs: Exit gc thread correctly
Julian Liu [Thu, 3 Oct 2019 05:54:50 +0000 (13:54 +0800)]
f2fs: Exit gc thread correctly

4 years agoprintk: silence healthd and batteryd logs
Julian Liu [Tue, 1 Oct 2019 23:41:11 +0000 (07:41 +0800)]
printk: silence healthd and batteryd logs

* <3>batteryd, <4>healthd

4 years agof2fs: fix dead wakelock holding
Julian Liu [Wed, 2 Oct 2019 06:22:26 +0000 (14:22 +0800)]
f2fs: fix dead wakelock holding

4 years agovideo: fbdev: Remove extraneous parentheses
Julian Liu [Sun, 29 Sep 2019 14:27:12 +0000 (22:27 +0800)]
video: fbdev: Remove extraneous parentheses

4 years agocamera_v2: ois: Remove extraneous parentheses
Julian Liu [Sun, 29 Sep 2019 14:25:08 +0000 (22:25 +0800)]
camera_v2: ois: Remove extraneous parentheses

4 years agocpuidle: lpm-levels: Remove unused variable
Julian Liu [Sun, 29 Sep 2019 14:22:48 +0000 (22:22 +0800)]
cpuidle: lpm-levels: Remove unused variable

4 years agof2fs: trigger rapid GC only when screen state actually changes
Park Ju Hyung [Wed, 14 Aug 2019 15:37:15 +0000 (00:37 +0900)]
f2fs: trigger rapid GC only when screen state actually changes

While it's normal for these events to happen after the other one,
with AOD or poorly made kernel source, we can receive the same event
consequently.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agof2fs: Stop gc if less invalid blocks when not charging
Julian Liu [Sat, 28 Sep 2019 20:10:54 +0000 (04:10 +0800)]
f2fs: Stop gc if less invalid blocks when not charging

4 years agof2fs: Optimize invalid block calculation
Julian Liu [Sat, 28 Sep 2019 19:53:24 +0000 (03:53 +0800)]
f2fs: Optimize invalid block calculation

4 years agoRevert "Makefile: Use O3 optimization level for Clang LTO"
Julian Liu [Sat, 28 Sep 2019 11:05:07 +0000 (19:05 +0800)]
Revert "Makefile: Use O3 optimization level for Clang LTO"

This reverts commit 9385ccbfc41bb3f700f444f7542e0e2f6f2cc8ce.

4 years agoRevert "kbuild: use LLVM integrated assembler for C files"
Julian Liu [Sat, 28 Sep 2019 10:51:52 +0000 (18:51 +0800)]
Revert "kbuild: use LLVM integrated assembler for C files"

* we are still not using llvm as
This reverts commit 8e6f3377e608364f55330eb1f2b85596bbfe72d3.

4 years agof2fs: Also execute rapid gc without charging
Julian Liu [Fri, 27 Sep 2019 15:07:18 +0000 (23:07 +0800)]
f2fs: Also execute rapid gc without charging

4 years agoiommu: msm: Rewrite to improve clarity and performance
Sultan Alsawaf [Fri, 27 Sep 2019 01:03:04 +0000 (18:03 -0700)]
iommu: msm: Rewrite to improve clarity and performance

This scope of this driver's lock usage is extremely wide, leading to
excessively long lock hold times. Additionally, there is lots of
excessive linked-list traversal and unnecessary dynamic memory
allocation in a critical path, causing poor performance across the
board.

Fix all of this by greatly reducing the scope of the locks used and by
significantly reducing the amount of operations performed when
msm_dma_map_sg_attrs() is called. The entire driver's code is overhauled
for better cleanliness and performance.

Note that ION must be modified to pass a known structure via the private
dma_buf pointer, so that the iommu driver can prevent races when
operating on the same buffer concurrently. This is the only way to
eliminate said buffer races without hurting the iommu driver's
performance.

Some additional members are added to the device struct as well to make
these various performance improvements possible.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoRevert "USB: set hub's default autosuspend delay as 0"
Thierry Strudel [Wed, 9 May 2018 18:39:23 +0000 (11:39 -0700)]
Revert "USB: set hub's default autosuspend delay as 0"

Certain USB-C devices are failing to enumerate if the bus
transitions from active to suspend between connection and enumeration.

When a USB-C accessory is inserted in a phone and is detected by the
CC lines, the controller driver is loaded and the only devices present
on the bus are the root hubs, until the device enumerations.
As a result, a suspend transition between device connection and
enumeration is very likely.

This change leaves the hub autosuspend set to the usbcore.autosuspend
value so a value can be set high enough to prevent this race.

This reverts:
commit 596d789a211d ("USB: set hub's default autosuspend delay as 0")

  This patch sets hub device's default autosuspend delay as 0 to
  speedup bus suspend, see comments in code for details.

Bug: 71936484
Change-Id: If9b50c52fdbbece154ca9adf559cd93db89fb0f3
Signed-off-by: Thierry Strudel <tstrudel@google.com>
Signed-off-by: Andrew Chant <achant@google.com>
4 years agomsm: kgsl: Increase worker thread priority
Sultan Alsawaf [Sun, 14 Oct 2018 07:52:53 +0000 (00:52 -0700)]
msm: kgsl: Increase worker thread priority

Currently, the kgsl worker thread is erroneosly ranked right below
Android's audio threads in terms of priority.

The kgsl worker thread is in the critical path for rendering frames to the
display, so increase its priority to match the priority of MDSS' kthread (mdss_fb0).

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
4 years agoRevert "msm: kgsl: Increase priority of RT thread"
Julian Liu [Mon, 23 Sep 2019 10:34:12 +0000 (18:34 +0800)]
Revert "msm: kgsl: Increase priority of RT thread"

This reverts commit 276fd756b9847aa4ede44860fb772fed1eb97348.

4 years agoRevert "ANDROID: sdcardfs: Allocate temporary name buffer on the stack"
Danny Lin [Sun, 22 Sep 2019 22:50:10 +0000 (15:50 -0700)]
Revert "ANDROID: sdcardfs: Allocate temporary name buffer on the stack"

This reverts commit 674f131b53ee1b4c22d0391ab48a46a583ef0962.

This causes stack overflows when combined with commit f16b4c07c7602
("quota_tree: Avoid dynamic memory allocations"). Revert this and retain
the quota_tree commit since it allocates more often than sdcardfs.

Known triggers are Asus' Twin Apps feature as well as using rsync to
transfer files in /sdcard.

[   74.545384] Kernel panic - not syncing: kernel stack overflow
[   74.545389] CPU: 1 PID: 581 Comm: Binder:503_3 Tainted: G S      W       4.14.146-Proton-gfaa3aaa2 #1089
[   74.545394] Hardware name: Qualcomm Technologies, Inc. SM8150 V2 PM8150 KIRIN MP (DT)
[   74.545398] Call trace:
[   74.545405]  dump_backtrace+0x0/0x218
[   74.545410]  show_stack+0x14/0x1c
[   74.545418]  dump_stack+0xbc/0x100
[   74.545424]  panic+0x110/0x284
[   74.545429]  panic+0x0/0x284
[   74.545434]  handle_bad_stack+0x110/0x124
[   74.545439]  __bad_stack+0x88/0x8c
[   74.545443]  pagecache_get_page+0x4/0x3f4
[   74.545448]  read_cache_page_gfp+0x1c/0x24
[   74.545455]  f2fs_quota_read+0xa4/0x3cc
[   74.545461]  do_insert_tree+0x8c/0x998
[   74.545466]  do_insert_tree+0x1c8/0x998
[   74.545471]  do_insert_tree+0x1c8/0x998
[   74.545476]  do_insert_tree+0x1c8/0x998
[   74.545481]  qtree_write_dquot+0x144/0x2c0
[   74.545486]  v2_write_dquot+0x58/0x84
[   74.545492]  dquot_acquire+0xe0/0x128
[   74.545497]  f2fs_dquot_acquire+0x30/0x6c
[   74.545502]  dqget+0x3a8/0x510
[   74.545507]  dquot_transfer+0xb8/0x15c
[   74.545511]  f2fs_setattr+0x10c/0x3cc
[   74.545517]  notify_change2+0x2b0/0x3a8
[   74.545523]  fixup_lower_ownership+0x138/0x3ac
[   74.545529]  sdcardfs_lookup+0x4d0/0x538
[   74.545534]  lookup_slow+0x9c/0x194
[   74.545539]  walk_component+0x120/0x1b0
[   74.545544]  path_lookupat+0x94/0x27c
[   74.545548]  filename_lookup+0x8c/0x1e0
[   74.545552]  user_path_at_empty+0x44/0x54
[   74.545558]  vfs_statx+0x84/0x124
[   74.545563]  SyS_newfstatat+0x30/0x6c
[   74.545568]  el0_svc_naked+0x34/0x38

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
4 years agodefconfig: Enable lmk adj rbtree
Julian Liu [Thu, 19 Sep 2019 16:00:09 +0000 (00:00 +0800)]
defconfig: Enable lmk adj rbtree

4 years agoMakefile: Pass optimization flags to assembler
Julian Liu [Mon, 16 Sep 2019 14:33:02 +0000 (22:33 +0800)]
Makefile: Pass optimization flags to assembler

4 years agoMakefile: Optimize for our CPU
wloot [Sat, 1 Jun 2019 21:15:08 +0000 (05:15 +0800)]
Makefile: Optimize for our CPU

4 years agoMakefile: Compile with O3
Joe Maples [Fri, 10 Nov 2017 15:51:18 +0000 (10:51 -0500)]
Makefile: Compile with O3

Signed-off-by: Joe Maples <joe@frap129.org>
4 years agoqcacld: check if auth_tag_len exceeds sizeof(hash)
Park Ju Hyung [Sat, 6 Jul 2019 18:00:59 +0000 (03:00 +0900)]
qcacld: check if auth_tag_len exceeds sizeof(hash)

Without this check, memcmp() compile-time check fails

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agoqcacld: disable more debugs
0ranko0P [Tue, 29 Oct 2019 12:03:59 +0000 (20:03 +0800)]
qcacld: disable more debugs

4 years agoqcacld: disable tso debugging
0ranko0P [Tue, 29 Oct 2019 04:10:09 +0000 (12:10 +0800)]
qcacld: disable tso debugging

4 years agoqcacld: nuke rx_wakelock code entirely
Park Ju Hyung [Thu, 7 Mar 2019 02:11:33 +0000 (11:11 +0900)]
qcacld: nuke rx_wakelock code entirely

We're not allowing this to be configurable on this kernel.

Nuke this entirely to reduce resource usage.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agoqcacld: initialize variables to avoid errors during compilation
Park Ju Hyung [Mon, 15 Apr 2019 09:47:58 +0000 (18:47 +0900)]
qcacld: initialize variables to avoid errors during compilation

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agopower: qcom: Silence clang warning
Harsh Shandilya [Sun, 6 Oct 2019 15:35:45 +0000 (21:05 +0530)]
power: qcom: Silence clang warning

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
4 years agodrivers: video: fbdev: update from sagit-p-oss
0ranko0P [Mon, 28 Oct 2019 11:37:05 +0000 (19:37 +0800)]
drivers: video: fbdev: update from sagit-p-oss

4 years agoqcacld-3.0: Fix another uninitialized variable
Julian Liu [Sat, 20 Jul 2019 09:55:59 +0000 (17:55 +0800)]
qcacld-3.0: Fix another uninitialized variable

Clang warns:
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1819:8: error:
      variable 'phyMode2' is used uninitialized whenever 'if' condition is
      false [-Werror,-Wsometimes-uninitialized]
                        if (eCSR_DOT11_MODE_AUTO & phyMode) {
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1826:36: note:
      uninitialized use occurs here
                fMatch = csr_get_phy_mode_in_use(phyMode2, phyModeInBssDesc,
                                                 ^~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1819:4: note:
      remove the 'if' if its condition is always true
                        if (eCSR_DOT11_MODE_AUTO & phyMode) {
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1797:2: note:
      variable 'phyMode2' is declared here
        eCsrPhyMode phyModeInBssDesc = eCSR_DOT11_MODE_AUTO, phyMode2;
        ^
1 error generated.

4 years agoMerge f2fs changes from branch 'memeuibut8.2' of https://github.com/wloot/android_ker...
0Ranko0P [Mon, 21 Oct 2019 12:31:15 +0000 (20:31 +0800)]
Merge f2fs changes from branch 'memeuibut8.2' of https://github.com/wloot/android_kernel_xiaomi_msm8998

4 years agolowmemorykiller: Account for extra_free_kbytes in calcuations
Jeff Vanhoof [Thu, 19 Oct 2017 10:39:30 +0000 (05:39 -0500)]
lowmemorykiller: Account for extra_free_kbytes in calcuations

Account for extra_free_kbytes in calcuations

CRs-fixed: (CR)
Signed-off-by: Jeff Vanhoof <qjv001@motorola.com>
Change-Id: I2c44a1775d43fad40cf49d6303b7552c2c089b6e
Reviewed-on: https://gerrit.mot.com/1076213
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Coverity Analysis <coverity@motorola.com>
Reviewed-by: Igor Kovalenko <igork@motorola.com>
Submit-Approved: Jira Key

4 years agolmk: add inline keywords to in-loop functions
Park Ju Hyung [Thu, 20 Jul 2017 13:04:03 +0000 (22:04 +0900)]
lmk: add inline keywords to in-loop functions

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agolmk: add static keywords to locally used variables
Park Ju Hyung [Thu, 20 Jul 2017 13:01:51 +0000 (22:01 +0900)]
lmk: add static keywords to locally used variables

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agolowmemorykiller: redesign memory instrumentation
Josh Galicia [Thu, 15 Sep 2016 18:43:49 +0000 (13:43 -0500)]
lowmemorykiller: redesign memory instrumentation

Add tracking node for LMK counts for memory instrumentation.

Change-Id: I7cd201dd4b84de81f08da580b590dad35673753b
Signed-off-by: Josh Galicia <cjg040@motorola.com>
Reviewed-on: https://gerrit.mot.com/899855
SLTApproved: Slta Waiver <sltawvr@motorola.com>
SME-Granted: SME Approvals Granted
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <cfries@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
4 years agolmk: import rbtree changes from Motorola
Park Ju Hyung [Wed, 17 Jul 2019 17:43:50 +0000 (02:43 +0900)]
lmk: import rbtree changes from Motorola

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Julian Liu <wlootlxt123@gmail.com>
[@wloot: backport to k4.4]

4 years agolowmemorykiller: fix compilation with 4.4
Julian Liu [Thu, 19 Sep 2019 15:44:40 +0000 (23:44 +0800)]
lowmemorykiller: fix compilation with 4.4

4 years agolowmemorykiller: checkout to android-4.9
Julian Liu [Thu, 19 Sep 2019 15:13:56 +0000 (23:13 +0800)]
lowmemorykiller: checkout to android-4.9

4 years agoRevert "{chiron,sagit}_defconfig: Use Simple LMK"
Julian Liu [Thu, 19 Sep 2019 15:10:05 +0000 (23:10 +0800)]
Revert "{chiron,sagit}_defconfig: Use Simple LMK"

This reverts commit ca0e1a2fd5be9399388af504886a2622315bc7bd.

4 years agotreewide: revert "remove duplicate const specifier" patchs
Julian Liu [Fri, 20 Sep 2019 03:57:25 +0000 (11:57 +0800)]
treewide: revert "remove duplicate const specifier" patchs

* C defined grammar

4 years agofs: proc: cpumaxfreq: Fix memory leak in cpumaxfreq_open
Julian Liu [Thu, 19 Sep 2019 19:38:00 +0000 (03:38 +0800)]
fs: proc: cpumaxfreq: Fix memory leak in cpumaxfreq_open

4 years agocamera_v2: Fix memory leak in msm_eeprom_platform_probe
Julian Liu [Thu, 19 Sep 2019 18:37:59 +0000 (02:37 +0800)]
camera_v2: Fix memory leak in msm_eeprom_platform_probe

4 years agonet: ipc_router: Fix memory leak when IPC_LOGGING disabled
Julian Liu [Thu, 19 Sep 2019 18:50:14 +0000 (02:50 +0800)]
net: ipc_router: Fix memory leak when IPC_LOGGING disabled

4 years agoRevert "camera_v2: update from sagit-p-oss"
Julian Liu [Wed, 18 Sep 2019 18:54:17 +0000 (02:54 +0800)]
Revert "camera_v2: update from sagit-p-oss"

This reverts commit e67a25de54ccdc249c887d7ad4829dc1dd127c3f.

4 years agocpuidle: lpm-levels: Remove debug event logging
Danny Lin [Mon, 6 May 2019 04:59:37 +0000 (21:59 -0700)]
cpuidle: lpm-levels: Remove debug event logging

A measurably significant amount of CPU time is spent on logging events
for debugging purposes in lpm_cpuidle_enter. Kill the useless logging to
reduce overhead.

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
4 years ago{chiron,sagit}_defconfig: omit frame pointer
Sultan Alsawaf [Mon, 15 Oct 2018 03:23:55 +0000 (20:23 -0700)]
{chiron,sagit}_defconfig: omit frame pointer

This improves performance by freeing up a register at the expense of a huge
hit to ease of debugging. Since this kernel is not actively being debugged
for anything though, frame pointers can be disabled.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Change-Id: I98f88e981f01336923e08a4585a2b5c6b174512b

4 years agoarm64: don't force FRAME_POINTER
Sultan Alsawaf [Mon, 15 Oct 2018 03:21:25 +0000 (20:21 -0700)]
arm64: don't force FRAME_POINTER

Change-Id: I08261db2f80fb11b7e02af64a4ec011c2dab2b39

4 years ago{chiron,sagit}_defconfig: Use Simple LMK
Sultan Alsawaf [Sun, 12 May 2019 20:12:25 +0000 (13:12 -0700)]
{chiron,sagit}_defconfig: Use Simple LMK

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agosimple_lmk: Mark reclaim kthread as performance critical
Sultan Alsawaf [Sun, 12 May 2019 20:12:21 +0000 (13:12 -0700)]
simple_lmk: Mark reclaim kthread as performance critical

Simple LMK's reclaim thread needs to run as quickly as possible to
reduce memory allocation latency when memory pressure is high. Mark it
as performance critical to schedule it on faster CPUs.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosimple_lmk: Introduce Simple Low Memory Killer for Android
Sultan Alsawaf [Wed, 21 Aug 2019 15:45:15 +0000 (08:45 -0700)]
simple_lmk: Introduce Simple Low Memory Killer for Android

This is a complete low memory killer solution for Android that is small
and simple. Processes are killed according to the priorities that
Android gives them, so that the least important processes are always
killed first. Processes are killed until memory deficits are satisfied,
as observed from kswapd struggling to free up pages. Simple LMK stops
killing processes when kswapd finally goes back to sleep.

The only tunables are the desired amount of memory to be freed per
reclaim event and desired frequency of reclaim events. Simple LMK tries
to free at least the desired amount of memory per reclaim and waits
until all of its victims' memory is freed before proceeding to kill more
processes.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR
宋金时 [Thu, 10 May 2018 02:05:03 +0000 (02:05 +0000)]
ANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR

When to execute binder_stat_br the e->cmd has been modifying as BR_OK
instead of the original return error cmd, in fact we want to know the
original return error, such as BR_DEAD_REPLY or BR_FAILED_REPLY, etc.
instead of always BR_OK, in order to avoid the value of the e->cmd is
always BR_OK, so we need assign the value of the e->cmd to cmd before
e->cmd = BR_OK.

Signed-off-by: songjinshi <songjinshi@xiaomi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 years agobinder: fix incorrect cmd to binder_stat_br
Todd Kjos [Tue, 8 Aug 2017 22:48:36 +0000 (15:48 -0700)]
binder: fix incorrect cmd to binder_stat_br

commit 26549d177410 ("binder: guarantee txn complete / errors delivered
in-order") passed the locally declared and undefined cmd
to binder_stat_br() which results in a bogus cmd field in a trace
event and BR stats are incremented incorrectly.

Change to use e->cmd which has been initialized.

Signed-off-by: Todd Kjos <tkjos@google.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 26549d177410 ("binder: guarantee txn complete / errors delivered in-order")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 years agofib_rules: Fix payload calculation
Sultan Alsawaf [Thu, 1 Aug 2019 03:10:06 +0000 (20:10 -0700)]
fib_rules: Fix payload calculation

The errant semicolon here results in the final addend getting discarded.

Fixes: ef5fbba6f8da ("net: core: add UID to flows, rules, and routes")
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agonet/ipv4: fib_trie: Avoid cryptic ternary expressions
Matthias Kaehlcke [Tue, 18 Jun 2019 21:14:40 +0000 (14:14 -0700)]
net/ipv4: fib_trie: Avoid cryptic ternary expressions

empty_child_inc/dec() use the ternary operator for conditional
operations. The conditions involve the post/pre in/decrement
operator and the operation is only performed when the condition
is *not* true. This is hard to parse for humans, use a regular
'if' construct instead and perform the in/decrement separately.

This also fixes two warnings that are emitted about the value
of the ternary expression being unused, when building the kernel
with clang + "kbuild: Remove unnecessary -Wno-unused-value"
(https://lore.kernel.org/patchwork/patch/1089869/):

CC      net/ipv4/fib_trie.o
net/ipv4/fib_trie.c:351:2: error: expression result unused [-Werror,-Wunused-value]
        ++tn_info(n)->empty_children ? : ++tn_info(n)->full_children;

Fixes: 95f60ea3e99a ("fib_trie: Add collapse() and should_collapse() to resize")
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
4 years ago{chiron,sagit}_defconfig: Panic in schedule() when stack corruption is found
Sultan Alsawaf [Thu, 1 Aug 2019 01:38:18 +0000 (18:38 -0700)]
{chiron,sagit}_defconfig: Panic in schedule() when stack corruption is found

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agolib: Kconfig.debug: Remove debug dependency from SCHED_STACK_END_CHECK
Sultan Alsawaf [Thu, 1 Aug 2019 01:37:06 +0000 (18:37 -0700)]
lib: Kconfig.debug: Remove debug dependency from SCHED_STACK_END_CHECK

This is a very useful feature that doesn't have any real dependencies on
DEBUG_KERNEL. Let it be used in the absence of DEBUG_KERNEL.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: sdcardfs: Allocate temporary name buffer on the stack
Sultan Alsawaf [Thu, 1 Aug 2019 01:34:31 +0000 (18:34 -0700)]
ANDROID: sdcardfs: Allocate temporary name buffer on the stack

Since this 4 KiB name buffer is only used temporarily, allocate it on
the stack to improve performance. This is confirmed to be safe according
to runtime stack usage measurements.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokobject_uevent: Allocate environment buffer on the stack
Sultan Alsawaf [Thu, 1 Aug 2019 01:27:02 +0000 (18:27 -0700)]
kobject_uevent: Allocate environment buffer on the stack

The environment buffer isn't very big; when it's allocated on the stack,
kobject_uevent_env's stack frame size increases to just over 2 KiB,
which is safe considering that we have a 16 KiB stack.

Allocate the environment buffer on the stack instead of using the slab
allocator in order to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoion: system_heap: Speed up system heap allocations
Sultan Alsawaf [Thu, 1 Aug 2019 01:02:49 +0000 (18:02 -0700)]
ion: system_heap: Speed up system heap allocations

The system heap allocation process consists of allocating numerous
temporary buffers that can instead be placed on the stack, to an extent;
if the new 4 KiB on-stack buffer runs out, page_info allocations will
fall back to using kmalloc.

Additionally, since system heap allocations are frequent, they can
benefit from the use of a memory pool for allocating the persistent
sg_table structures. These allocations, along with a few others, also
don't need to be zeroed out.

These changes improve system heap allocation performance considerably.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: crypto: heh - Avoid dynamically allocating memory for keys
Sultan Alsawaf [Wed, 31 Jul 2019 20:07:35 +0000 (13:07 -0700)]
ANDROID: crypto: heh - Avoid dynamically allocating memory for keys

The derived keys are usually quite small (48 B). We can use a small
on-stack buffer of 1 KiB to dodge dynamic memory allocation, speeding up
heh_setkey.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoext4: Avoid dynamically allocating memory in ext4_ext_remove_space
Sultan Alsawaf [Wed, 31 Jul 2019 20:06:33 +0000 (13:06 -0700)]
ext4: Avoid dynamically allocating memory in ext4_ext_remove_space

Although path depth is unbounded, we can still fulfill many path
allocations here with a 4 KiB stack allocation, thereby improving
performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoxattr: Avoid dynamically allocating memory in getxattr
Sultan Alsawaf [Wed, 31 Jul 2019 07:04:01 +0000 (00:04 -0700)]
xattr: Avoid dynamically allocating memory in getxattr

Although the maximum xattr size is too big to fit on the stack (64 KiB),
we can still fulfill most getxattr requests with a 4 KiB stack
allocation, thereby improving performance. Such a large stack allocation
here is confirmed to be safe via stack usage measurements at runtime.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agobinfmt_elf: Don't allocate memory dynamically in load_elf_binary
Sultan Alsawaf [Wed, 31 Jul 2019 07:00:01 +0000 (00:00 -0700)]
binfmt_elf: Don't allocate memory dynamically in load_elf_binary

The dynamic memory allocations in load_elf_binary can be replaced by
large stack allocations that bring the total frame size for the function
up to about 4 KiB. We have 16 KiB of stack space, and runtime
measurements confirm that using this much stack memory here is safe.
This improves performance by eliminating the overhead of dynamic memory
allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: sync: Use an on-stack allocation for fence info ioctl
Sultan Alsawaf [Wed, 31 Jul 2019 06:56:18 +0000 (23:56 -0700)]
staging: sync: Use an on-stack allocation for fence info ioctl

Since the fence info ioctl limits output data length to 4096 bytes, we
can just use a 4096-byte on-stack buffer for it (which is confirmed to
be safe via runtime stack usage measurements). This ioctl is used for
every frame rendered to the display, so eliminating dynamic memory
allocation overhead here improves frame rendering performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomedia: v4l2-ioctl: Use larger on-stack video copy buffers
Sultan Alsawaf [Wed, 31 Jul 2019 06:53:13 +0000 (23:53 -0700)]
media: v4l2-ioctl: Use larger on-stack video copy buffers

We have a 16 KiB stack; buffers of 4 KiB and 512 B work perfectly fine
in place of a small 128-byte buffer and especially no on-stack buffer at
all. This avoids dynamic memory allocation more often, improving
performance, and it's safe according to stack usage measurements at
runtime.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: camera: Optimize memory allocation for small buffers
Sultan Alsawaf [Wed, 31 Jul 2019 06:38:19 +0000 (23:38 -0700)]
msm: camera: Optimize memory allocation for small buffers

Try to use an on-stack buffer for memory allocations that are small
enough to not warrant a dynamic allocation, and eliminate dynamic memory
allocation entirely in msm_camera_cci_i2c_read_seq. This improves
performance by skipping latency-prone dynamic memory allocation when it
isn't needed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't allocate memory dynamically for temp command buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:35:56 +0000 (21:35 -0700)]
msm: kgsl: Don't allocate memory dynamically for temp command buffers

The temporary command buffer in _set_pagetable_gpu is only the size of a
single page; it is therefore easy to replace the dynamic command buffer
allocation with a static one to improve performance by avoiding the
latency of dynamic memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't allocate memory dynamically for small layer buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:29:13 +0000 (21:29 -0700)]
msm: mdss: Don't allocate memory dynamically for small layer buffers

There's no reason to dynamically allocate memory for a single, small
struct instance (output_layer) when it can be allocated on the stack.
Additionally, layer_list and validate_info_list are limited by the
maximum number of layers allowed, so they can be replaced by stack
allocations.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoext4 crypto: Use a larger on-stack file name buffer
Sultan Alsawaf [Wed, 31 Jul 2019 04:15:10 +0000 (21:15 -0700)]
ext4 crypto: Use a larger on-stack file name buffer

32 bytes for the on-stack file name buffer is rather small and doesn't
fit many file names, causing dynamic allocation to be used more often
than necessary instead. Increasing the on-stack buffer to 4 KiB is safe
and helps this function avoid dynamic memory allocations far more
frequently.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoselinux: Avoid dynamic memory allocation for small context buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:13:43 +0000 (21:13 -0700)]
selinux: Avoid dynamic memory allocation for small context buffers

Most context buffers are rather small and can fit on the stack,
eliminating the need to allocate them dynamically. Reserve a 4 KiB
stack buffer for this purpose to avoid the overhead of dynamic
memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokernfs: Avoid dynamic memory allocation for small write buffers
Sultan Alsawaf [Tue, 30 Jul 2019 21:21:10 +0000 (14:21 -0700)]
kernfs: Avoid dynamic memory allocation for small write buffers

Most write buffers are rather small and can fit on the stack,
eliminating the need to allocate them dynamically. Reserve a 4 KiB
stack buffer for this purpose to avoid the overhead of dynamic
memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Avoid dynamically allocating small command buffers
Sultan Alsawaf [Tue, 30 Jul 2019 21:19:59 +0000 (14:19 -0700)]
msm: kgsl: Avoid dynamically allocating small command buffers

Most command buffers here are rather small (fewer than 256 words); it's
a waste of time to dynamically allocate memory for such a small buffer
when it could easily fit on the stack.

Conditionally using an on-stack command buffer when the size is small
enough eliminates the need for using a dynamically-allocated buffer most
of the time, reducing GPU command submission latency.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years ago{chiron,sagit}_defconfig: Disable stack frame size warning
Sultan Alsawaf [Tue, 30 Jul 2019 21:19:45 +0000 (14:19 -0700)]
{chiron,sagit}_defconfig: Disable stack frame size warning

The stack frame size warning can be deceptive when it is clear that a
function with a large frame size won't cause stack overflows given how
it is used. Since this warning is more of a nuisance rather than
helpful, disable it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agoext4: Allocate allocation-context on the stack
Sultan Alsawaf [Sat, 13 Jul 2019 00:42:58 +0000 (17:42 -0700)]
ext4: Allocate allocation-context on the stack

The allocation context structure is quite small and easily fits on the
stack. There's no need to allocate it dynamically.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoscatterlist: Don't allocate sg lists using __get_free_page
Sultan Alsawaf [Fri, 12 Jul 2019 23:06:47 +0000 (16:06 -0700)]
scatterlist: Don't allocate sg lists using __get_free_page

Allocating pages with __get_free_page is slower than going through the
slab allocator to grab free pages out from a pool.

These are the results from running the code at the bottom of this
message:
[    1.278602] speedtest: __get_free_page: 9 us
[    1.278606] speedtest: kmalloc: 4 us
[    1.278609] speedtest: kmem_cache_alloc: 4 us
[    1.278611] speedtest: vmalloc: 13 us

kmalloc and kmem_cache_alloc (which is what kmalloc uses for common
sizes behind the scenes) are the fastest choices. Use kmalloc to speed
up sg list allocation.

This is the code used to produce the above measurements:
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

static int speedtest(void *data)
{
static const struct sched_param sched_max_rt_prio = {
.sched_priority = MAX_RT_PRIO - 1
};
volatile s64 ctotal = 0, gtotal = 0, ktotal = 0, vtotal = 0;
struct kmem_cache *page_pool;
int i, j, trials = 1000;
volatile ktime_t start;
void *ptr[100];

sched_setscheduler_nocheck(current, SCHED_FIFO, &sched_max_rt_prio);

page_pool = kmem_cache_create("pages", PAGE_SIZE, PAGE_SIZE, SLAB_PANIC,
      NULL);
for (i = 0; i < trials; i++) {
start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = kmem_cache_alloc(page_pool, GFP_KERNEL)));
ctotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
kmem_cache_free(page_pool, ptr[j]);

start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = (void *)__get_free_page(GFP_KERNEL)));
gtotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
free_page((unsigned long)ptr[j]);

start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = kmalloc(PAGE_SIZE, GFP_KERNEL)));
ktotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
kfree(ptr[j]);

start = ktime_get();
*ptr = vmalloc(ARRAY_SIZE(ptr) * PAGE_SIZE);
vtotal += ktime_us_delta(ktime_get(), start);
vfree(*ptr);
}
kmem_cache_destroy(page_pool);

printk("%s: __get_free_page: %lld us\n", __func__, gtotal / trials);
printk("%s: kmalloc: %lld us\n", __func__, ktotal / trials);
printk("%s: kmem_cache_alloc: %lld us\n", __func__, ctotal / trials);
printk("%s: vmalloc: %lld us\n", __func__, vtotal / trials);
complete(data);
return 0;
}

static int __init start_test(void)
{
DECLARE_COMPLETION_ONSTACK(done);

BUG_ON(IS_ERR(kthread_run(speedtest, &done, "malloc_test")));
wait_for_completion(&done);
return 0;
}
late_initcall(start_test);

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomm: kmemleak: Don't die when memory allocation fails
Sultan Alsawaf [Sun, 7 Jul 2019 04:15:19 +0000 (21:15 -0700)]
mm: kmemleak: Don't die when memory allocation fails

When memory is leaking, it's going to be harder to allocate more memory,
making it more likely for this failure condition inside of kmemleak to
manifest itself. This is extremely frustrating since kmemleak kills
itself upon the first instance of memory allocation failure.

Bypass that and make kmemleak more resilient when memory is running low.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomm: kmemleak: Don't require global debug options
Sultan Alsawaf [Sun, 7 Jul 2019 01:59:34 +0000 (18:59 -0700)]
mm: kmemleak: Don't require global debug options

This allows kmemleak to function even when debugfs is globally disabled,
allowing kmemleak to give accurate results for CONFIG_DEBUG_FS=n.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agombcache2: Speed up cache entry creation
Sultan Alsawaf [Wed, 3 Jul 2019 21:09:01 +0000 (14:09 -0700)]
mbcache2: Speed up cache entry creation

In order to prevent redundant entry creation by racing against itself,
mb2_cache_entry_create scans through a large hash-list of all current
entries in order to see if another allocation for the requested new
entry has been made. Furthermore, it allocates memory for a new entry
before scanning through this hash-list, which results in that allocated
memory being discarded when the requested new entry is already present.
This happens more than half the time.

Speed up cache entry creation by keeping a small linked list of
requested new entries in progress, and scanning through that first
instead of the large hash-list. Additionally, don't bother allocating
memory for a new entry until it's known that the allocated memory will
be used.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't allocate memory dynamically for destination scaler
Sultan Alsawaf [Wed, 31 Jul 2019 04:22:00 +0000 (21:22 -0700)]
msm: mdss: Don't allocate memory dynamically for destination scaler

Every atomic frame commit allocates memory dynamically for the
destination scaler, when those allocations can just be stored on the
stack instead. Eliminate these dynamic memory allocations in the frame
commit path to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoarm64: vdso: Mark vdso_pagelist allocation as not a leak
Sultan Alsawaf [Sun, 30 Jun 2019 04:56:06 +0000 (21:56 -0700)]
arm64: vdso: Mark vdso_pagelist allocation as not a leak

The vdso_pagelist allocation is stored inside the vDSO mappings, which
are static, so the memory is never leaked. However, kmemleak thinks that
vdso_pagelist is leaked because the vDSO mappings are read-only after
init.

Fix kmemleak's false positive by marking the allocation as not a leak.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agodmaengine: Fix memory leak in dma_async_device_register
Sultan Alsawaf [Sun, 30 Jun 2019 04:23:36 +0000 (21:23 -0700)]
dmaengine: Fix memory leak in dma_async_device_register

The atomic reference counter, idr_ref, is leaked when there are no
channels available for a DMA device. Free idr_ref in this case to fix
the memory leak.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoiommu: arm-smmu: Free pgtbl ops when domain contexts are destroyed
Sultan Alsawaf [Tue, 25 Jun 2019 17:53:43 +0000 (10:53 -0700)]
iommu: arm-smmu: Free pgtbl ops when domain contexts are destroyed

When a domain context is initialized, pgtbl ops are allocated, but they
aren't freed when the domain context is destroyed, causing memory to be
leaked. Fix the memory leak by freeing pgtbl ops when domain contexts
are destroyed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoALSA: control_compat: Don't dynamically allocate single-use structs
Sultan Alsawaf [Sat, 20 Jul 2019 17:58:01 +0000 (10:58 -0700)]
ALSA: control_compat: Don't dynamically allocate single-use structs

All of these dynamically-allocated structs can be simply placed on the
stack, eliminating the overhead of dynamic memory allocation entirely.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't allocate memory dynamically for drawobj sync structs
Sultan Alsawaf [Sun, 16 Jun 2019 21:26:47 +0000 (14:26 -0700)]
msm: kgsl: Don't allocate memory dynamically for drawobj sync structs

The memory allocated dynamically here is just used to store a single
instance of a struct. Allocate both possible structs on the stack
instead of allocating them dynamically to improve performance. These
structs also do not need to be zeroed out.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't try to wait for fences that have been signaled
Sultan Alsawaf [Sun, 16 Jun 2019 21:04:38 +0000 (14:04 -0700)]
msm: kgsl: Don't try to wait for fences that have been signaled

Trying to wait for fences that have already been signaled incurs a high
setup cost, since dynamic memory allocation must be used. Avoiding this
overhead when it isn't needed improves performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: sync: Add a function to check if a fence has been signaled
Sultan Alsawaf [Sun, 16 Jun 2019 21:02:24 +0000 (14:02 -0700)]
staging: sync: Add a function to check if a fence has been signaled

Knowing if a fence has been signaled is useful for avoiding the overhead
of needlessly setting up a sync operation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: android: ashmem: Get rid of the big mutex lock
Sultan Alsawaf [Tue, 11 Jun 2019 17:09:15 +0000 (10:09 -0700)]
staging: android: ashmem: Get rid of the big mutex lock

Ashmem uses a single big mutex lock for all synchronization, and even
uses it when no synchronization issues are present. The contention from
using a single lock results in all-around poor performance.

Use fine-grained locks and atomic constructions to eliminate the big
mutex lock, thereby improving performance greatly.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>