From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E7E2606A332 for ; Thu, 3 Dec 2026 04:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=FlR2eL47 Received: by kanga.kvack.org (Postfix) id 494396B00EF; Wed, 2 Dec 2026 23:24:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46C2F6B05B3; Wed, 2 Dec 2026 23:24:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35ADE6B05B4; Wed, 2 Dec 2026 23:24:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0504D6B00EF for ; Wed, 2 Dec 2026 23:24:51 -0500 (EST) Received: from smtpin04.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EC552A8120 for ; Thu, 3 Dec 2026 04:24:49 +0000 (UTC) X-FDA: 85501381098.04.C184D07 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) by imf02.hostedemail.com (Postfix) with ESMTP id 1035F80004 for ; Thu, 3 Dec 2026 04:24:47 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=FlR2eL47; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 74.125.82.45 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796271888; b=D0zPw0/z/B0lmRo4bvuYKonwKNS5nKjRK6NOoIeukuggH4JyFvXa3O+h7c7Y9vIf2QNTtE 4R86CSCBBM/XOIsMO+PPegykY+yZoert13h+paTCTAefWzYcA+kyXObsfn2DkhGHoIsJAt aPSv5vggY9lx7LNGibGEQpI+dlD+Paw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796271888; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X5kRFK67OFhyLVkPCARAegu4WBwyizYtEoR6vMCQXkI=; b=354EjEIUeIkg5NSot/8HbfTZ86b1/GVtYzg6aorT42fheOgHWV4shoOY9WXL9jn4SSmnFH VpnfOmt+uOAToVjXgLKncLaHFtZq7k3i2IjTj0Xwzqivee9GK9MCp5nUEvRg2j+Lalf2ea p2L+wD3kDZONoe7UvStyvmmsEvnwiHU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=FlR2eL47; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 74.125.82.45 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-1b59dfe466bso7560023c88.1 for ; Wed, 02 Dec 2026 20:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796271887; x=1796876687; darn=kvack.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=X5kRFK67OFhyLVkPCARAegu4WBwyizYtEoR6vMCQXkI=; b=FlR2eL47kJVBKaFQka05A/NdO5DP6Q4cEsHpe3hisZ5nb9LcZMTel7TM+KRtb48aEB ZQacqJhZZMt4ds5rZbvw1HW9a7hryLGqR0s1CqLkZo8+N2qvpOFkMDGHF118cehueOos j+l5Q/D+AsE59+uBhn/ukDqZSCIiUM3pCvavM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796271887; x=1796876687; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=X5kRFK67OFhyLVkPCARAegu4WBwyizYtEoR6vMCQXkI=; b=m3PpJPAJfseut3oTe7w82Yon+SLOoI1vWlyYcerQ9wP+8zojf9wktZR+k6+oQ3gJv2 ATgGaroyQcTHjr8WTJRDloFLy6hrEepD71OOhUny9FEdbCu1H9F2Tembb1O76A4zy2OD UER235Qg+ya2nRyTv7nEmvhU4Tf40LqOWFkPuXw+rj/t9WI/StrF6XrL8l14ytNlTdbC IyPX4C5LxVKNrJxoIaDLerwWiuOatk3ViD5UsHt+cMKr1mUzJHPzRWzfKdoC92rs5FbW YJdyOwPAu+fER5vsqKz0aaK1w26HaO9+MibogNuFXTyyWaHabdEt7e2hd0b9jjH38905 LHRQ== X-Forwarded-Encrypted: i=1; AL+hErEwOfvlDZrypCBMze+JQPL3PB9q8CAPivhiWn6G/K3MRJb6p/fqvJ7rEMcd5NVkUDZId8khmdgGMg==@kvack.org X-Gm-Message-State: APuU4Z/flWyDC2B9aLrb23hk/VCjhOpb/giJa4fv84NTwoGMkixt5rcv Cq5fNPrGq3xT4R2UqIBkhKPUGi4SWah+Kf4JdLxAHWkH+bLCGBuxkFZ8KlowmgwfhA== X-Gm-Gg: AZFdTZcvCM3VBNAfvtasfwBW4As2ubnYhiBcmMewMDDgoOYHzVThKRVyj5akSIgAKxU 2M//zDZUybjEu4oJCjnJ/mySfL7VyreJkpOlzEu7GzOzi3nm3zkrfHCZUz1JHoJFokL6VnctkLY +GKQguzFCEHSU3hZhHC37HyQW5cNJWLKaPmH/JD0eXpBiFbL4y2gQtsl4Abn6L5/ZPBDtR3H7Ux 0bIQHD76xrz1OumCgTrC31EiZkegYDlrkRmT634MH7wjCyFm4ilHYGkkqejUCOmAVzzc1ppd9yt 50gi/ESt51hge5KVR/xY1VGEPmt/bI5KEvtPrEhKaQu6rh6gaBrtwrIrbD7rL8AickQEeSpiAOW 5qMm3we0LI5yU7sVN0545dHSjSyn2Qqsd7GC82IcpxF+2cdb+wr3AvlbXmq2VRmazguEOJpWKFu FPdAB1/beEumL3RZWS6+Gsq/Er4SeOOY8Rk4fRx4jByT0cyorQHBrxP3tT0f7xippagF5XKzjmH 98WNfcYRCv9YBm9t6Bzo0G25TdFXtS7gdQqrc1YyP6Cm76WnbTU+yr3XiFEAWbT4dq4BaDXonZm IfB1RLab0OPwwpbhTltVa8CdgHjlYQgnYDuFBd3DwET8HWLzQGhypI2RYHQ2uoQ/CnBRg5VyIvj hs+zQA6aMOfcH9A== X-Received: by 2002:a05:701b:2816:b0:1b5:3b83:5374 with SMTP id a92af1059eb24-1b5568cfbd9mr39449066c88.19.1796271886781; Wed, 02 Dec 2026 20:24:46 -0800 (PST) Received: from google.com ([2a00:79e0:2031:6:e18c:e957:aa04:7114]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556847fdasm109279296c88.13.2026.12.02.20.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 20:24:46 -0800 (PST) Date: Thu, 3 Dec 2026 13:24:21 +0900 From: Sergey Senozhatsky To: Barry Song Cc: Chris Wiseman , Andrew Morton , Minchan Kim , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Xueyuan Chen , Xueyuan Chen , Brian Geffon , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nanzhe Zhao , Sergey Senozhatsky Subject: Re: [PATCH] mm/zsmalloc: remove shrinker Message-ID: References: <18ed2967f99a2eff.3137322e32332e3235332e313736.2c2157.0000sendgmr@google.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: bnzje895d8onz1xiye43i68wj3o7dcsu X-Rspamd-Queue-Id: 1035F80004 X-Rspamd-Server: rspam10 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1796271887-627768 X-HE-Meta: U2FsdGVkX19KXx9UA68Pca/f6Jynok6ISaRniveioDN4phOedzpeihhA6X9ixlHuszRxZPwRz38sd35j9H7y7QcyLKRO8cyanA1vMWSIW2tIEmjfCitjjpw9grb4xzSTrkcaicHWDTjzHem3f3Pk9R0DT8sA8+9B00UdGjAS80DPphNiN1KINIBcMzUmCLZ5yFwq36NGI+Ynb7cL4fqtoc8pTm22bzxK1bqEF4IQQozul53uGX/Sz0Y6m6/Imu11z4dwO03jJ8PrTcTx9hgVSfdFWDXMK9I0DefzIVSoUeeBZp/NVNB/pFTxxXn2cv6yAdt73Qyt3wP7lDmvJwrKOuZeWt2IzY4yzoNV/cBMyOeHD7KPetDjz3JQWCpyIT0pfeTbXYRTwqXrnVkiNKp2DfJbewxubBrJ5D0VxXmx2BDhpPqlzpFUvJHyEumEgcDNh0G903SKkXHja0dvWjkMEtR14I/mDaQc1W3QpDE7bfX9aYcNLT3DT2vmvVtO7NRyjCc5Lk4IAndoAZ86q7f1BNyw8Uj+inJS0sS6BcR0ypeLu2q2t/YS3WE/2GgsiwKNEhiSYKhYM3SMfQ8UdlesvB/KXxWolrO67AcARjbDFkso3k0xQm+dFwRjcTFerRpEDV5/hZEulJMyhUNor+5Lf+PEm+zTWu9pvO4UPOKNCu0ElIeAPldsOBWgSDg7YqZpY3cqpxnFd9T+tnwPRoNqgNrWhO9cxoRqgS370KQGxK6yzWtHrJg7ODDIf/e4lfddPWxEbmAhThYPTzLWFrSr5kxu0qwuEGZ8jtzcJAFS6CAGaAsXreWJIaNjTGN6stPo9Ht5/WcIbr7PDZ22DuUs34POzImeTApdtUBJS1VQ4/l+IYXhgNnNsGI9CaAyA1WwNAIa0VVSmwOjd1LNBosEwiTluA9ynmCUOmxJLNyAYc4BE529QPlS4dbvmcrqL+TlyfR17FwH75ZsSD2E/JF 9328nJRs uOfX9f/CaJdXcl0hRr5shZOJrDeVXyS3IdXZP1bWkLzRzpW3NO03X6UN9jQvf2MEuKcLjBBrzZ3BsOwPsv+v9RxyhCoTua7QX9LmKwNCU7bncZSvP+75RH2QF8RAUMLnpdV8a6cmLqnMHpeZhbpDTKNswosXquBbnLOacsGQ7ZDJ8LeQSx7w6N9rXrO++LDL7IyCD4OkX75TGsG5F7pSNS2bVUBtAW1Bt1ir1ExI2qhRlygTddUbNiEWSq6HG8JaEIJasy+RjDnQieWGPMuXTImKtkyfzBzK3UyvVFZoNJCc2jQ7sOd041OyW7EK7gF4kno94TuRYjY5HdY+J9Zaa8hB7+0mnKdRTTmdIcY2D7EYS0TuBLCkD2sXGrgNVdOUAJ8H9WIYpf2wCj0HzRCWfZKWXV1kUbcaKSs93y9WUwMoiHl18ECACrzBmD0+LmmxxPn4dPkG91RPit2r7Fs93Q3p4waVStPdTl2g3Gbnulb4YfhRPWThedCqiKryg6k1GMvTR7LQlrY+v2CuLbOnpIuRPvv8qdW9C5a1U4IiV30TdqO2BtVpRbkDEXb40zfEZprBYAXj7PZ4f0TALUoYlaXFUgPDb1W2ugObHBpdGVEqkZAnn8wwuJ4Bc1spC7xv9f7OY1+IyhXLSj8tIjcz7OcKd3g== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On (26/12/03 12:37), Sergey Senozhatsky wrote: > On (26/12/03 11:24), Barry Song wrote: > [..] > > > I suppose compaction will be beneficial after a huge app swap-in, e.g. > > > bringing back a web browser with (usual) million tabs. Or after a huge > > > app kill/termination, if the app had swap presence. Both of these > > > release memory from zsmalloc and create fragmentation, so we might > > > benefit from doing a de-fragmentation. > > > > Right. I had Nanzhe(Cc-ed) test this patch on Pixel 6 phones by repeatedly > > launching apps in a loop. We observed some negative results with > > this patch in the absence of proactive compaction. > > > > Nanzhe collected the time series of (mem_used_total - compr_data_size). > > Without the patch, the median was 32 MB. With the patch, it increased > > to 182 MB, peaking at 622 MB. > > > > The median memory overhead due to fragmentation increased from > > 2.5% without the patch to 16.87% with the patch. > > Hmm that's a high number... > > > So it seems that while mid-swap compaction is undesirable from a > > performance perspective, it does help reduce the memory footprint > > on phones. > > A bit of problem is that you need memory pressure to trigger compaction. > On a device, which does proactive per-app swap outs w/o hitting memory > pressure, the fragmentation footprint just sits there (and maybe even > grows). > > I wonder if we should consider some sort of a background compaction > triggered by zram instead of shrinker callback. E.g. when zram observes > that mem_used_total to compr_data_size ration goes above some run-time ^ ratio. Every single time! Every single time I try to spell "ratio" a "ration" comes out. So, atop of Chris' patch. Just a (vibe coded) sketch of an idea. Writeback is another case which creates fragmentation, but writeback is already called by user-space, so user-space can call compaction immediately after writeback. Opinions? ---- diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index db256c53b127..0c18b7fd144a 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -254,6 +254,8 @@ compressed_writeback RW show and set compressed writeback feature comp_algorithm RW show and change the compression algorithm algorithm_params WO setup compression algorithm parameters compact WO trigger memory compaction +compact_threshold RW show and set fragmentation threshold (%) for + deferred background compaction debug_stat RO this file is used for zram debugging purposes backing_dev RW set up backend storage for zram to write out idle WO mark allocated slot as idle diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 36873b655d66..4d410c918ef1 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "zram_drv.h" @@ -40,6 +41,7 @@ static int zram_major; static const char *default_compressor = CONFIG_ZRAM_DEF_COMP; #define ZRAM_MAX_ALGO_NAME_SZ 128 +#define ZRAM_COMPACT_DELAY (10 * HZ) /* Module params (documentation at end) */ static unsigned int num_devices = 1; @@ -1948,6 +1950,28 @@ static ssize_t recomp_algorithm_store(struct device *dev, } #endif +static void zram_schedule_compaction(struct zram *zram) +{ + if (!zram->compact_threshold) + return; + if (delayed_work_pending(&zram->compact_work)) + return; + + queue_delayed_work(system_dfl_long_wq, &zram->compact_work, + ZRAM_COMPACT_DELAY); +} + +static void zram_compact_work_fn(struct work_struct *work) +{ + struct zram *zram = container_of(work, struct zram, compact_work.work); + + guard(rwsem_read)(&zram->dev_lock); + if (!init_done(zram) || !zram->compact_threshold) + return; + + zs_compact_threshold(zram->mem_pool, zram->compact_threshold); +} + static ssize_t compact_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -1962,6 +1986,38 @@ static ssize_t compact_store(struct device *dev, struct device_attribute *attr, return len; } +static ssize_t compact_threshold_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct zram *zram = dev_to_zram(dev); + u32 val; + + guard(rwsem_read)(&zram->dev_lock); + val = zram->compact_threshold; + + return sysfs_emit(buf, "%u\n", val); +} + +static ssize_t compact_threshold_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + u32 val; + + if (kstrtouint(buf, 10, &val) || val >= 100) + return -EINVAL; + + guard(rwsem_write)(&zram->dev_lock); + if (init_done(zram)) + return -EBUSY; + + zram->compact_threshold = val; + + return len; +} + static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2120,6 +2176,7 @@ static void slot_free(struct zram *zram, unsigned long index) zram_stat_sub(zram, ZRAM_STAT_COMPR_DATA_SIZE, get_slot_size(zram, index)); + zram_schedule_compaction(zram); out: zram_stat_sub(zram, ZRAM_STAT_PAGES_STORED, 1); zram->table[index].element = 0; @@ -2895,9 +2952,12 @@ static void zram_reset_device(struct zram *zram) { int cpu; + disable_delayed_work_sync(&zram->compact_work); + guard(rwsem_write)(&zram->dev_lock); zram->limit_pages = 0; + zram->compact_threshold = 0; set_capacity_and_notify(zram->disk, 0); part_stat_set_all(zram->disk->part0, 0); @@ -2917,6 +2977,7 @@ static void zram_reset_device(struct zram *zram) zram->wb_batch_size = 32; zram->compressed_wb = false; #endif + enable_delayed_work(&zram->compact_work); } static ssize_t disksize_store(struct device *dev, struct device_attribute *attr, @@ -3038,6 +3099,7 @@ static DEVICE_ATTR_RO(io_stat); static DEVICE_ATTR_RO(mm_stat); static DEVICE_ATTR_RO(debug_stat); static DEVICE_ATTR_WO(compact); +static DEVICE_ATTR_RW(compact_threshold); static DEVICE_ATTR_RW(disksize); static DEVICE_ATTR_RO(initstate); static DEVICE_ATTR_WO(reset); @@ -3065,6 +3127,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_initstate.attr, &dev_attr_reset.attr, &dev_attr_compact.attr, + &dev_attr_compact_threshold.attr, &dev_attr_mem_limit.attr, &dev_attr_mem_used_max.attr, &dev_attr_idle.attr, @@ -3140,6 +3203,7 @@ static int zram_add(void) device_id = ret; init_rwsem(&zram->dev_lock); + INIT_DELAYED_WORK(&zram->compact_work, zram_compact_work_fn); #ifdef CONFIG_ZRAM_WRITEBACK zram->wb_batch_size = 32; zram->compressed_wb = false; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index a3fa6e3d007f..7f8223d3d490 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "zcomp.h" @@ -143,6 +144,8 @@ struct zram { * the number of pages zram can consume for storing compressed data */ unsigned long limit_pages; + unsigned int compact_threshold; + struct delayed_work compact_work; struct zram_stats stats; struct zram_pcpu_stats __percpu *pcpu_stats; diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 3232bc9c33b2..9bb544a48e47 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -54,6 +54,7 @@ size_t zs_huge_class_size(struct zs_pool *pool); unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); +void zs_compact_threshold(struct zs_pool *pool, unsigned int threshold); unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a1b6161fd237..5cbb8cb34a25 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -541,18 +541,18 @@ static struct size_class *lookup_size_class(struct zs_pool *pool, size_t size) static inline void class_stat_add(struct size_class *class, int type, unsigned long cnt) { - class->stats.objs[type] += cnt; + WRITE_ONCE(class->stats.objs[type], class->stats.objs[type] + cnt); } static inline void class_stat_sub(struct size_class *class, int type, unsigned long cnt) { - class->stats.objs[type] -= cnt; + WRITE_ONCE(class->stats.objs[type], class->stats.objs[type] - cnt); } static inline unsigned long class_stat_read(struct size_class *class, int type) { - return class->stats.objs[type]; + return READ_ONCE(class->stats.objs[type]); } static void __init zs_stat_init(void) @@ -2017,6 +2017,14 @@ static unsigned long __zs_compact(struct zs_pool *pool, struct zspage *dst_zspage = NULL; unsigned long pages_freed = 0; + /* + * Fast lockless check to avoid taking pool->lock and class->lock + * for classes that have no compactable pages. The exact counts + * are re-checked under locks below. + */ + if (!zs_can_compact(class)) + return 0; + /* * Protect against races between zpage migration and zs_free() / * zs_rebind_handle() (only when ZS_OBJ_CLASS_BITS does not apply), @@ -2103,6 +2111,44 @@ unsigned long zs_compact(struct zs_pool *pool) } EXPORT_SYMBOL_GPL(zs_compact); +static unsigned long zs_pool_can_compact(struct zs_pool *pool) +{ + int i; + struct size_class *class; + unsigned long pages_to_free = 0; + + for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { + class = pool->size_class[i]; + if (class->index != i) + continue; + + pages_to_free += zs_can_compact(class); + } + + return pages_to_free; +} + +void zs_compact_threshold(struct zs_pool *pool, unsigned int threshold) +{ + unsigned long total_pages; + unsigned long pages_to_free; + + if (!threshold || threshold >= 100 || + atomic_read(&pool->compaction_in_progress)) + return; + + total_pages = zs_get_total_pages(pool); + if (!total_pages) + return; + + pages_to_free = zs_pool_can_compact(pool); + if ((u64)pages_to_free * 100 < (u64)total_pages * threshold) + return; + + zs_compact(pool); +} +EXPORT_SYMBOL_GPL(zs_compact_threshold); + void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats) { memcpy(stats, &pool->stats, sizeof(struct zs_pool_stats));