summaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-04-15 12:59:16 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-04-15 12:59:16 -0700
commit334fbe734e687404f346eba7d5d96ed2b44d35ab (patch)
tree65d5c8f4de18335209b2529146e6b06960a48b43 /drivers/block
parent5bdb4078e1efba9650c03753616866192d680718 (diff)
parent3bac01168982ec3e3bf87efdc1807c7933590a85 (diff)
Merge tag 'mm-stable-2026-04-13-21-45' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull MM updates from Andrew Morton: - "maple_tree: Replace big node with maple copy" (Liam Howlett) Mainly prepararatory work for ongoing development but it does reduce stack usage and is an improvement. - "mm, swap: swap table phase III: remove swap_map" (Kairui Song) Offers memory savings by removing the static swap_map. It also yields some CPU savings and implements several cleanups. - "mm: memfd_luo: preserve file seals" (Pratyush Yadav) File seal preservation to LUO's memfd code - "mm: zswap: add per-memcg stat for incompressible pages" (Jiayuan Chen) Additional userspace stats reportng to zswap - "arch, mm: consolidate empty_zero_page" (Mike Rapoport) Some cleanups for our handling of ZERO_PAGE() and zero_pfn - "mm/kmemleak: Improve scan_should_stop() implementation" (Zhongqiu Han) A robustness improvement and some cleanups in the kmemleak code - "Improve khugepaged scan logic" (Vernon Yang) Improve khugepaged scan logic and reduce CPU consumption by prioritizing scanning tasks that access memory frequently - "Make KHO Stateless" (Jason Miu) Simplify Kexec Handover by transitioning KHO from an xarray-based metadata tracking system with serialization to a radix tree data structure that can be passed directly to the next kernel - "mm: vmscan: add PID and cgroup ID to vmscan tracepoints" (Thomas Ballasi and Steven Rostedt) Enhance vmscan's tracepointing - "mm: arch/shstk: Common shadow stack mapping helper and VM_NOHUGEPAGE" (Catalin Marinas) Cleanup for the shadow stack code: remove per-arch code in favour of a generic implementation - "Fix KASAN support for KHO restored vmalloc regions" (Pasha Tatashin) Fix a WARN() which can be emitted the KHO restores a vmalloc area - "mm: Remove stray references to pagevec" (Tal Zussman) Several cleanups, mainly udpating references to "struct pagevec", which became folio_batch three years ago - "mm: Eliminate fake head pages from vmemmap optimization" (Kiryl Shutsemau) Simplify the HugeTLB vmemmap optimization (HVO) by changing how tail pages encode their relationship to the head page - "mm/damon/core: improve DAMOS quota efficiency for core layer filters" (SeongJae Park) Improve two problematic behaviors of DAMOS that makes it less efficient when core layer filters are used - "mm/damon: strictly respect min_nr_regions" (SeongJae Park) Improve DAMON usability by extending the treatment of the min_nr_regions user-settable parameter - "mm/page_alloc: pcp locking cleanup" (Vlastimil Babka) The proper fix for a previously hotfixed SMP=n issue. Code simplifications and cleanups ensued - "mm: cleanups around unmapping / zapping" (David Hildenbrand) A bunch of cleanups around unmapping and zapping. Mostly simplifications, code movements, documentation and renaming of zapping functions - "support batched checking of the young flag for MGLRU" (Baolin Wang) Batched checking of the young flag for MGLRU. It's part cleanups; one benchmark shows large performance benefits for arm64 - "memcg: obj stock and slab stat caching cleanups" (Johannes Weiner) memcg cleanup and robustness improvements - "Allow order zero pages in page reporting" (Yuvraj Sakshith) Enhance free page reporting - it is presently and undesirably order-0 pages when reporting free memory. - "mm: vma flag tweaks" (Lorenzo Stoakes) Cleanup work following from the recent conversion of the VMA flags to a bitmap - "mm/damon: add optional debugging-purpose sanity checks" (SeongJae Park) Add some more developer-facing debug checks into DAMON core - "mm/damon: test and document power-of-2 min_region_sz requirement" (SeongJae Park) An additional DAMON kunit test and makes some adjustments to the addr_unit parameter handling - "mm/damon/core: make passed_sample_intervals comparisons overflow-safe" (SeongJae Park) Fix a hard-to-hit time overflow issue in DAMON core - "mm/damon: improve/fixup/update ratio calculation, test and documentation" (SeongJae Park) A batch of misc/minor improvements and fixups for DAMON - "mm: move vma_(kernel|mmu)_pagesize() out of hugetlb.c" (David Hildenbrand) Fix a possible issue with dax-device when CONFIG_HUGETLB=n. Some code movement was required. - "zram: recompression cleanups and tweaks" (Sergey Senozhatsky) A somewhat random mix of fixups, recompression cleanups and improvements in the zram code - "mm/damon: support multiple goal-based quota tuning algorithms" (SeongJae Park) Extend DAMOS quotas goal auto-tuning to support multiple tuning algorithms that users can select - "mm: thp: reduce unnecessary start_stop_khugepaged()" (Breno Leitao) Fix the khugpaged sysfs handling so we no longer spam the logs with reams of junk when starting/stopping khugepaged - "mm: improve map count checks" (Lorenzo Stoakes) Provide some cleanups and slight fixes in the mremap, mmap and vma code - "mm/damon: support addr_unit on default monitoring targets for modules" (SeongJae Park) Extend the use of DAMON core's addr_unit tunable - "mm: khugepaged cleanups and mTHP prerequisites" (Nico Pache) Cleanups to khugepaged and is a base for Nico's planned khugepaged mTHP support - "mm: memory hot(un)plug and SPARSEMEM cleanups" (David Hildenbrand) Code movement and cleanups in the memhotplug and sparsemem code - "mm: remove CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE and cleanup CONFIG_MIGRATION" (David Hildenbrand) Rationalize some memhotplug Kconfig support - "change young flag check functions to return bool" (Baolin Wang) Cleanups to change all young flag check functions to return bool - "mm/damon/sysfs: fix memory leak and NULL dereference issues" (Josh Law and SeongJae Park) Fix a few potential DAMON bugs - "mm/vma: convert vm_flags_t to vma_flags_t in vma code" (Lorenzo Stoakes) Convert a lot of the existing use of the legacy vm_flags_t data type to the new vma_flags_t type which replaces it. Mainly in the vma code. - "mm: expand mmap_prepare functionality and usage" (Lorenzo Stoakes) Expand the mmap_prepare functionality, which is intended to replace the deprecated f_op->mmap hook which has been the source of bugs and security issues for some time. Cleanups, documentation, extension of mmap_prepare into filesystem drivers - "mm/huge_memory: refactor zap_huge_pmd()" (Lorenzo Stoakes) Simplify and clean up zap_huge_pmd(). Additional cleanups around vm_normal_folio_pmd() and the softleaf functionality are performed. * tag 'mm-stable-2026-04-13-21-45' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (369 commits) mm: fix deferred split queue races during migration mm/khugepaged: fix issue with tracking lock mm/huge_memory: add and use has_deposited_pgtable() mm/huge_memory: add and use normal_or_softleaf_folio_pmd() mm: add softleaf_is_valid_pmd_entry(), pmd_to_softleaf_folio() mm/huge_memory: separate out the folio part of zap_huge_pmd() mm/huge_memory: use mm instead of tlb->mm mm/huge_memory: remove unnecessary sanity checks mm/huge_memory: deduplicate zap deposited table call mm/huge_memory: remove unnecessary VM_BUG_ON_PAGE() mm/huge_memory: add a common exit path to zap_huge_pmd() mm/huge_memory: handle buggy PMD entry in zap_huge_pmd() mm/huge_memory: have zap_huge_pmd return a boolean, add kdoc mm/huge: avoid big else branch in zap_huge_pmd() mm/huge_memory: simplify vma_is_specal_huge() mm: on remap assert that input range within the proposed VMA mm: add mmap_action_map_kernel_pages[_full]() uio: replace deprecated mmap hook with mmap_prepare in uio_info drivers: hv: vmbus: replace deprecated mmap hook with mmap_prepare mm: allow handling of stacked mmap_prepare hooks in more drivers ...
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/zram/backend_lz4.c29
-rw-r--r--drivers/block/zram/zcomp.c9
-rw-r--r--drivers/block/zram/zcomp.h2
-rw-r--r--drivers/block/zram/zram_drv.c269
-rw-r--r--drivers/block/zram/zram_drv.h1
5 files changed, 156 insertions, 154 deletions
diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c
index 04e186614760..c449d511ba86 100644
--- a/drivers/block/zram/backend_lz4.c
+++ b/drivers/block/zram/backend_lz4.c
@@ -14,13 +14,38 @@ struct lz4_ctx {
static void lz4_release_params(struct zcomp_params *params)
{
+ LZ4_stream_t *dict_stream = params->drv_data;
+
+ params->drv_data = NULL;
+ if (!dict_stream)
+ return;
+
+ kfree(dict_stream);
}
static int lz4_setup_params(struct zcomp_params *params)
{
+ LZ4_stream_t *dict_stream;
+ int ret;
+
if (params->level == ZCOMP_PARAM_NOT_SET)
params->level = LZ4_ACCELERATION_DEFAULT;
+ if (!params->dict || !params->dict_sz)
+ return 0;
+
+ dict_stream = kzalloc_obj(*dict_stream, GFP_KERNEL);
+ if (!dict_stream)
+ return -ENOMEM;
+
+ ret = LZ4_loadDict(dict_stream,
+ params->dict, params->dict_sz);
+ if (ret != params->dict_sz) {
+ kfree(dict_stream);
+ return -EINVAL;
+ }
+ params->drv_data = dict_stream;
+
return 0;
}
@@ -79,9 +104,7 @@ static int lz4_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
zctx->mem);
} else {
/* Cstrm needs to be reset */
- ret = LZ4_loadDict(zctx->cstrm, params->dict, params->dict_sz);
- if (ret != params->dict_sz)
- return -EINVAL;
+ memcpy(zctx->cstrm, params->drv_data, sizeof(*zctx->cstrm));
ret = LZ4_compress_fast_continue(zctx->cstrm, req->src,
req->dst, req->src_len,
req->dst_len, params->level);
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index a771a8ecc540..974c4691887e 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -84,9 +84,14 @@ static const struct zcomp_ops *lookup_backend_ops(const char *comp)
return backends[i];
}
-bool zcomp_available_algorithm(const char *comp)
+const char *zcomp_lookup_backend_name(const char *comp)
{
- return lookup_backend_ops(comp) != NULL;
+ const struct zcomp_ops *backend = lookup_backend_ops(comp);
+
+ if (backend)
+ return backend->name;
+
+ return NULL;
}
/* show available compressors */
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index eacfd3f7d61d..81a0f3f6ff48 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -80,7 +80,7 @@ struct zcomp {
int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node);
int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
ssize_t zcomp_available_show(const char *comp, char *buf, ssize_t at);
-bool zcomp_available_algorithm(const char *comp);
+const char *zcomp_lookup_backend_name(const char *comp);
struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params);
void zcomp_destroy(struct zcomp *comp);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index af679375b193..c2afd1c34f4a 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1196,9 +1196,9 @@ static int parse_mode(char *val, u32 *mode)
return 0;
}
-static int scan_slots_for_writeback(struct zram *zram, u32 mode,
- unsigned long lo, unsigned long hi,
- struct zram_pp_ctl *ctl)
+static void scan_slots_for_writeback(struct zram *zram, u32 mode,
+ unsigned long lo, unsigned long hi,
+ struct zram_pp_ctl *ctl)
{
u32 index = lo;
@@ -1230,8 +1230,6 @@ next:
break;
index++;
}
-
- return 0;
}
static ssize_t writeback_store(struct device *dev,
@@ -1429,21 +1427,21 @@ static void zram_async_read_endio(struct bio *bio)
queue_work(system_highpri_wq, &req->work);
}
-static void read_from_bdev_async(struct zram *zram, struct page *page,
- u32 index, unsigned long blk_idx,
- struct bio *parent)
+static int read_from_bdev_async(struct zram *zram, struct page *page,
+ u32 index, unsigned long blk_idx,
+ struct bio *parent)
{
struct zram_rb_req *req;
struct bio *bio;
req = kmalloc_obj(*req, GFP_NOIO);
if (!req)
- return;
+ return -ENOMEM;
bio = bio_alloc(zram->bdev, 1, parent->bi_opf, GFP_NOIO);
if (!bio) {
kfree(req);
- return;
+ return -ENOMEM;
}
req->zram = zram;
@@ -1459,6 +1457,8 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
__bio_add_page(bio, page, PAGE_SIZE, 0);
bio_inc_remaining(parent);
submit_bio(bio);
+
+ return 0;
}
static void zram_sync_read(struct work_struct *w)
@@ -1507,8 +1507,7 @@ static int read_from_bdev(struct zram *zram, struct page *page, u32 index,
return -EIO;
return read_from_bdev_sync(zram, page, index, blk_idx);
}
- read_from_bdev_async(zram, page, index, blk_idx, parent);
- return 0;
+ return read_from_bdev_async(zram, page, index, blk_idx, parent);
}
#else
static inline void reset_bdev(struct zram *zram) {};
@@ -1619,45 +1618,62 @@ static void zram_debugfs_register(struct zram *zram) {};
static void zram_debugfs_unregister(struct zram *zram) {};
#endif
-static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg)
+/* Only algo parameter given, lookup by algo name */
+static int lookup_algo_priority(struct zram *zram, const char *algo,
+ u32 min_prio)
{
- /* Do not free statically defined compression algorithms */
- if (zram->comp_algs[prio] != default_compressor)
- kfree(zram->comp_algs[prio]);
+ s32 prio;
+
+ for (prio = min_prio; prio < ZRAM_MAX_COMPS; prio++) {
+ if (!zram->comp_algs[prio])
+ continue;
+ if (!strcmp(zram->comp_algs[prio], algo))
+ return prio;
+ }
+
+ return -EINVAL;
+}
+
+/* Both algo and priority parameters given, validate them */
+static int validate_algo_priority(struct zram *zram, const char *algo, u32 prio)
+{
+ if (prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ /* No algo at given priority */
+ if (!zram->comp_algs[prio])
+ return -EINVAL;
+ /* A different algo at given priority */
+ if (strcmp(zram->comp_algs[prio], algo))
+ return -EINVAL;
+ return 0;
+}
+
+static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg)
+{
zram->comp_algs[prio] = alg;
}
static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
{
- char *compressor;
+ const char *alg;
size_t sz;
sz = strlen(buf);
if (sz >= ZRAM_MAX_ALGO_NAME_SZ)
return -E2BIG;
- compressor = kstrdup(buf, GFP_KERNEL);
- if (!compressor)
- return -ENOMEM;
-
- /* ignore trailing newline */
- if (sz > 0 && compressor[sz - 1] == '\n')
- compressor[sz - 1] = 0x00;
-
- if (!zcomp_available_algorithm(compressor)) {
- kfree(compressor);
+ alg = zcomp_lookup_backend_name(buf);
+ if (!alg)
return -EINVAL;
- }
guard(rwsem_write)(&zram->dev_lock);
if (init_done(zram)) {
- kfree(compressor);
pr_info("Can't change algorithm for initialized device\n");
return -EBUSY;
}
- comp_algorithm_set(zram, prio, compressor);
+ comp_algorithm_set(zram, prio, alg);
return 0;
}
@@ -1705,6 +1721,7 @@ static ssize_t algorithm_params_store(struct device *dev,
char *args, *param, *val, *algo = NULL, *dict_path = NULL;
struct deflate_params deflate_params;
struct zram *zram = dev_to_zram(dev);
+ bool prio_param = false;
int ret;
deflate_params.winbits = ZCOMP_PARAM_NOT_SET;
@@ -1717,6 +1734,7 @@ static ssize_t algorithm_params_store(struct device *dev,
return -EINVAL;
if (!strcmp(param, "priority")) {
+ prio_param = true;
ret = kstrtoint(val, 10, &prio);
if (ret)
return ret;
@@ -1748,24 +1766,26 @@ static ssize_t algorithm_params_store(struct device *dev,
}
}
- /* Lookup priority by algorithm name */
- if (algo) {
- s32 p;
+ guard(rwsem_write)(&zram->dev_lock);
+ if (init_done(zram))
+ return -EBUSY;
- prio = -EINVAL;
- for (p = ZRAM_PRIMARY_COMP; p < ZRAM_MAX_COMPS; p++) {
- if (!zram->comp_algs[p])
- continue;
+ if (prio_param) {
+ if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ }
- if (!strcmp(zram->comp_algs[p], algo)) {
- prio = p;
- break;
- }
- }
+ if (algo && prio_param) {
+ ret = validate_algo_priority(zram, algo, prio);
+ if (ret)
+ return ret;
}
- if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
- return -EINVAL;
+ if (algo && !prio_param) {
+ prio = lookup_algo_priority(zram, algo, ZRAM_PRIMARY_COMP);
+ if (prio < 0)
+ return -EINVAL;
+ }
ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
return ret ? ret : len;
@@ -2334,8 +2354,20 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
#define RECOMPRESS_IDLE (1 << 0)
#define RECOMPRESS_HUGE (1 << 1)
-static int scan_slots_for_recompress(struct zram *zram, u32 mode, u32 prio_max,
- struct zram_pp_ctl *ctl)
+static bool highest_priority_algorithm(struct zram *zram, u32 prio)
+{
+ u32 p;
+
+ for (p = prio + 1; p < ZRAM_MAX_COMPS; p++) {
+ if (zram->comp_algs[p])
+ return false;
+ }
+
+ return true;
+}
+
+static void scan_slots_for_recompress(struct zram *zram, u32 mode, u32 prio,
+ struct zram_pp_ctl *ctl)
{
unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
unsigned long index;
@@ -2360,8 +2392,8 @@ static int scan_slots_for_recompress(struct zram *zram, u32 mode, u32 prio_max,
test_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE))
goto next;
- /* Already compressed with same of higher priority */
- if (get_slot_comp_priority(zram, index) + 1 >= prio_max)
+ /* Already compressed with same or higher priority */
+ if (get_slot_comp_priority(zram, index) >= prio)
goto next;
ok = place_pp_slot(zram, ctl, index);
@@ -2370,8 +2402,6 @@ next:
if (!ok)
break;
}
-
- return 0;
}
/*
@@ -2382,8 +2412,7 @@ next:
* Corresponding ZRAM slot should be locked.
*/
static int recompress_slot(struct zram *zram, u32 index, struct page *page,
- u64 *num_recomp_pages, u32 threshold, u32 prio,
- u32 prio_max)
+ u64 *num_recomp_pages, u32 threshold, u32 prio)
{
struct zcomp_strm *zstrm = NULL;
unsigned long handle_old;
@@ -2417,51 +2446,10 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page,
*/
clear_slot_flag(zram, index, ZRAM_IDLE);
- class_index_old = zs_lookup_class_index(zram->mem_pool, comp_len_old);
-
- prio = max(prio, get_slot_comp_priority(zram, index) + 1);
- /*
- * Recompression slots scan should not select slots that are
- * already compressed with a higher priority algorithm, but
- * just in case
- */
- if (prio >= prio_max)
- return 0;
-
- /*
- * Iterate the secondary comp algorithms list (in order of priority)
- * and try to recompress the page.
- */
- for (; prio < prio_max; prio++) {
- if (!zram->comps[prio])
- continue;
-
- zstrm = zcomp_stream_get(zram->comps[prio]);
- src = kmap_local_page(page);
- ret = zcomp_compress(zram->comps[prio], zstrm,
- src, &comp_len_new);
- kunmap_local(src);
-
- if (ret) {
- zcomp_stream_put(zstrm);
- zstrm = NULL;
- break;
- }
-
- class_index_new = zs_lookup_class_index(zram->mem_pool,
- comp_len_new);
-
- /* Continue until we make progress */
- if (class_index_new >= class_index_old ||
- (threshold && comp_len_new >= threshold)) {
- zcomp_stream_put(zstrm);
- zstrm = NULL;
- continue;
- }
-
- /* Recompression was successful so break out */
- break;
- }
+ zstrm = zcomp_stream_get(zram->comps[prio]);
+ src = kmap_local_page(page);
+ ret = zcomp_compress(zram->comps[prio], zstrm, src, &comp_len_new);
+ kunmap_local(src);
/*
* Decrement the limit (if set) on pages we can recompress, even
@@ -2472,21 +2460,27 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page,
if (*num_recomp_pages)
*num_recomp_pages -= 1;
- /* Compression error */
- if (ret)
+ if (ret) {
+ zcomp_stream_put(zstrm);
return ret;
+ }
+
+ class_index_old = zs_lookup_class_index(zram->mem_pool, comp_len_old);
+ class_index_new = zs_lookup_class_index(zram->mem_pool, comp_len_new);
+
+ if (class_index_new >= class_index_old ||
+ (threshold && comp_len_new >= threshold)) {
+ zcomp_stream_put(zstrm);
- if (!zstrm) {
/*
* Secondary algorithms failed to re-compress the page
* in a way that would save memory.
*
- * Mark the object incompressible if the max-priority
- * algorithm couldn't re-compress it.
+ * Mark the object incompressible if the max-priority (the
+ * last configured one) algorithm couldn't re-compress it.
*/
- if (prio < zram->num_active_comps)
- return 0;
- set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
+ if (highest_priority_algorithm(zram, prio))
+ set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
return 0;
}
@@ -2531,15 +2525,13 @@ static ssize_t recompress_store(struct device *dev,
char *args, *param, *val, *algo = NULL;
u64 num_recomp_pages = ULLONG_MAX;
struct zram_pp_ctl *ctl = NULL;
- struct zram_pp_slot *pps;
+ s32 prio = ZRAM_SECONDARY_COMP;
u32 mode = 0, threshold = 0;
- u32 prio, prio_max;
+ struct zram_pp_slot *pps;
struct page *page = NULL;
+ bool prio_param = false;
ssize_t ret;
- prio = ZRAM_SECONDARY_COMP;
- prio_max = zram->num_active_comps;
-
args = skip_spaces(buf);
while (*args) {
args = next_arg(args, &param, &val);
@@ -2585,14 +2577,10 @@ static ssize_t recompress_store(struct device *dev,
}
if (!strcmp(param, "priority")) {
- ret = kstrtouint(val, 10, &prio);
+ prio_param = true;
+ ret = kstrtoint(val, 10, &prio);
if (ret)
return ret;
-
- if (prio == ZRAM_PRIMARY_COMP)
- prio = ZRAM_SECONDARY_COMP;
-
- prio_max = prio + 1;
continue;
}
}
@@ -2604,32 +2592,26 @@ static ssize_t recompress_store(struct device *dev,
if (!init_done(zram))
return -EINVAL;
- if (algo) {
- bool found = false;
-
- for (; prio < ZRAM_MAX_COMPS; prio++) {
- if (!zram->comp_algs[prio])
- continue;
-
- if (!strcmp(zram->comp_algs[prio], algo)) {
- prio_max = prio + 1;
- found = true;
- break;
- }
- }
+ if (prio_param) {
+ if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ }
- if (!found) {
- ret = -EINVAL;
- goto out;
- }
+ if (algo && prio_param) {
+ ret = validate_algo_priority(zram, algo, prio);
+ if (ret)
+ return ret;
}
- prio_max = min(prio_max, (u32)zram->num_active_comps);
- if (prio >= prio_max) {
- ret = -EINVAL;
- goto out;
+ if (algo && !prio_param) {
+ prio = lookup_algo_priority(zram, algo, ZRAM_SECONDARY_COMP);
+ if (prio < 0)
+ return -EINVAL;
}
+ if (!zram->comps[prio])
+ return -EINVAL;
+
page = alloc_page(GFP_KERNEL);
if (!page) {
ret = -ENOMEM;
@@ -2642,7 +2624,7 @@ static ssize_t recompress_store(struct device *dev,
goto out;
}
- scan_slots_for_recompress(zram, mode, prio_max, ctl);
+ scan_slots_for_recompress(zram, mode, prio, ctl);
ret = len;
while ((pps = select_pp_slot(ctl))) {
@@ -2656,8 +2638,7 @@ static ssize_t recompress_store(struct device *dev,
goto next;
err = recompress_slot(zram, pps->index, page,
- &num_recomp_pages, threshold,
- prio, prio_max);
+ &num_recomp_pages, threshold, prio);
next:
slot_unlock(zram, pps->index);
release_pp_slot(zram, pps);
@@ -2837,15 +2818,10 @@ static void zram_destroy_comps(struct zram *zram)
if (!comp)
continue;
zcomp_destroy(comp);
- zram->num_active_comps--;
}
- for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
- /* Do not free statically defined compression algorithms */
- if (zram->comp_algs[prio] != default_compressor)
- kfree(zram->comp_algs[prio]);
+ for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++)
zram->comp_algs[prio] = NULL;
- }
zram_comp_params_reset(zram);
}
@@ -2906,7 +2882,6 @@ static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
}
zram->comps[prio] = comp;
- zram->num_active_comps++;
}
zram->disksize = disksize;
set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT);
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index f0de8f8218f5..08d1774c15db 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -125,7 +125,6 @@ struct zram {
*/
u64 disksize; /* bytes */
const char *comp_algs[ZRAM_MAX_COMPS];
- s8 num_active_comps;
/*
* zram is claimed so open request will be failed
*/