From patchwork Fri Mar 7 12:01:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UXVuLXdlaSBMaW4gKOael+e+pOW0tCk=?= X-Patchwork-Id: 14006390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6675EC282DE for ; Fri, 7 Mar 2025 12:02:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD2746B0085; Fri, 7 Mar 2025 07:02:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B5AF06B0088; Fri, 7 Mar 2025 07:02:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 984E96B0089; Fri, 7 Mar 2025 07:02:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 78EBE6B0085 for ; Fri, 7 Mar 2025 07:02:13 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C544BB723A for ; Fri, 7 Mar 2025 12:02:15 +0000 (UTC) X-FDA: 83194617030.05.7C2B852 Received: from mailgw01.mediatek.com (mailgw01.mediatek.com [216.200.240.184]) by imf25.hostedemail.com (Postfix) with ESMTP id 61D54A002E for ; Fri, 7 Mar 2025 12:02:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b=iy8T8atn; spf=pass (imf25.hostedemail.com: domain of qun-wei.lin@mediatek.com designates 216.200.240.184 as permitted sender) smtp.mailfrom=qun-wei.lin@mediatek.com; dmarc=pass (policy=quarantine) header.from=mediatek.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741348933; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=z29LXW8H6j5+YRRi20VzwXPPtbzAx8PDXEJJyuBSweA=; b=V0k+qVZXQI+9v5a8a6az9WsB/ISZrJXrQZqmIbYqIms4g9aQ91NtVZeKQiIDi/roY3It06 2ROS8EmI+rVW1mxfVXRTTn7HQWwFNOl0MbkXt6F8XfRNgWvtHu/+OD2jL9nLEJF0fgvjdl 8Qo8G+ZB/yeXsajNksHlZdaKjn/XL3I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741348933; a=rsa-sha256; cv=none; b=7GZ1LQfitA1901XYiUDZWz2f6rhkWJtmDyPOTqMcSXI7yaA7iG9Sat96i/ncj1d871i79f z1xC7W80nCWSxZ9TDpyWz9udjAZIgzmjs0wwnugghON30F7UesdZYsT7QBhYI51MQvwiif CAhzrypUl+MxNHnxnomRYDRExk/cg1Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b=iy8T8atn; spf=pass (imf25.hostedemail.com: domain of qun-wei.lin@mediatek.com designates 216.200.240.184 as permitted sender) smtp.mailfrom=qun-wei.lin@mediatek.com; dmarc=pass (policy=quarantine) header.from=mediatek.com X-UUID: fca379b2fb4b11ef83f2a1c9db70dae0-20250307 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=z29LXW8H6j5+YRRi20VzwXPPtbzAx8PDXEJJyuBSweA=; b=iy8T8atnxWBpiv4K8S5gBAoe6cHhhxTIYMQ0ui2oZyoX3fRif1h37NXcMYc2piKPF3vxAnqvXTULZ+OoaYayrP/Bsm0d8YE4c/WgaRB/aBqmBOaGHMdREBv3hofNtqS9aBiCEbuNeQEDbVjE+J3kg799+swipg86lduTxnsP3hM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:f3829ec8-3043-426c-8809-cf118eeade08,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:0 X-CID-META: VersionHash:0ef645f,CLOUDID:50cad149-a527-43d8-8af6-bc8b32d9f5e9,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0|50,EDM:-3,IP:ni l,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: fca379b2fb4b11ef83f2a1c9db70dae0-20250307 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 218018552; Fri, 07 Mar 2025 05:02:05 -0700 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Fri, 7 Mar 2025 20:02:01 +0800 Received: from mtksitap99.mediatek.inc (10.233.130.16) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Fri, 7 Mar 2025 20:02:01 +0800 From: Qun-Wei Lin To: Jens Axboe , Minchan Kim , Sergey Senozhatsky , Vishal Verma , Dan Williams , Dave Jiang , Ira Weiny , Andrew Morton , Matthias Brugger , AngeloGioacchino Del Regno , Chris Li , Ryan Roberts , "Huang, Ying" , Kairui Song , Dan Schatzberg , Barry Song , Al Viro CC: , , , , , , Casper Li , Chinwen Chang , Andrew Yang , James Hsu , Qun-Wei Lin Subject: [PATCH 0/2] Improve Zram by separating compression context from kswapd Date: Fri, 7 Mar 2025 20:01:02 +0800 Message-ID: <20250307120141.1566673-1-qun-wei.lin@mediatek.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-MTK: N X-Rspamd-Server: rspam02 X-Stat-Signature: oatpzyctzhucc69wfpj9ukpz44kjhoz1 X-Rspamd-Queue-Id: 61D54A002E X-Rspam-User: X-HE-Tag: 1741348933-698435 X-HE-Meta: U2FsdGVkX19lYiDeSYRLo5JMZVkiihA87bqN9DuEaBX+lRq7sGE1ONpzWHYZK9RmTSx5HQeb6JEX0GXVvafYlGEptzgIr5rNxL8L6p36fBrsj+TQG6jMqWBjdDs/BthhTcSZI/wI0kuIeV2LZSm83w49s8twGLw9Kv9ICValS4qU+vzGZHcLzf67HAw34godZBj3XEEAzsfG+nFOasoXLBsywrTlVJbHk7Y1ZAjJ3k8WHoTYpEoiL3s8YJOYpV4Ztev9qCxjmY7stPzd1UVlDPiu8U4iXv53GlnyAUck+i1kuGvZhuZQeKK9mJi6s9EXxKv4mOnEyEFSFZGHqQxMiA/8PVOnotugGrRCI05zBc038j0ESTSFAii8VsmNbEcBbGmpv+id/Fp0EaEnfYlEBbM6DC8Yu23ni5RZca8cmgm3wHjnbECOWDGv9+LVHUxI1MDI8QYIW1NcTtHTWzBrG8GE2dJY3r8CKWeExZi7BGrK1LFdJSespar77CWhLFbHuMkDvjzG8ksHG+H6ftTrnTgJ879htZmdNpeRxVt3SV3jaYxz5C+b6CoVU6/d/pOdJteNtqo2b24FowO1Ytqs9Rw6AdqwrcCBzeigQ/SCIzA8y4Ua2QJcOguZoiLUoGK7iWeXUlI6usg2rKk6+dUe9s+x3WZhSVuid4jdOlS4/IjzFC3IgDxaj/U6kYeHyw+t6SlSHv2zzsnHv+FoCXtIA93uoXvk17m8St6IKKmDNtmWBnI5dArUW21luAe9hen4ieeLZVJbNQqWmleyrlJ43ezumxwx4xH4zh2ZBHEKRl/cVVMkBdN74tEsyQQO8T8pwj+Wjn0uCFITiKbif3YfOsFcQBq9QZ1GxjW8L2aEBZON+jZFm8MxXr0fMZa9D9SS7qyltP8AeLDs2oBz5Lw7oAUnsrZzKL+QM85Zxc9o2DP+9GpjOyk10TFN0xir5WbZyW/8ukGdwe6ggcaaKWh 0Q9CwE1i 6duRdYIHvC8GTxQwAPiflWJWwt187LJLlFsVoXCQZkeFBYBKDhpTIDetrnxsWGJpR8yDuJ2chsV03dmyFoDhoLthSzfjUs7bUZtIKSopTw693EEH0sMCE4i5dAVEK/t8TaMQrXzl2JKXoi2M8LawzzapGVhkXVlY5PkLAeaxEUi6NJRKu4pA7lzP7tJj3UvxbLTtuRxXl+3VFFQuWH7Btu+h522YX2JUs2p/1NwwYva0tduj0Fk5UGWGg6w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch series introduces a new mechanism called kcompressd to improve the efficiency of memory reclaiming in the operating system. The main goal is to separate the tasks of page scanning and page compression into distinct processes or threads, thereby reducing the load on the kswapd thread and enhancing overall system performance under high memory pressure conditions. Problem: In the current system, the kswapd thread is responsible for both scanning the LRU pages and compressing pages into the ZRAM. This combined responsibility can lead to significant performance bottlenecks, especially under high memory pressure. The kswapd thread becomes a single point of contention, causing delays in memory reclaiming and overall system performance degradation. Target: The target of this invention is to improve the efficiency of memory reclaiming. By separating the tasks of page scanning and page compression into distinct processes or threads, the system can handle memory pressure more effectively. Patch 1: - Introduces 2 new feature flags, BLK_FEAT_READ_SYNCHRONOUS and SWP_READ_SYNCHRONOUS_IO. Patch 2: - Implemented the core functionality of Kcompressd and made necessary modifications to the zram driver to support it. In our handheld devices, we found that applying this mechanism under high memory pressure scenarios can increase the rate of pgsteal_anon per second by over 260% compared to the situation with only kswapd. Qun-Wei Lin (2): mm: Split BLK_FEAT_SYNCHRONOUS and SWP_SYNCHRONOUS_IO into separate read and write flags kcompressd: Add Kcompressd for accelerated zram compression drivers/block/brd.c | 3 +- drivers/block/zram/Kconfig | 11 ++ drivers/block/zram/Makefile | 3 +- drivers/block/zram/kcompressd.c | 340 ++++++++++++++++++++++++++++++++ drivers/block/zram/kcompressd.h | 25 +++ drivers/block/zram/zram_drv.c | 21 +- drivers/nvdimm/btt.c | 3 +- drivers/nvdimm/pmem.c | 5 +- include/linux/blkdev.h | 24 ++- include/linux/swap.h | 31 +-- mm/memory.c | 4 +- mm/page_io.c | 6 +- mm/swapfile.c | 7 +- 13 files changed, 446 insertions(+), 37 deletions(-) create mode 100644 drivers/block/zram/kcompressd.c create mode 100644 drivers/block/zram/kcompressd.h