mm: zram: fix swapcached issue on kernel 5.4

Afer Zram backing dev setuped, zram will be treated as a ASYNC IO
swap device, no longer SYNC IO device, because WB pages do have IO
operation on swap in, so the optimization on skiping swapcache
for fast swap device will no longer be applyed on such case.

Now we refactor this optimization, skip the swapcache by checking
SYNC IO state on each swap page via ioctl. Reuse ioctl because we
should not break the GKI.

Change-Id: Ia1dc351eafc7c0b62126a3864a6da9136c2bfe6d
Signed-off-by: huangzq2 <[email protected]>
Reviewed-on: https://gerrit.mot.com/1898090
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Yonghui Jia <[email protected]>
Reviewed-by: Zhizhong Ge <[email protected]>
Reviewed-by: Huosheng Liao <[email protected]>
Submit-Approved: Jira Key
This commit is contained in:
huangzq2 2021-03-11 09:49:55 +08:00 • committed by Xiaojun Ji
commit 824502c8d1
4 changed files with 55 additions and 4 deletions

View file

@ -25,6 +25,7 @@
#include <linux/genhd.h>
#include <linux/highmem.h>
#include <linux/slab.h>
#include <linux/swap.h>
#include <linux/backing-dev.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
@ -1630,6 +1631,27 @@ static void zram_slot_free_notify(struct block_device *bdev,
zram_slot_unlock(zram, index);
}
/* Moto huangzq2: check sync_io state on swap entry,
* return 0 on wb page, else return 1.
*/
#ifdef CONFIG_ZRAM_WRITEBACK
static int zram_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long index)
{
struct zram *zram;
int has_sync_io = 1;
if (cmd != SWP_SYNCHRONOUS_IO) return -EINVAL;
zram = bdev->bd_disk->private_data;
zram_slot_lock(zram, index);
has_sync_io = zram_test_flag(zram, index, ZRAM_WB) ? 0 : 1;
zram_slot_unlock(zram, index);
return has_sync_io;
}
#endif
static int zram_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, unsigned int op)
{
@ -1822,6 +1844,9 @@ static int zram_open(struct block_device *bdev, fmode_t mode)
static const struct block_device_operations zram_devops = {
.open = zram_open,
.swap_slot_free_notify = zram_slot_free_notify,
#ifdef CONFIG_ZRAM_WRITEBACK
.ioctl = zram_ioctl,
#endif
.rw_page = zram_rw_page,
.owner = THIS_MODULE
};