From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF0EF1FCFF5 for ; Mon, 27 Jan 2025 07:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962988; cv=none; b=i60zPvdH9u9GDwBxZteuUJZYQAlXAUPCVPg5zWJ8fvKClRFuDo9v3OpvbtLzokeB5CtY4VmhJgQIQJb0KJt1pctn+IjxW5T/2aTGxYWxtSQLyx/0gIaBjAUrp3WeE8f0R3u0X7IYcpTdPBoK/G0P40oidNLb7Z/DAD4wKuNe6gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962988; c=relaxed/simple; bh=EZa/W2dQAjJcOVTq1x/07GV7agrI/FKT6fi+vfFRaHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4AkT+WnQpE3pKdM1q931Acps8ujwWwF+Bbu/5MmKwGsdtc0X+KCVUOeNPk/GXBWkQrhCxhaoIjX/3SuofLhZBGD+qT+7KRbnztbiunuAOxUv8dO/2uTLePDkJLI6h26p3v5uCqICAJ4UGgWRjBYlmhO7FO3tJ1tB0Jwn4KpRPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=djTZfzzw; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="djTZfzzw" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21619108a6bso67640815ad.3 for ; Sun, 26 Jan 2025 23:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737962986; x=1738567786; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q566LymSR3yLFFaT+LJFKvYojLsB2mtA0so6QzTzlYU=; b=djTZfzzw8+RGjXxwsuAZ1JdDhXNVGtUCGH2cGptEvIFF8slYR+D1ZRp+j6loZH/X3b 7IbwKSPtETYxiaL1Xx9Oj+3kGbrNOYq46Lonr+eKPBEZT16pvuA2lmK236XzNvN0zJrY n39YCzoB/zJU5pX85BUl5qIPvb3DfKDTE8IiU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737962986; x=1738567786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q566LymSR3yLFFaT+LJFKvYojLsB2mtA0so6QzTzlYU=; b=w1yVm+OJDepQIV09ZdkaRlDT0E9SbAfAeQvk18Lf6FEYec7kINFJJNRGCfRv30GDE/ LxlOqUTvaoNn5Nngf1usHfO2AcC09WrbpK9CZie5X6HNALCrmiAksi8Oid79kQyzFvdi tmiW6jdg/3FANuOMuljsCamASM+WCwAtNpoyZQ8nPxr/ImDKSpQikr+I5f0Zjuzm/UJS k+kE6F75kHFTdxnlEzgaMrWhXocVjP3Bb1rJHATNGvUO23MlmTd/kJDFmx7I4YnhOtQ1 uig9edUF44x+Dq/OYFIjgSwdKECdjutyPSj9S1AXatDD1zO/kWlWrFfa+lOk4hgBtbXM wUUQ== X-Forwarded-Encrypted: i=1; AJvYcCV86+1BIco20yBHCEEDtkPwIXq6Tb7sP+Sc1wmD+LzuDs3M1V2p8cNQA8OiRLG1nFsfoOarPzNZbAHgA+s=@vger.kernel.org X-Gm-Message-State: AOJu0YxrPkt9Rn+xTITX6xqit3k5FQMr4VbOYwhzc1FGKPh67hsjtS9+ USd7kiOp/6Kg57NCS/DjxxmGsVSVmHnIKd5nJq1rpS/FM/dfuv8NtjDrCgKIxQ== X-Gm-Gg: ASbGncudtZLyPM976XfkTEzIVSsGt6qQ5MUW9s75tNpS2fR72nVAqO4V8dAiP521Ebb enpoX4bO/ZmL9/r4e1sRXpIKP7KXUJaYW3psadPVinJK1POqMNf0AI8utGxb1PMTRlD83a5Y8x4 1W5x8WSidvwKPI9m+VqMkm6JZd+C7fE+DsXROuY2gsYz7Mfx3E+xTnDER9UCxXZJ2I9iJ4Srzvq DmnbjlSfirlUjEZ9o+zkBIHTfVsDuMaJZfPlQvxF8D+8ZtZBhPnv3OgykswH/n0HH9U58YI7D0+ 5CrH6/s= X-Google-Smtp-Source: AGHT+IHWGcaKLW0ar/9axezARL9DLtAwfcGy5WchQ6brciU9TbvtbSpVRLYsS13AacDLWO3sj1eyFw== X-Received: by 2002:a05:6a00:8013:b0:725:8c0f:6fa3 with SMTP id d2e1a72fcca58-72dafbaae38mr52843068b3a.22.1737962986053; Sun, 26 Jan 2025 23:29:46 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a69f41esm6319379b3a.31.2025.01.26.23.29.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:29:45 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 1/9] zram: switch to non-atomic entry locking Date: Mon, 27 Jan 2025 16:29:12 +0900 Message-ID: <20250127072932.1289973-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Concurrent modifications of meta table entries is now handled by per-entry spin-lock. This has a number of shortcomings. First, this imposes atomic requirements on compression backends. zram can call both zcomp_compress() and zcomp_decompress() under entry spin-lock, which implies that we can use only compression algorithms that don't schedule/sleep/wait during compression and decompression. This, for instance, makes it impossible to use some of the ASYNC compression algorithms (H/W compression, etc.) implementations. Second, this can potentially trigger watchdogs. For example, entry re-compression with secondary algorithms is performed under entry spin-lock. Given that we chain secondary compression algorithms and that some of them can be configured for best compression ratio (and worst compression speed) zram can stay under spin-lock for quite some time. Do not use per-entry spin-locks and instead convert it to an atomic_t variable which open codes reader-writer type of lock. This permits preemption from slot_lock section. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 155 +++++++++++++++++++++------------- drivers/block/zram/zram_drv.h | 7 +- 2 files changed, 98 insertions(+), 64 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9f5020b077c5..14859bd2611f 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -58,19 +58,57 @@ static void zram_free_page(struct zram *zram, size_t in= dex); static int zram_read_from_zspool(struct zram *zram, struct page *page, u32 index); =20 -static int zram_slot_trylock(struct zram *zram, u32 index) +static int zram_slot_write_trylock(struct zram *zram, u32 index) { - return spin_trylock(&zram->table[index].lock); + int old; + + old =3D atomic_cmpxchg(&zram->table[index].lock, ZRAM_ENTRY_UNLOCKED, + ZRAM_ENTRY_WRLOCKED); + return old =3D=3D ZRAM_ENTRY_UNLOCKED; } =20 -static void zram_slot_lock(struct zram *zram, u32 index) +static void zram_slot_write_lock(struct zram *zram, u32 index) { - spin_lock(&zram->table[index].lock); + atomic_t *lock =3D &zram->table[index].lock; + int old; + + while (1) { + old =3D atomic_cmpxchg(lock, ZRAM_ENTRY_UNLOCKED, + ZRAM_ENTRY_WRLOCKED); + if (old =3D=3D ZRAM_ENTRY_UNLOCKED) + return; + + cond_resched(); + } } =20 -static void zram_slot_unlock(struct zram *zram, u32 index) +static void zram_slot_write_unlock(struct zram *zram, u32 index) { - spin_unlock(&zram->table[index].lock); + atomic_set(&zram->table[index].lock, ZRAM_ENTRY_UNLOCKED); +} + +static void zram_slot_read_lock(struct zram *zram, u32 index) +{ + atomic_t *lock =3D &zram->table[index].lock; + int old; + + while (1) { + old =3D atomic_read(lock); + if (old =3D=3D ZRAM_ENTRY_WRLOCKED) { + cond_resched(); + continue; + } + + if (atomic_cmpxchg(lock, old, old + 1) =3D=3D old) + return; + + cond_resched(); + } +} + +static void zram_slot_read_unlock(struct zram *zram, u32 index) +{ + atomic_dec(&zram->table[index].lock); } =20 static inline bool init_done(struct zram *zram) @@ -93,7 +131,6 @@ static void zram_set_handle(struct zram *zram, u32 index= , unsigned long handle) zram->table[index].handle =3D handle; } =20 -/* flag operations require table entry bit_spin_lock() being held */ static bool zram_test_flag(struct zram *zram, u32 index, enum zram_pageflags flag) { @@ -229,9 +266,9 @@ static void release_pp_slot(struct zram *zram, struct z= ram_pp_slot *pps) { list_del_init(&pps->entry); =20 - zram_slot_lock(zram, pps->index); + zram_slot_write_lock(zram, pps->index); zram_clear_flag(zram, pps->index, ZRAM_PP_SLOT); - zram_slot_unlock(zram, pps->index); + zram_slot_write_unlock(zram, pps->index); =20 kfree(pps); } @@ -394,11 +431,11 @@ static void mark_idle(struct zram *zram, ktime_t cuto= ff) * * And ZRAM_WB slots simply cannot be ZRAM_IDLE. */ - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); if (!zram_allocated(zram, index) || zram_test_flag(zram, index, ZRAM_WB) || zram_test_flag(zram, index, ZRAM_SAME)) { - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); continue; } =20 @@ -410,7 +447,7 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) zram_set_flag(zram, index, ZRAM_IDLE); else zram_clear_flag(zram, index, ZRAM_IDLE); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); } } =20 @@ -709,7 +746,7 @@ static int scan_slots_for_writeback(struct zram *zram, = u32 mode, =20 INIT_LIST_HEAD(&pps->entry); =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); if (!zram_allocated(zram, index)) goto next; =20 @@ -731,7 +768,7 @@ static int scan_slots_for_writeback(struct zram *zram, = u32 mode, place_pp_slot(zram, ctl, pps); pps =3D NULL; next: - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); } =20 kfree(pps); @@ -822,7 +859,7 @@ static ssize_t writeback_store(struct device *dev, } =20 index =3D pps->index; - zram_slot_lock(zram, index); + zram_slot_read_lock(zram, index); /* * scan_slots() sets ZRAM_PP_SLOT and relases slot lock, so * slots can change in the meantime. If slots are accessed or @@ -833,7 +870,7 @@ static ssize_t writeback_store(struct device *dev, goto next; if (zram_read_from_zspool(zram, page, index)) goto next; - zram_slot_unlock(zram, index); + zram_slot_read_unlock(zram, index); =20 bio_init(&bio, zram->bdev, &bio_vec, 1, REQ_OP_WRITE | REQ_SYNC); @@ -860,7 +897,7 @@ static ssize_t writeback_store(struct device *dev, } =20 atomic64_inc(&zram->stats.bd_writes); - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); /* * Same as above, we release slot lock during writeback so * slot can change under us: slot_free() or slot_free() and @@ -882,7 +919,7 @@ static ssize_t writeback_store(struct device *dev, zram->bd_wb_limit -=3D 1UL << (PAGE_SHIFT - 12); spin_unlock(&zram->wb_limit_lock); next: - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); release_pp_slot(zram, pps); =20 cond_resched(); @@ -1001,7 +1038,7 @@ static ssize_t read_block_state(struct file *file, ch= ar __user *buf, for (index =3D *ppos; index < nr_pages; index++) { int copied; =20 - zram_slot_lock(zram, index); + zram_slot_read_lock(zram, index); if (!zram_allocated(zram, index)) goto next; =20 @@ -1019,13 +1056,13 @@ static ssize_t read_block_state(struct file *file, = char __user *buf, ZRAM_INCOMPRESSIBLE) ? 'n' : '.'); =20 if (count <=3D copied) { - zram_slot_unlock(zram, index); + zram_slot_read_unlock(zram, index); break; } written +=3D copied; count -=3D copied; next: - zram_slot_unlock(zram, index); + zram_slot_read_unlock(zram, index); *ppos +=3D 1; } =20 @@ -1455,33 +1492,31 @@ static void zram_meta_free(struct zram *zram, u64 d= isksize) =20 static bool zram_meta_alloc(struct zram *zram, u64 disksize) { - size_t num_pages, index; + size_t num_ents, index; =20 - num_pages =3D disksize >> PAGE_SHIFT; - zram->table =3D vzalloc(array_size(num_pages, sizeof(*zram->table))); + num_ents =3D disksize >> PAGE_SHIFT; + zram->table =3D vzalloc(array_size(num_ents, sizeof(*zram->table))); if (!zram->table) - return false; + goto error; =20 zram->mem_pool =3D zs_create_pool(zram->disk->disk_name); - if (!zram->mem_pool) { - vfree(zram->table); - zram->table =3D NULL; - return false; - } + if (!zram->mem_pool) + goto error; =20 if (!huge_class_size) huge_class_size =3D zs_huge_class_size(zram->mem_pool); =20 - for (index =3D 0; index < num_pages; index++) - spin_lock_init(&zram->table[index].lock); + for (index =3D 0; index < num_ents; index++) + atomic_set(&zram->table[index].lock, ZRAM_ENTRY_UNLOCKED); + return true; + +error: + vfree(zram->table); + zram->table =3D NULL; + return false; } =20 -/* - * To protect concurrent access to the same index entry, - * caller should hold this table index entry's bit_spinlock to - * indicate this index entry is accessing. - */ static void zram_free_page(struct zram *zram, size_t index) { unsigned long handle; @@ -1602,17 +1637,17 @@ static int zram_read_page(struct zram *zram, struct= page *page, u32 index, { int ret; =20 - zram_slot_lock(zram, index); + zram_slot_read_lock(zram, index); if (!zram_test_flag(zram, index, ZRAM_WB)) { /* Slot should be locked through out the function call */ ret =3D zram_read_from_zspool(zram, page, index); - zram_slot_unlock(zram, index); + zram_slot_read_unlock(zram, index); } else { /* * The slot should be unlocked before reading from the backing * device. */ - zram_slot_unlock(zram, index); + zram_slot_read_unlock(zram, index); =20 ret =3D read_from_bdev(zram, page, zram_get_handle(zram, index), parent); @@ -1655,10 +1690,10 @@ static int zram_bvec_read(struct zram *zram, struct= bio_vec *bvec, static int write_same_filled_page(struct zram *zram, unsigned long fill, u32 index) { - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_set_flag(zram, index, ZRAM_SAME); zram_set_handle(zram, index, fill); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 atomic64_inc(&zram->stats.same_pages); atomic64_inc(&zram->stats.pages_stored); @@ -1693,11 +1728,11 @@ static int write_incompressible_page(struct zram *z= ram, struct page *page, kunmap_local(src); zs_unmap_object(zram->mem_pool, handle); =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_set_flag(zram, index, ZRAM_HUGE); zram_set_handle(zram, index, handle); zram_set_obj_size(zram, index, PAGE_SIZE); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 atomic64_add(PAGE_SIZE, &zram->stats.compr_data_size); atomic64_inc(&zram->stats.huge_pages); @@ -1718,9 +1753,9 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) bool same_filled; =20 /* First, free memory allocated to this slot (if any) */ - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_free_page(zram, index); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 mem =3D kmap_local_page(page); same_filled =3D page_same_filled(mem, &element); @@ -1790,10 +1825,10 @@ static int zram_write_page(struct zram *zram, struc= t page *page, u32 index) zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); zs_unmap_object(zram->mem_pool, handle); =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_set_handle(zram, index, handle); zram_set_obj_size(zram, index, comp_len); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 /* Update stats */ atomic64_inc(&zram->stats.pages_stored); @@ -1850,7 +1885,7 @@ static int scan_slots_for_recompress(struct zram *zra= m, u32 mode, =20 INIT_LIST_HEAD(&pps->entry); =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); if (!zram_allocated(zram, index)) goto next; =20 @@ -1871,7 +1906,7 @@ static int scan_slots_for_recompress(struct zram *zra= m, u32 mode, place_pp_slot(zram, ctl, pps); pps =3D NULL; next: - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); } =20 kfree(pps); @@ -2162,7 +2197,7 @@ static ssize_t recompress_store(struct device *dev, if (!num_recomp_pages) break; =20 - zram_slot_lock(zram, pps->index); + zram_slot_write_lock(zram, pps->index); if (!zram_test_flag(zram, pps->index, ZRAM_PP_SLOT)) goto next; =20 @@ -2170,7 +2205,7 @@ static ssize_t recompress_store(struct device *dev, &num_recomp_pages, threshold, prio, prio_max); next: - zram_slot_unlock(zram, pps->index); + zram_slot_write_unlock(zram, pps->index); release_pp_slot(zram, pps); =20 if (err) { @@ -2217,9 +2252,9 @@ static void zram_bio_discard(struct zram *zram, struc= t bio *bio) } =20 while (n >=3D PAGE_SIZE) { - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_free_page(zram, index); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); atomic64_inc(&zram->stats.notify_free); index++; n -=3D PAGE_SIZE; @@ -2248,9 +2283,9 @@ static void zram_bio_read(struct zram *zram, struct b= io *bio) } flush_dcache_page(bv.bv_page); =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_accessed(zram, index); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 bio_advance_iter_single(bio, &iter, bv.bv_len); } while (iter.bi_size); @@ -2278,9 +2313,9 @@ static void zram_bio_write(struct zram *zram, struct = bio *bio) break; } =20 - zram_slot_lock(zram, index); + zram_slot_write_lock(zram, index); zram_accessed(zram, index); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); =20 bio_advance_iter_single(bio, &iter, bv.bv_len); } while (iter.bi_size); @@ -2321,13 +2356,13 @@ static void zram_slot_free_notify(struct block_devi= ce *bdev, zram =3D bdev->bd_disk->private_data; =20 atomic64_inc(&zram->stats.notify_free); - if (!zram_slot_trylock(zram, index)) { + if (!zram_slot_write_trylock(zram, index)) { atomic64_inc(&zram->stats.miss_free); return; } =20 zram_free_page(zram, index); - zram_slot_unlock(zram, index); + zram_slot_write_unlock(zram, index); } =20 static void zram_comp_params_reset(struct zram *zram) diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index db78d7c01b9a..3436ddf8ab23 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -15,7 +15,6 @@ #ifndef _ZRAM_DRV_H_ #define _ZRAM_DRV_H_ =20 -#include #include #include =20 @@ -28,7 +27,6 @@ #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \ (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT)) =20 - /* * ZRAM is mainly used for memory efficiency so we want to keep memory * footprint small and thus squeeze size and zram pageflags into a flags @@ -58,13 +56,14 @@ enum zram_pageflags { __NR_ZRAM_PAGEFLAGS, }; =20 -/*-- Data structures */ +#define ZRAM_ENTRY_UNLOCKED 0 +#define ZRAM_ENTRY_WRLOCKED (-1) =20 /* Allocated for each disk page */ struct zram_table_entry { unsigned long handle; unsigned int flags; - spinlock_t lock; + atomic_t lock; #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME ktime_t ac_time; #endif --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 023AB1FCCFF for ; Mon, 27 Jan 2025 07:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962993; cv=none; b=DlRATcOrdwzc5Ihy5jHsgMBtEtnWiNgojLdBOB2OmkvuyL5Idke6QZT3UeSHe6VA5OMalr8fbz61AhjPdVGitp5iUZYvtcT1eIo3c8q2wF6gVopSRs4vdjnt9WAkTvargNFe4LwEFHB+1//arf+96MeS/FkQIZ1iR43EE2xIEko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962993; c=relaxed/simple; bh=PhOW5pj8bTcYqwnl7MvQUZ1kANLbo+r8PXRaqc1lxmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PU8DL6u803xhOgl+Dl1hqLDNzkbifmqJBQ/NeI626SUR7USV7GZQKBLcJqmU/uN7ao3cDib0tXmpJz5m3Mw4rSFRCDJXzJQyFzOckG9Vxu6jtcPb9QtF7niR4XvysG/xwSMBVlweb3h5FhC0Ex8xej/m3pprDC5fuHbEscoMAgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=FJ8dM9F3; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FJ8dM9F3" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ee50ffcf14so7914836a91.0 for ; Sun, 26 Jan 2025 23:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737962991; x=1738567791; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J0265o4fXtEfPILxc30ZTaArQv74vpUz9xkcp3pdNNI=; b=FJ8dM9F3u9I3CZh4gLTQaygOfJUHBkQFkU1ss6yBY7kRFw/qUdEp7NeS74Gs+7hwhv U7Fz5cyQarxWfsZdI7a4wGOiy0UHq5pYVPXw7wEA/0m6Fe5LdJEeAS/hsJ6EIvE1PwLG hEIqeillLVmF5KUZL0zKPSTc8dxOfSq8YnyXw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737962991; x=1738567791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J0265o4fXtEfPILxc30ZTaArQv74vpUz9xkcp3pdNNI=; b=ryVC6kbHsHQvDF81kRerii5IzPmMxN+kAUEviRxcp5k+gttTaNJHE+QDExY2yG8scH E/jrmbeNWc0a+YSXsyMb1Td7ZYIvMnBBpd+PKoQCNYqQcq5fEySiMf5wKkugv4WY5hGj FGlBrV6tiae06eYZdK9QOA+Rld2xMcQthQNEFiwNugrgpatgxsi49h5eDDqiiegzSSZ6 U8Y2uAsWn2GV/w31z4Eh6ccUqNQ6GBGE56HPW5Bc2rtCqw7pc6phhCf49Cz/yE0I1dR2 qt/f5NYcH2MhF0/9xdkT2szHSmewRC1MygFBtiKFpt4ICgJFtplDnAtKiobAg+CflaCx ignw== X-Forwarded-Encrypted: i=1; AJvYcCUXGAgZuhpPMEvEzxPUVRfQZsC1ioJk2qdZjm+9jfXWVu2UcOL7lFCZkyX5uIZe1cK2pc/cT/5QlU9eRo8=@vger.kernel.org X-Gm-Message-State: AOJu0YxD5dNDVeGeLd0a3x9Pa57wIO4tB7OOOO9PVf9iCXkmw7pTyan4 aCr02LE8ffbTZyHOf23uB1sU6dBsEEEd2niWg7fmbNa0ACkb71fHxMM9To0sEw== X-Gm-Gg: ASbGncu48+BejErauBm19XglANcMe7TlywP0TWYcwCsZpjnWJHt1pncmm5jOY2Y0ZK9 p4DPQQP9BPi/NGRP2fhCTdGHKZ01Le6GpBvWl8w2FhqI85X51R3IQMvySjiXAkCVhrUO7XtO8e7 o6N0GFCg4JZeafcxriRjpkK4OOgpJgzhTjdnrVNLLvt5i6C+0t31Vae/kSWiDws43mo4cs69fHk 0YmmvwSYtYS+pMeKhgS+R+e4yREdmC1GX2/kjWx7Us8GmXxbVUDkvwq0cGVcCDr2iYSxCGdOKHy qxR8Uyo= X-Google-Smtp-Source: AGHT+IFSyrUoBu0dmirDsCNwBpWN0PP0zKexAyYjhwQ6BiECY+L1XRsV9WJ0VUAZ72LIigkZJ+PQTw== X-Received: by 2002:a17:90b:5488:b0:2ee:7e53:bfae with SMTP id 98e67ed59e1d1-2f7f177c6b3mr25160506a91.10.1737962991164; Sun, 26 Jan 2025 23:29:51 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffaf8f03sm6352175a91.39.2025.01.26.23.29.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:29:50 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 2/9] zram: do not use per-CPU compression streams Date: Mon, 27 Jan 2025 16:29:13 +0900 Message-ID: <20250127072932.1289973-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Similarly to per-entry spin-lock per-CPU compression streams also have a number of shortcoming. First, per-CPU stream access has to be done from a non-preemptible (atomic) section, which imposes the same atomicity requirements on compression backends as entry spin-lock do and makes it impossible to use algorithms that can schedule/wait/sleep during compression and decompression. Second, per-CPU streams noticeably increase memory usage (actually more like wastage) of secondary compression streams. The problem is that secondary compression streams are allocated per-CPU, just like the primary streams are. Yet we never use more that one secondary stream at a time, because recompression is a single threaded action. Which means that remaining num_online_cpu() - 1 streams are allocated for nothing, and this is per-priority list (we can have several secondary compression algorithms). Depending on the algorithm this may lead to a significant memory wastage, in addition each stream also carries a workmem buffer (2 physical pages). Instead of per-CPU streams, maintain a list of idle compression streams and allocate new streams on-demand (something that we used to do many years ago). So that zram read() and write() become non-atomic and ease requirements on the compression algorithm implementation. This also means that we now should have only one secondary stream per-priority list. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 164 +++++++++++++++++++--------------- drivers/block/zram/zcomp.h | 17 ++-- drivers/block/zram/zram_drv.c | 29 +++--- include/linux/cpuhotplug.h | 1 - 4 files changed, 109 insertions(+), 102 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index bb514403e305..982c769d5831 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include =20 @@ -43,31 +43,40 @@ static const struct zcomp_ops *backends[] =3D { NULL }; =20 -static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) +static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *strm) { - comp->ops->destroy_ctx(&zstrm->ctx); - vfree(zstrm->buffer); - zstrm->buffer =3D NULL; + comp->ops->destroy_ctx(&strm->ctx); + vfree(strm->buffer); + kfree(strm); } =20 -static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) +static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp) { + struct zcomp_strm *strm; int ret; =20 - ret =3D comp->ops->create_ctx(comp->params, &zstrm->ctx); - if (ret) - return ret; + strm =3D kzalloc(sizeof(*strm), GFP_KERNEL); + if (!strm) + return NULL; + + INIT_LIST_HEAD(&strm->entry); + + ret =3D comp->ops->create_ctx(comp->params, &strm->ctx); + if (ret) { + kfree(strm); + return NULL; + } =20 /* - * allocate 2 pages. 1 for compressed data, plus 1 extra for the - * case when compressed size is larger than the original one + * allocate 2 pages. 1 for compressed data, plus 1 extra in case if + * compressed data is larger than the original one. */ - zstrm->buffer =3D vzalloc(2 * PAGE_SIZE); - if (!zstrm->buffer) { - zcomp_strm_free(comp, zstrm); - return -ENOMEM; + strm->buffer =3D vzalloc(2 * PAGE_SIZE); + if (!strm->buffer) { + zcomp_strm_free(comp, strm); + return NULL; } - return 0; + return strm; } =20 static const struct zcomp_ops *lookup_backend_ops(const char *comp) @@ -109,13 +118,59 @@ ssize_t zcomp_available_show(const char *comp, char *= buf) =20 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) { - local_lock(&comp->stream->lock); - return this_cpu_ptr(comp->stream); + struct zcomp_strm *strm; + + might_sleep(); + + while (1) { + spin_lock(&comp->strm_lock); + if (!list_empty(&comp->idle_strm)) { + strm =3D list_first_entry(&comp->idle_strm, + struct zcomp_strm, + entry); + list_del(&strm->entry); + spin_unlock(&comp->strm_lock); + return strm; + } + + /* cannot allocate new stream, wait for an idle one */ + if (comp->avail_strm >=3D num_online_cpus()) { + spin_unlock(&comp->strm_lock); + wait_event(comp->strm_wait, + !list_empty(&comp->idle_strm)); + continue; + } + + /* allocate new stream */ + comp->avail_strm++; + spin_unlock(&comp->strm_lock); + + strm =3D zcomp_strm_alloc(comp); + if (strm) + break; + + spin_lock(&comp->strm_lock); + comp->avail_strm--; + spin_unlock(&comp->strm_lock); + wait_event(comp->strm_wait, !list_empty(&comp->idle_strm)); + } + + return strm; } =20 -void zcomp_stream_put(struct zcomp *comp) +void zcomp_stream_put(struct zcomp *comp, struct zcomp_strm *strm) { - local_unlock(&comp->stream->lock); + spin_lock(&comp->strm_lock); + if (comp->avail_strm <=3D num_online_cpus()) { + list_add(&strm->entry, &comp->idle_strm); + spin_unlock(&comp->strm_lock); + wake_up(&comp->strm_wait); + return; + } + + comp->avail_strm--; + spin_unlock(&comp->strm_lock); + zcomp_strm_free(comp, strm); } =20 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, @@ -148,61 +203,19 @@ int zcomp_decompress(struct zcomp *comp, struct zcomp= _strm *zstrm, return comp->ops->decompress(comp->params, &zstrm->ctx, &req); } =20 -int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) -{ - struct zcomp *comp =3D hlist_entry(node, struct zcomp, node); - struct zcomp_strm *zstrm; - int ret; - - zstrm =3D per_cpu_ptr(comp->stream, cpu); - local_lock_init(&zstrm->lock); - - ret =3D zcomp_strm_init(comp, zstrm); - if (ret) - pr_err("Can't allocate a compression stream\n"); - return ret; -} - -int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node) -{ - struct zcomp *comp =3D hlist_entry(node, struct zcomp, node); - struct zcomp_strm *zstrm; - - zstrm =3D per_cpu_ptr(comp->stream, cpu); - zcomp_strm_free(comp, zstrm); - return 0; -} - -static int zcomp_init(struct zcomp *comp, struct zcomp_params *params) -{ - int ret; - - comp->stream =3D alloc_percpu(struct zcomp_strm); - if (!comp->stream) - return -ENOMEM; - - comp->params =3D params; - ret =3D comp->ops->setup_params(comp->params); - if (ret) - goto cleanup; - - ret =3D cpuhp_state_add_instance(CPUHP_ZCOMP_PREPARE, &comp->node); - if (ret < 0) - goto cleanup; - - return 0; - -cleanup: - comp->ops->release_params(comp->params); - free_percpu(comp->stream); - return ret; -} - void zcomp_destroy(struct zcomp *comp) { - cpuhp_state_remove_instance(CPUHP_ZCOMP_PREPARE, &comp->node); + struct zcomp_strm *strm; + + while (!list_empty(&comp->idle_strm)) { + strm =3D list_first_entry(&comp->idle_strm, + struct zcomp_strm, + entry); + list_del(&strm->entry); + zcomp_strm_free(comp, strm); + } + comp->ops->release_params(comp->params); - free_percpu(comp->stream); kfree(comp); } =20 @@ -229,7 +242,12 @@ struct zcomp *zcomp_create(const char *alg, struct zco= mp_params *params) return ERR_PTR(-EINVAL); } =20 - error =3D zcomp_init(comp, params); + INIT_LIST_HEAD(&comp->idle_strm); + init_waitqueue_head(&comp->strm_wait); + spin_lock_init(&comp->strm_lock); + + comp->params =3D params; + error =3D comp->ops->setup_params(comp->params); if (error) { kfree(comp); return ERR_PTR(error); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index ad5762813842..62330829db3f 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -3,10 +3,10 @@ #ifndef _ZCOMP_H_ #define _ZCOMP_H_ =20 -#include - #define ZCOMP_PARAM_NO_LEVEL INT_MIN =20 +#include + /* * Immutable driver (backend) parameters. The driver may attach private * data to it (e.g. driver representation of the dictionary, etc.). @@ -31,7 +31,7 @@ struct zcomp_ctx { }; =20 struct zcomp_strm { - local_lock_t lock; + struct list_head entry; /* compression buffer */ void *buffer; struct zcomp_ctx ctx; @@ -60,16 +60,15 @@ struct zcomp_ops { const char *name; }; =20 -/* dynamic per-device compression frontend */ struct zcomp { - struct zcomp_strm __percpu *stream; + struct list_head idle_strm; + spinlock_t strm_lock; + u32 avail_strm; + wait_queue_head_t strm_wait; const struct zcomp_ops *ops; struct zcomp_params *params; - struct hlist_node node; }; =20 -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); bool zcomp_available_algorithm(const char *comp); =20 @@ -77,7 +76,7 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_= params *params); void zcomp_destroy(struct zcomp *comp); =20 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp); -void zcomp_stream_put(struct zcomp *comp); +void zcomp_stream_put(struct zcomp *comp, struct zcomp_strm *strm); =20 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, const void *src, unsigned int *dst_len); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 14859bd2611f..486068dda395 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include =20 @@ -1610,7 +1609,7 @@ static int read_compressed_page(struct zram *zram, st= ruct page *page, u32 index) ret =3D zcomp_decompress(zram->comps[prio], zstrm, src, size, dst); kunmap_local(dst); zs_unmap_object(zram->mem_pool, handle); - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); =20 return ret; } @@ -1771,14 +1770,14 @@ static int zram_write_page(struct zram *zram, struc= t page *page, u32 index) kunmap_local(mem); =20 if (unlikely(ret)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); pr_err("Compression failed! err=3D%d\n", ret); zs_free(zram->mem_pool, handle); return ret; } =20 if (comp_len >=3D huge_class_size) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); return write_incompressible_page(zram, page, index); } =20 @@ -1802,7 +1801,7 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); atomic64_inc(&zram->stats.writestall); handle =3D zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | @@ -1814,7 +1813,7 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) } =20 if (!zram_can_store_page(zram)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); zs_free(zram->mem_pool, handle); return -ENOMEM; } @@ -1822,7 +1821,7 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) dst =3D zs_map_object(zram->mem_pool, handle, ZS_MM_WO); =20 memcpy(dst, zstrm->buffer, comp_len); - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); zs_unmap_object(zram->mem_pool, handle); =20 zram_slot_write_lock(zram, index); @@ -1981,7 +1980,7 @@ static int recompress_slot(struct zram *zram, u32 ind= ex, struct page *page, kunmap_local(src); =20 if (ret) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); return ret; } =20 @@ -1991,7 +1990,7 @@ static int recompress_slot(struct zram *zram, u32 ind= ex, struct page *page, /* Continue until we make progress */ if (class_index_new >=3D class_index_old || (threshold && comp_len_new >=3D threshold)) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); continue; } =20 @@ -2049,13 +2048,13 @@ static int recompress_slot(struct zram *zram, u32 i= ndex, struct page *page, __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle_new)) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); return PTR_ERR((void *)handle_new); } =20 dst =3D zs_map_object(zram->mem_pool, handle_new, ZS_MM_WO); memcpy(dst, zstrm->buffer, comp_len_new); - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); =20 zs_unmap_object(zram->mem_pool, handle_new); =20 @@ -2803,7 +2802,6 @@ static void destroy_devices(void) zram_debugfs_destroy(); idr_destroy(&zram_index_idr); unregister_blkdev(zram_major, "zram"); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); } =20 static int __init zram_init(void) @@ -2813,15 +2811,9 @@ static int __init zram_init(void) =20 BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > sizeof(zram_te.flags) * 8); =20 - ret =3D cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare", - zcomp_cpu_up_prepare, zcomp_cpu_dead); - if (ret < 0) - return ret; - ret =3D class_register(&zram_control_class); if (ret) { pr_err("Unable to register zram-control class\n"); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); return ret; } =20 @@ -2830,7 +2822,6 @@ static int __init zram_init(void) if (zram_major <=3D 0) { pr_err("Unable to get major number\n"); class_unregister(&zram_control_class); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); return -EBUSY; } =20 diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 6cc5e484547c..092ace7db8ee 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -119,7 +119,6 @@ enum cpuhp_state { CPUHP_MM_ZS_PREPARE, CPUHP_MM_ZSWP_POOL_PREPARE, CPUHP_KVM_PPC_BOOK3S_PREPARE, - CPUHP_ZCOMP_PREPARE, CPUHP_TIMERS_PREPARE, CPUHP_TMIGR_PREPARE, CPUHP_MIPS_SOC_PREPARE, --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED3ED1FE454 for ; Mon, 27 Jan 2025 07:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962998; cv=none; b=YuC0BaOJi2En/NG9+EZyQ3mTT39sz7ThG+C8jZnC6CfiXyQuovdxxSCy/zG51qAIdkmsF9zdhhsEMYlHeSAeIyaJrJxLFmEGX0YvP6NuWZ2FS79rUCtCv0sDDHqWt1CjmTioZg9ohz91zNXsH+9AlDw6GcmENPcexh2mbBJ1Fos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737962998; c=relaxed/simple; bh=+6d9AfTSxYRYZT7CBVVbUJEibwaLY0ntQMOAfQXEevQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FBMVeQuQvntq15V0JcVYUwOOqxJmXA+/zrScTB+2iMwzkyGmbiS6NtnrUsGPq3jOiI2d9vzPbq4r+bMR1gqFMsqTg3DPdS5/lYKLIafAb+M+bWDAAwKiiSa1x3QLLQKiVadTI50YdhTic0Larl1g2TRT4uZlo/0WGqGFbcTrHcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=R4x4dpVt; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="R4x4dpVt" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2f4448bf96fso5372247a91.0 for ; Sun, 26 Jan 2025 23:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737962996; x=1738567796; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZMKoDSDfvoX+go24fej91nvl1Fy002IINq4VDAWYIx0=; b=R4x4dpVtAPw/IT9aayIXFWmjZgsyTbSnfoB9uahPO/rXU+NqzMwAL07WohxiiGvV7T JbGQI7vO6Bmn7IQaZorrO984ZDLsLuY2G4prSeXwNwDKjtVbftayHBLoo7PZiXSENYEn L1fHXUItgHQ+gVhqUsiI4V+a0P1A57fzW0Z8A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737962996; x=1738567796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZMKoDSDfvoX+go24fej91nvl1Fy002IINq4VDAWYIx0=; b=pTcdkAOi91TSpPgmqohRw/lSVcT15waXrnjpanvMcN7v9+VyYfich0D0z9SrRoQ0SI vMQKl5yMip/FIKdkPCsWWuPzL39Tp7moH3l6MPY9OJPm1K3MUq6IvcLDKcuvt6C+7Bm0 Ks3JIMqf+WGy72H+hYL0X/JEQJbjtFxAu9pKLPeqkeHJ27TtHpmOAX9YWGvWcZqu2b6Z 2jNfHcDeIMTNJeZwICiZalTHjOPvxvjUmJjU5QUYoqxJkCwx665fEMMOOHE/3UCsipA5 4aNm8lTpBXKztjFw5XM4v7kGdnHkmrD4x1Fps3vDzziFjz1zN4cNQIl/roWe0IdFY+L+ rfEA== X-Forwarded-Encrypted: i=1; AJvYcCWkrfhz4b+tYRVYNA7/n0V5BOGUyIT4hdJVsZBcLul0e/pKmd538FHhy7eyIHnu7PTsbHQIjb2rltm7Xa4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3AtSxyFK+iIaPghmEw5fw+xzXopAZXrfZievAqsImcRjZxifN MVe9Cf+PM6r/JwUEVpBurvyaffa2nOKVS/pTxvyYdOQbRP3UFaDbQe5s1kLfIw== X-Gm-Gg: ASbGnctqT21lo9uyoEG7siw9CKKpm1DAf40BoQlMZDq57dSXAjq9kmi/vObjTrrAy+y kEkx473/MyaPIZS/hkZ4uWJklGfC/QRCDfym9VI+DlthF4Xfmf7lOZf+zio+iEwFwVGVy/2xsjw DVOu17z9Zxlf9vk0lPd2BivEzDADXumSjX8NaXzcQcJUGrRM8Jr31ZOuX3dAKpUVoYA8tb9sxQ+ PRnzgavH0Pdhjje4OLIwaxY8hYOTKrYz77kgxnD5U6hQpaa2DCwJPgBl3WNGa4MZYw9am38zvMY 7Ot8QPE= X-Google-Smtp-Source: AGHT+IEfwUI8auttHRk1qh7AN8+U6mvQ/O5WBUL7JmvN0YslOiw0cRVxh68/cSFEaaq3Cgj0hlneng== X-Received: by 2002:a17:90b:2803:b0:2ee:ad18:b30d with SMTP id 98e67ed59e1d1-2f782c4bd4emr8745204a91.6.1737962996210; Sun, 26 Jan 2025 23:29:56 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffb19938sm6431742a91.45.2025.01.26.23.29.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:29:55 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 3/9] zram: remove crypto include Date: Mon, 27 Jan 2025 16:29:14 +0900 Message-ID: <20250127072932.1289973-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove a leftover crypto header include. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 1 - drivers/block/zram/zram_drv.c | 4 +++- drivers/block/zram/zram_drv.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 982c769d5831..efd5919808d9 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -7,7 +7,6 @@ #include #include #include -#include #include =20 #include "zcomp.h" diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 486068dda395..c1ecaac0b39f 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -43,6 +43,8 @@ static DEFINE_MUTEX(zram_index_mutex); static int zram_major; static const char *default_compressor =3D CONFIG_ZRAM_DEF_COMP; =20 +#define ZRAM_MAX_ALGO_NAME_SZ 64 + /* Module params (documentation at end) */ static unsigned int num_devices =3D 1; /* @@ -1148,7 +1150,7 @@ static int __comp_algorithm_store(struct zram *zram, = u32 prio, const char *buf) size_t sz; =20 sz =3D strlen(buf); - if (sz >=3D CRYPTO_MAX_ALG_NAME) + if (sz >=3D ZRAM_MAX_ALGO_NAME_SZ) return -E2BIG; =20 compressor =3D kstrdup(buf, GFP_KERNEL); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 3436ddf8ab23..045032acb22f 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -16,7 +16,6 @@ #define _ZRAM_DRV_H_ =20 #include -#include =20 #include "zcomp.h" =20 --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CB621FECBC for ; Mon, 27 Jan 2025 07:30:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963003; cv=none; b=TaC3EX/452oOIy2x8BYvbMEEY9nnfkj2W3eaD8xDmnInqWrRp5SkGA9mj+/i347/Lj++TA7r/fUwcThMOC2AQIq3x6jt5Ns+6ujl9Xa7LGQRJ5W9si4guOT9oCJ0Mpy129KSOpPpzUEhYSywnWHq0bWofQtnuxh2IOH1Y1DUasY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963003; c=relaxed/simple; bh=z/eZVGbkQtvXn0THVb/tYUz0TkqIGeRlshDurgOU2ns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iqeFUhZhzsQAx5ZHokqShNhvWckg+85uYpX/IsAPVAxoivTP52S0Y00vcQkdfJ9iXmXqRidFcHCB8ilTLpVHXW8EIamuX+VO8Ldw8mQh8+oiIVLa26arTflgd9274WJZMWvlNYZapAvv7LUC6mMlEUwLHyogBqs0r5n0FCZg2yE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Qpo4IGtX; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Qpo4IGtX" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2166651f752so79363175ad.3 for ; Sun, 26 Jan 2025 23:30:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963000; x=1738567800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lUvRyh0me1bXpwqfK+TRyFS4H2+UkCD7EBcpdcldqV8=; b=Qpo4IGtXTBYRe94H/kLEJFYJWe1ubsfr05YydQmHlUEUmPDlVVojGdQdN/+xL43fHr W+hB6REpRnj3vQgBNNRTK8tXcDWSCqh67gpVpLuuKburD732HEYhpbAXfVYyXOalWgXN yLAQf2MEZgeLe+SAd5X9XNlFThO9q7KtmH6bw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963000; x=1738567800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUvRyh0me1bXpwqfK+TRyFS4H2+UkCD7EBcpdcldqV8=; b=d0/Nb4FN+q4yEWwNyabd8jzW8adGMeAIjEuL3B158ZNpaBHSgp7VxaEt4HpbDFWI0L CDKA/8d4mW3pSt/i4A8pyVCx26ANrOgGZZviwKluHitArTCjeuhNr+3pPWtpc6J2vro7 XnrtC5r1KFhl1FE1M/3d9cJj7iJN+IsRKdAwvjW6zhux5iicYdexpH7rNs7P23GO4CTG aDCpAVnCwJ7NA1P0HiF0ijB9ak3wNN12L0jtT9w7l+TRHXNLLCrELoXagWy5m/1gCKF6 bcTd947P8FEIcL6VHhfFhe6p9MkX8N/Zk1ym9ZIuWYOTuaVCYt4+CIu6R4vZUcZYvdQ3 gH6Q== X-Forwarded-Encrypted: i=1; AJvYcCWk/g6aEdbwnWDts1ctEqnEHgQtdj/lPmDJwIDqcIMGgPqG5I+MH7rMCKf20xuFV8INaG5cqge4ucQdong=@vger.kernel.org X-Gm-Message-State: AOJu0YzCCEzNrynUiZMD/Zdo2Xh5KHBCnN81VodeRANDwx6yBejKbjeS Uk8Pt4y+t0oaPFA64G5eKq7CaJI5/sAoRM130w1scldLM9uhQfEBi6/mcC4Osw== X-Gm-Gg: ASbGnctbl+lbB+PqpN9G5C9IhPeRFtR+bSgCIyRC1+BDUuJluMjPV3vZYkWB87YWNWI ux7IzjUIFqBHMd4KrO1zL4LzZC4dMvkYvUhfM13VG23vfD7rF43ByNxLL0rfEOVKGskRvB7u/Pv 0fKv2s+uTPCrr6PIodK5pHRvHiEcnUbz0/3Z+Azn11uya2rjnjt8PVqHKMDiEr1bdAIkPCPSNv+ nWrPhvSZiuR7tyGI3DldQVe3r1x4qO+MFS2YSGcmeFU4ecfEUsiCXnonMZfddBb8/ZNIdtQsy/I WwN/ooE= X-Google-Smtp-Source: AGHT+IEMZNai1/9yM8pfA7fL3mLUFYeR0CMWjd6TA0xHnzwmsWa0/+qcJq0oMDnr/ZCTRC5XkIHMLQ== X-Received: by 2002:a17:902:ea03:b0:219:d28a:ca23 with SMTP id d9443c01a7336-21c355eea74mr607842355ad.36.1737963000524; Sun, 26 Jan 2025 23:30:00 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da424e779sm56851105ad.213.2025.01.26.23.29.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:00 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 4/9] zram: remove max_comp_streams device attr Date: Mon, 27 Jan 2025 16:29:15 +0900 Message-ID: <20250127072932.1289973-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" max_comp_streams device attribute has been defunct since May 2016 when zram switched to per-CPU compression streams, remove it. Signed-off-by: Sergey Senozhatsky --- Documentation/ABI/testing/sysfs-block-zram | 8 ----- Documentation/admin-guide/blockdev/zram.rst | 36 ++++++--------------- drivers/block/zram/zram_drv.c | 23 ------------- 3 files changed, 10 insertions(+), 57 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-block-zram b/Documentation/ABI= /testing/sysfs-block-zram index 1ef69e0271f9..36c57de0a10a 100644 --- a/Documentation/ABI/testing/sysfs-block-zram +++ b/Documentation/ABI/testing/sysfs-block-zram @@ -22,14 +22,6 @@ Description: device. The reset operation frees all the memory associated with this device. =20 -What: /sys/block/zram/max_comp_streams -Date: February 2014 -Contact: Sergey Senozhatsky -Description: - The max_comp_streams file is read-write and specifies the - number of backend's zcomp_strm compression streams (number of - concurrent compress operations). - What: /sys/block/zram/comp_algorithm Date: February 2014 Contact: Sergey Senozhatsky diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/ad= min-guide/blockdev/zram.rst index 1576fb93f06c..9bdb30901a93 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -54,7 +54,7 @@ The list of possible return codes: If you use 'echo', the returned value is set by the 'echo' utility, and, in general case, something like:: =20 - echo 3 > /sys/block/zram0/max_comp_streams + echo foo > /sys/block/zram0/comp_algorithm if [ $? -ne 0 ]; then handle_error fi @@ -73,21 +73,7 @@ This creates 4 devices: /dev/zram{0,1,2,3} num_devices parameter is optional and tells zram how many devices should be pre-created. Default: 1. =20 -2) Set max number of compression streams -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -Regardless of the value passed to this attribute, ZRAM will always -allocate multiple compression streams - one per online CPU - thus -allowing several concurrent compression operations. The number of -allocated compression streams goes down when some of the CPUs -become offline. There is no single-compression-stream mode anymore, -unless you are running a UP system or have only 1 CPU online. - -To find out how many streams are currently available:: - - cat /sys/block/zram0/max_comp_streams - -3) Select compression algorithm +2) Select compression algorithm =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D =20 Using comp_algorithm device attribute one can see available and @@ -107,7 +93,7 @@ Examples:: For the time being, the `comp_algorithm` content shows only compression algorithms that are supported by zram. =20 -4) Set compression algorithm parameters: Optional +3) Set compression algorithm parameters: Optional =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Compression algorithms may support specific parameters which can be @@ -138,7 +124,7 @@ better the compression ratio, it even can take negative= s values for some algorithms), for other algorithms `level` is acceleration level (the higher the value the lower the compression ratio). =20 -5) Set Disksize +4) Set Disksize =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Set disk size by writing the value to sysfs node 'disksize'. @@ -158,7 +144,7 @@ There is little point creating a zram of greater than t= wice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of= the size of the disk when not in use so a huge zram is wasteful. =20 -6) Set memory limit: Optional +5) Set memory limit: Optional =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 Set memory limit by writing the value to sysfs node 'mem_limit'. @@ -177,7 +163,7 @@ Examples:: # To disable memory limit echo 0 > /sys/block/zram0/mem_limit =20 -7) Activate +6) Activate =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 :: @@ -188,7 +174,7 @@ Examples:: mkfs.ext4 /dev/zram1 mount /dev/zram1 /tmp =20 -8) Add/remove zram devices +7) Add/remove zram devices =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =20 zram provides a control interface, which enables dynamic (on-demand) device @@ -208,7 +194,7 @@ execute:: =20 echo X > /sys/class/zram-control/hot_remove =20 -9) Stats +8) Stats =3D=3D=3D=3D=3D=3D=3D=3D =20 Per-device statistics are exported as various nodes under /sys/block/zram<= id>/ @@ -228,8 +214,6 @@ mem_limit WO specifies the maximum amount of m= emory ZRAM can writeback_limit WO specifies the maximum amount of write IO zram can write out to backing device as 4KB unit writeback_limit_enable RW show and set writeback_limit feature -max_comp_streams RW the number of possible concurrent compress - operations comp_algorithm RW show and change the compression algorithm algorithm_params WO setup compression algorithm parameters compact WO trigger memory compaction @@ -310,7 +294,7 @@ a single line of text and contains the following stats = separated by whitespace: Unit: 4K bytes =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 -10) Deactivate +9) Deactivate =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 :: @@ -318,7 +302,7 @@ a single line of text and contains the following stats = separated by whitespace: swapoff /dev/zram0 umount /dev/zram1 =20 -11) Reset +10) Reset =3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Write any positive value to 'reset' sysfs node:: diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index c1ecaac0b39f..d867e15d1d2e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1103,27 +1103,6 @@ static void zram_debugfs_register(struct zram *zram)= {}; static void zram_debugfs_unregister(struct zram *zram) {}; #endif =20 -/* - * We switched to per-cpu streams and this attr is not needed anymore. - * However, we will keep it around for some time, because: - * a) we may revert per-cpu streams in the future - * b) it's visible to user space and we need to follow our 2 years - * retirement rule; but we already have a number of 'soon to be - * altered' attrs, so max_comp_streams need to wait for the next - * layoff cycle. - */ -static ssize_t max_comp_streams_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "%d\n", num_online_cpus()); -} - -static ssize_t max_comp_streams_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - return len; -} - static void comp_algorithm_set(struct zram *zram, u32 prio, const char *al= g) { /* Do not free statically defined compression algorithms */ @@ -2542,7 +2521,6 @@ static DEVICE_ATTR_WO(reset); static DEVICE_ATTR_WO(mem_limit); static DEVICE_ATTR_WO(mem_used_max); static DEVICE_ATTR_WO(idle); -static DEVICE_ATTR_RW(max_comp_streams); static DEVICE_ATTR_RW(comp_algorithm); #ifdef CONFIG_ZRAM_WRITEBACK static DEVICE_ATTR_RW(backing_dev); @@ -2564,7 +2542,6 @@ static struct attribute *zram_disk_attrs[] =3D { &dev_attr_mem_limit.attr, &dev_attr_mem_used_max.attr, &dev_attr_idle.attr, - &dev_attr_max_comp_streams.attr, &dev_attr_comp_algorithm.attr, #ifdef CONFIG_ZRAM_WRITEBACK &dev_attr_backing_dev.attr, --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AEED1FF1BE for ; Mon, 27 Jan 2025 07:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963008; cv=none; b=fsupFefNv84TS/+sREBsqvOgUjBUm3h2l7lnV0RP0l4s+augNs4eSiBTh/IKS1c4MVhVrMSgFnYbNBFxsxBcLwgSLnW+iMlHtJ6be/cF4Sm3BdgfNa/UgSpRkAO8dxFqfrvc96SNlZN6WJWfE/ZPcLEgInLB6IF4rj940UuxEYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963008; c=relaxed/simple; bh=nzkv5EM7WYnuylbdfc1Yt1qqTfqW+t+Kci8eCcUPCQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tGn4Xaibfjv5YbC3WiOQraQkJxMTsoPbNdOmhT7iZFuD3a3vJRPQUhP+kcMCFPRMUFJHhPSTaSQVtIWcgogVryYpvie8/Yauc73+6qCZh1XX1wDhu2PdXorOCUx771Y6JYO0BS3T8p5wwDUx+KyXRtC6Tji950VUYB+Jdo4x8a4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=YvwKOyos; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YvwKOyos" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2165448243fso88323405ad.1 for ; Sun, 26 Jan 2025 23:30:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963005; x=1738567805; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QR/p5Tl6lRpVatp+KkNy0La/JT3xx5EKDzU3nlrXbQA=; b=YvwKOyosTy94wyzHmQR076rrv/inOWdIrZyyr5Yp/tv78YZKgz7trIwblMFJ0Gljpd DdoEjE3MzHzRrhU/LOWJ9hVra/V3ahJhNYr2GYJn/bjUE0jwQ+OY97t0zcJgYQn+rztP t8hz1vWq2bwbvudEtSUHM71prxt+6IKUFVPu8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963005; x=1738567805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QR/p5Tl6lRpVatp+KkNy0La/JT3xx5EKDzU3nlrXbQA=; b=KQrGiyxO+BTQbrutjw0wHvrmfWa+Osw/IDl993Y4YMUVi0hWQy2Y1xXzcUrRcbvwlm SG24iGNBL/Vygcj6Ho+rZ2iumEK077rPEGQ63xlmmwUXEyfSFwZRsdnozT2F/I2cKrV4 iq3WopsQo6yufYHzbzZTT3++C63wetBcyfsmdRghUMJFf3PZ27D/8SXTx5t9AQa2ZzhW KwwTk5t9y4n2rPCUqf/ptEr8mtDSzwTD38/Eyh093TC22SpaBZkjIpw1udZYL6xSqLXt IRnpgary/j+Z+45F3bHNE1VYt4HaW0j1/+ObDRc3GyqSYeaM69cIsc4pSeH5LxYwo4bh vicA== X-Forwarded-Encrypted: i=1; AJvYcCVdbuk9LZPuPFNa7Irp2fAy2Peo+FkN0JYXRmZJGqzC4ZTLDkbGgGJpLp6d9YDHsOhD+WnpNumY8padZms=@vger.kernel.org X-Gm-Message-State: AOJu0YxY/3XRTSTOzf16+rnlgSFsODS4ZMcVI0dsINcCo466wwVOWTpM /U4hWEvCDMU+lObC7bswnph6wNFVqwKi1/9LHK7KIXkAuX8R1wAjfupZ3J6j83f3Gr0EUS/GCPs = X-Gm-Gg: ASbGncvtjsMBo2avNr0ZueD7BaCScIAfYJCOkiAdRuiFZ+E6QdcaOBX1OF/xTMcVe/P 7ydjMj2HdyG4Ri7ODpLaZ/wY7t2jFKB8rDPnqJx6Y+jID3XnMIK/p18OZYvZYyHjTClsAhyMxtK jZ5SgKkzCMpGM8ZCPpLEO8PuKiNwxm0OCsV8TqcvOPpbtbDBqwTTsjoQ0uH+etEOZC3adWXklJV DoVHj4UDe0NsKgt7ub7H+SMdZ2uyprE4okrmNMRigXfF6aaZyfV1Gek/iCyFnJw1W8dscO2Rk+l r++NCXU= X-Google-Smtp-Source: AGHT+IHV7YMpzbIT6L+DxKKXMn+vhmqmbhrzw8POAb9AfcZ1TJR/LzmJE93baxj7ELaSGxd4dqLq6A== X-Received: by 2002:a05:6a20:8428:b0:1e1:9f57:eaaf with SMTP id adf61e73a8af0-1eb2144d54amr59526793637.6.1737963005514; Sun, 26 Jan 2025 23:30:05 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a760e1fsm6352930b3a.113.2025.01.26.23.30.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:05 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 5/9] zram: remove two-staged handle allocation Date: Mon, 27 Jan 2025 16:29:16 +0900 Message-ID: <20250127072932.1289973-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously zram write() was atomic which required us to pass __GFP_KSWAPD_RECLAIM to zsmalloc handle allocation on a fast path and attempt a slow path allocation (with recompression) when the fast path failed. Since it's not atomic anymore we can permit direct reclaim during allocation, and remove fast allocation path and, also, drop the recompression path (which should reduce CPU/battery usage). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 41 +++++------------------------------ 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d867e15d1d2e..046c80aa4310 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1725,11 +1725,11 @@ static int write_incompressible_page(struct zram *z= ram, struct page *page, static int zram_write_page(struct zram *zram, struct page *page, u32 index) { int ret =3D 0; - unsigned long handle =3D -ENOMEM; - unsigned int comp_len =3D 0; + unsigned long handle; + unsigned int comp_len; void *dst, *mem; struct zcomp_strm *zstrm; - unsigned long element =3D 0; + unsigned long element; bool same_filled; =20 /* First, free memory allocated to this slot (if any) */ @@ -1743,7 +1743,6 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) if (same_filled) return write_same_filled_page(zram, element, index); =20 -compress_again: zstrm =3D zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); mem =3D kmap_local_page(page); ret =3D zcomp_compress(zram->comps[ZRAM_PRIMARY_COMP], zstrm, @@ -1752,8 +1751,6 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) =20 if (unlikely(ret)) { zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); - pr_err("Compression failed! err=3D%d\n", ret); - zs_free(zram->mem_pool, handle); return ret; } =20 @@ -1762,36 +1759,10 @@ static int zram_write_page(struct zram *zram, struc= t page *page, u32 index) return write_incompressible_page(zram, page, index); } =20 - /* - * handle allocation has 2 paths: - * a) fast path is executed with preemption disabled (for - * per-cpu streams) and has __GFP_DIRECT_RECLAIM bit clear, - * since we can't sleep; - * b) slow path enables preemption and attempts to allocate - * the page with __GFP_DIRECT_RECLAIM bit set. we have to - * put per-cpu compression stream and, thus, to re-do - * the compression once handle is allocated. - * - * if we have a 'non-null' handle here then we are coming - * from the slow path and handle has already been allocated. - */ + handle =3D zs_malloc(zram->mem_pool, comp_len, + GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle)) - handle =3D zs_malloc(zram->mem_pool, comp_len, - __GFP_KSWAPD_RECLAIM | - __GFP_NOWARN | - __GFP_HIGHMEM | - __GFP_MOVABLE); - if (IS_ERR_VALUE(handle)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); - atomic64_inc(&zram->stats.writestall); - handle =3D zs_malloc(zram->mem_pool, comp_len, - GFP_NOIO | __GFP_HIGHMEM | - __GFP_MOVABLE); - if (IS_ERR_VALUE(handle)) - return PTR_ERR((void *)handle); - - goto compress_again; - } + return PTR_ERR((void *)handle); =20 if (!zram_can_store_page(zram)) { zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CDC91FF1C2 for ; Mon, 27 Jan 2025 07:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963013; cv=none; b=WH52EVXmXqP9IhbkRrlZx495v/J8FZHnS1wHyomNohJiAvor0M3JpcJu7UcpeLwLhvbxVgtw7KT0DZEPboECELnH6oKL8vR4P7kJ91vStdEr2QIEsonbbBQkVpw81VOSP826nb8O4rX7PcFWdo1UqxxktZaIF7l9zI790KnfBmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963013; c=relaxed/simple; bh=Ej/13Gy59hq4pSeuXyYtdu8JOFvxFaLu/EaPO8MCcTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQ/4g4wK6Z/t1nC5XMm+9qRIKUpAvZyZ3OUO8HQqcja7brFJYR37nP8AUCElne/9bAr5qQFOtWjCQfYFfdutnd5jcpQZtmkuETuK01f+Z91ozTGLM1xrnXVKPKDtrJzbuAD1yChTn6DJ+JADgvcb4sHdL9D1IIsgdQ/0+7cm5bY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ZBymykRS; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZBymykRS" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2f78a4ca5deso5385894a91.0 for ; Sun, 26 Jan 2025 23:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963010; x=1738567810; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5g614UtqxTvOkBYeQdwAP9Uo/j0Alc44lQaUMvbAkkk=; b=ZBymykRSU6rvWFHJZumEXcLG/E1YUcPFaPCw+hmYefCBpT+Ypx2PEyDxzcATSHMKwy yWWFsgpWv6SZMkBpjwzl/Rpkw3ZrnLpVnAGrtDUxTLYb12KI+aPqphzxxBa3Jcs9FCqD JNH0P7PFHBmKfA+Y3hHB1Ebg5EaREHQy+LYMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963010; x=1738567810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5g614UtqxTvOkBYeQdwAP9Uo/j0Alc44lQaUMvbAkkk=; b=XGGJ+RxTImvZmtGXCig0J//P9+OuIPyPJD3LMcLC5o0OVsu1Uqz0B1UAo8YWJopr2C ++a+OaUfjs5qim170NFZx65QteChUTH1kOieWR88jOF2pVgqgWHJInBi1DeaXPtEALMi Z69VqYbOMSinhEh8GzXl5Ry+RqE5L5gYtKqtOxE9uWMfcXNX3u5ekkdaXiiEou/QjqUG gpXRcYJttfaVyfkqY73Zr19NUWCPK5nXh7hCpItoO1XE8xLzshnR38tcHCfH1guhXw86 RfDcS+/NuNIf+jSW/EcVNGsY/tCPIzHq2aD33r7z+/O6lB1DA/KjNfAS6HG4PWTVRt0n icAA== X-Forwarded-Encrypted: i=1; AJvYcCUNhDGzSN0YuQ/MxZwrEpK9W3kxleSVSmTSEex/yK0yDr4rnRZcUXQVLcyOTTfQO8fwfrQ0zvkTY3f5KfQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxnbjP8XogozRWlEiGY+FARA//vAwMYPCaPwdUP6rUqh8d3iie0 nGxvjNF3XTw7HfZFEtsESevfxFKfQrDMYPv6gpCLeta45g3DhJmMRTC8ry6RYZhgi5MG6DuIWB8 = X-Gm-Gg: ASbGnctvivVutkJWl9aI0I9xsUVR0QbKQKiH4gY9GtNWZWM4yLYisrIc7eCUAHLGek6 JSmRxiXRTS5Zm7UuqJHFcxB4v6WG+A2OYu2mH/+TpkAh7+ZuCKQk+9M4K0Mht9cxY+ehAlajrAV fJ3OsiPwQmQ2wxk86UWeiTfnSRWu7PeIbyq6D9pkzFJIF0qDUZ6WxWWs1YFgb93dZ7Bqzz27SeL Uhpr2f/0VVV3PlCKw5DQQ21M4ki8UoFVEjxXvA0INy7LPXFbioDYDLcDpizAORb85QAKoXwtRgq SG7K+Ww= X-Google-Smtp-Source: AGHT+IGKyeWS3mv+loODSXHq45Ym+6tplx4pvP6lVRL0eZv4C+tLZFBWcDTabbbQlUIiu02lYNkogw== X-Received: by 2002:a05:6a00:2294:b0:728:e745:23cd with SMTP id d2e1a72fcca58-72daf92bbd7mr61064828b3a.3.1737963010417; Sun, 26 Jan 2025 23:30:10 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-ac48ea371dasm5724120a12.12.2025.01.26.23.30.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:10 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 6/9] zram: permit reclaim in zstd custom allocator Date: Mon, 27 Jan 2025 16:29:17 +0900 Message-ID: <20250127072932.1289973-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When configured with pre-trained compression/decompression dictionary support, zstd requires custom memory allocator, which it calls internally from compression()/decompression() routines. This was a tad problematic, because that would mean allocation from atomic context (either under entry spin-lock, or per-CPU local-lock or both). Now, with non-atomic zram write(), those limitations are relaxed and we can allow direct and indirect reclaim during allocations. The tricky part is zram read() path, which is still atomic in one particular case (read_compressed_page()), due to zsmalloc handling of object mapping. However, in zram in order to read() something one has to write() it first, and write() is when zstd allocates required internal state memory, and write() path is non-atomic. Because of this write() allocation, in theory, zstd should not call its allocator from the atomic read() path. Keep the non-preemptible branch, just in case if zstd allocates memory from read(), but WARN_ON_ONCE() if it happens. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/backend_zstd.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend= _zstd.c index 1184c0036f44..53431251ea62 100644 --- a/drivers/block/zram/backend_zstd.c +++ b/drivers/block/zram/backend_zstd.c @@ -24,19 +24,14 @@ struct zstd_params { /* * For C/D dictionaries we need to provide zstd with zstd_custom_mem, * which zstd uses internally to allocate/free memory when needed. - * - * This means that allocator.customAlloc() can be called from zcomp_compre= ss() - * under local-lock (per-CPU compression stream), in which case we must use - * GFP_ATOMIC. - * - * Another complication here is that we can be configured as a swap device. */ static void *zstd_custom_alloc(void *opaque, size_t size) { - if (!preemptible()) + /* Technically this should not happen */ + if (WARN_ON_ONCE(!preemptible())) return kvzalloc(size, GFP_ATOMIC); =20 - return kvzalloc(size, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN); + return kvzalloc(size, GFP_NOIO | __GFP_NOWARN); } =20 static void zstd_custom_free(void *opaque, void *address) --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7671FF602 for ; Mon, 27 Jan 2025 07:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963018; cv=none; b=Yoj7ub8v2oAETcvK+BVd0yNxSEhsZAantV1hn1GjsOobLTdfmTNvkev4uEpYy1NA3rDWh2nFWLnK5STI4299fh3y6cPgbmUMfMvANBhDQCT5JFDwXohy7OjQCWshps1R4ddPpHp09Y3KPnxjKWUuQKVJuU5g0lV4Gt2yZoqC7pM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963018; c=relaxed/simple; bh=xLjcXBVyaOqBx8gEu7T4yqHFwFjH+nKadXGoLMeevHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6/EvG+kE1OGhfE3t9sHLFcy9kLOhtFQsYCjn5SRhJLAtXeVGW/xwFr/CpFSDtCcQ9WQ1xTLD8n3Pd2VtHbV1UyC+xOoORiPygqlkNIaV9Tip9zpdAU9GKencihyy3kgnDZTGNFgBBl+egPnoc+YzkVNN+m73ZVg1s8grbFUK6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=VBKSQ2Wk; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VBKSQ2Wk" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ee709715d9so5599228a91.3 for ; Sun, 26 Jan 2025 23:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963016; x=1738567816; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eEuN8Bq5p1mqZ6qTtfa1iRJPgB+Yv5kUdAyDKcVHFeU=; b=VBKSQ2Wkr0lR0cy7l+9IEA7ArlVTSjPa87IMAmV/JZPlhzo2GfRmMEEVJsyJ8vb4ii mLSu5dlk6HyLvff9OWmVcc/Qj1Q7xiYHuW98svBXfhXsL9AvxbTsQGTJoBo3yaihhk+3 WUNE8WPv19I4uKJGkEez76il1q0FUJvRnlcBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963016; x=1738567816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eEuN8Bq5p1mqZ6qTtfa1iRJPgB+Yv5kUdAyDKcVHFeU=; b=pOpsNaWbKpcOvhsKh0Dduc+LbAo5M9/dQWTxjWSRCoRSCeuVSPxJcDE57SGdIi0PIz hR+ViMa6+MzbfJVNnhVpD2y8IJjK5OM+LkPCYS4fE315xaypwefwR5eEGoD6XtVBvhBy IsLc/uLyvuIMaHcQHwVHG68mrgJN+K1akJ5rpftoL5RNB8JtB9ReJ4x2Qau6En3Z+r18 Tg2SMFp/j39tdOco0WrFL5w/PV+phQhripIQKzp+YSSzFyUH7WHmPLP4bGn1OkwJpGST cWcXq7c+oBfE+66kZuDCh/+oapbd1lNQz1kvSt9w2kTdlidacEe60A2zGQKh7geWoVEk f40w== X-Forwarded-Encrypted: i=1; AJvYcCXWqqP/FjBDc7O4QoKPedYLHC4ybmTvF4cYDxTybTyhMhJeQpgKLL9dRuPFX/aXqFG72ZCYplLTD1Hpomo=@vger.kernel.org X-Gm-Message-State: AOJu0YzFm5vE85CRkyMQ654cR2IVui7WcI7I7fFX8KLbchod0pDFEd7O 9QXYpUyGKt38Ltw1jJaKB7Dl2mi6DfJYq6SHgXWf/rzOGiq4BC0zGKQb4VJYpg== X-Gm-Gg: ASbGncvTjEjwsS/h3QM6ENux9DvtTqqvA6HvnOVJEzmEHUCtLA0f639ii9r1Uug/Chq svJANnXYcPI6sbh9QKy45tDijLnaLBDKkNp+R8Ojj2/hSwWE6PCIaJ76ATes3tv2ZEUeZKWlNVB U4xhVPiE8VUHc49BwJqO0ZMW8/PcYuwtZva7J2+Yr8nqkC5D2P3ptTn289RPu5EWivgmc+U6Bji r92wsxqNHvUbUGAFkGIBHULPF57Aoe/k4kvqVDCpf2KxK/JD3A4Ra2KI0mVRn35Q5jKPpFGKKy/ BUmHIUY= X-Google-Smtp-Source: AGHT+IGlo/vTdElSIeoYoZL5xyWIf44NgB7/wcjQQDIBMbG82N6RjyywPPzveq1A/4IFqrAaMweY1g== X-Received: by 2002:a17:90b:5249:b0:2ee:e518:c1cb with SMTP id 98e67ed59e1d1-2f782c4bdd2mr61051697a91.7.1737963015607; Sun, 26 Jan 2025 23:30:15 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7ffa6a755sm7123997a91.26.2025.01.26.23.30.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:15 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 7/9] zram: permit reclaim in recompression handle allocation Date: Mon, 27 Jan 2025 16:29:18 +0900 Message-ID: <20250127072932.1289973-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Recompression path can now permit direct reclaim during new zs_handle allocation, because it's not atomic anymore. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 046c80aa4310..10e4c6a7735c 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1988,17 +1988,11 @@ static int recompress_slot(struct zram *zram, u32 i= ndex, struct page *page, return 0; =20 /* - * No direct reclaim (slow path) for handle allocation and no - * re-compression attempt (unlike in zram_write_bvec()) since - * we already have stored that object in zsmalloc. If we cannot - * alloc memory for recompressed object then we bail out and - * simply keep the old (existing) object in zsmalloc. + * If we cannot alloc memory for recompressed object then we bail out + * and simply keep the old (existing) object in zsmalloc. */ handle_new =3D zs_malloc(zram->mem_pool, comp_len_new, - __GFP_KSWAPD_RECLAIM | - __GFP_NOWARN | - __GFP_HIGHMEM | - __GFP_MOVABLE); + GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle_new)) { zcomp_stream_put(zram->comps[prio], zstrm); return PTR_ERR((void *)handle_new); --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C14361FCFC5 for ; Mon, 27 Jan 2025 07:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963024; cv=none; b=Zn339Ey4GfRU+KYbWT+9x2LyS4SabaUWvd1KRYa3gU0/os+9Zr9XYGsA+cxnFD+rxbQCTB2+VoPko+oItBvA9zg98YG612qe9Z4X2P3zex4zu1AX2OaRO6CLrbYg5d+X54hPsyjMEbLgmMc8OZ+RWIWrzPse0KfHur62/YxtEfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963024; c=relaxed/simple; bh=w+0wtoJXs9TQghSdq1RJa54Xow/458AcjfD3CArrsgY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q6/skX3xjTRtLpajC8F7C5CS/4xBcDBx9jdo3GuAT7P2blSF4L+Be3IllIXqUcfNeNIn7KPKWPJ7Zo+wHHKoO7u0Dx9eQvIUwLGcbYPYrN4745Wdx0bHqoxfrCu0jualRohOv783GJkoCYVk9YEJFnHExU2LE5nGInOYr6k9LHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=PqV5lKWx; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PqV5lKWx" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2164b662090so77453095ad.1 for ; Sun, 26 Jan 2025 23:30:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963022; x=1738567822; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kSgdSt89nTEWoMlDHQC4zKaDJjnbZfjCeF+nCuROQ6c=; b=PqV5lKWxgQZNnFgnyxe0eYfh3iXv+BOIGlQxHw4xDUCgLA7EICE+zDlyC7/NYeg7Zq qB/yQmJINhfTBYjkJFAwlrs6ANNeyXC1EdkAW0OPFqQeMeh7j4LRWTQWxifaeWNxwaKA GpZDC5GVNbC/KCBd7TDbdUxg2bmTyxP12V0QU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963022; x=1738567822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kSgdSt89nTEWoMlDHQC4zKaDJjnbZfjCeF+nCuROQ6c=; b=ccF+60ImW3uPkIgOJtRRLnV/4SfbvZonZu/P0UBrI0cCQ9WHzJL8UPhx/MxkpGnMzw JWzVDcGsX9+rL4VtoYQYBon6khhGICxS2+h6K8QwuBz8M/Ex0BLVvypmAiJhY+dIm2NX kuMowmyEU9EiCkDS/l0X+CmxDoEisC1WJd8XLS1ani2inewhkSbWwLM/I7o/KtNFFD9X /HW2c07u8vDTSW45NJYE1ZKl3mUfeABEDNz+8FU4W/MfHvvu47XzFe0iIhR1kmB9vGn3 1QZ/MaSEdSKHECa6yQsNFLxvSM6APu0ZUcZ3i8vSUInK48tEpQTFQp7RO4n2c1OEkZMr EwHg== X-Forwarded-Encrypted: i=1; AJvYcCWD1RP1uUSIvf0srOwhp0MqzqHQUC7HFcZieJCMl95rgPG2KyK98qm5UsqRNPVGHRiLg8YSSjWFKpXOfNs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7TbNvuR0Qe5Qee0ZMW3xNBaP21+Z/0ku63/YZGzglyARBGPxO N7VXy6VN3qL2mtTXKd80dEUm6Ipm5pOaZe0fuVqlT8yEm7Rnrr29syRQ+r5X4Q== X-Gm-Gg: ASbGncsNFxT54ER+hDsj3xOJJHc9ZlyPy0ONcSQ7WwahVgVQMw3/Q56vKlYR/bVZAdv rbDpuRTMFVksgxPVoglXmB08H+E4BcBe2WsG59iVRCs2+4SGcxPCK0aE+HuRnCCexKkCDWofODi vFDAkEZq0EmD+vdkmUdE9wx60OGXKLVRmKHlGnJUq1ev3k7Wez4w9iIniDqzmrUQn1kBkkDGDi2 Cj5oiisk+VubRuQIjdfkMhXBw3vmAz1NKmi5xbhn+ryFcOuXka7xY04chsdO5u/NhQwOng37dQ4 vRGEJnY= X-Google-Smtp-Source: AGHT+IFJkNEfxxGm9e2mhZinKXdaG+6TaYhwskg1qiYEq63JEXJ/MVr0HkgBllV11tnfS2o+XZnVNQ== X-Received: by 2002:a17:902:cf0b:b0:216:2af7:a2a3 with SMTP id d9443c01a7336-21c3560726cmr685117125ad.53.1737963022243; Sun, 26 Jan 2025 23:30:22 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da3d9e092sm56864765ad.28.2025.01.26.23.30.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:21 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 8/9] zram: remove writestall zram_stats member Date: Mon, 27 Jan 2025 16:29:19 +0900 Message-ID: <20250127072932.1289973-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no zsmalloc handle allocation slow path now and writestall is not possible any longer. Remove it from zram_stats. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 3 +-- drivers/block/zram/zram_drv.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 10e4c6a7735c..07cae8fe9b66 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1437,9 +1437,8 @@ static ssize_t debug_stat_show(struct device *dev, =20 down_read(&zram->init_lock); ret =3D scnprintf(buf, PAGE_SIZE, - "version: %d\n%8llu %8llu\n", + "version: %d\n0 %8llu\n", version, - (u64)atomic64_read(&zram->stats.writestall), (u64)atomic64_read(&zram->stats.miss_free)); up_read(&zram->init_lock); =20 diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 045032acb22f..b7e250d6fa02 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -78,7 +78,6 @@ struct zram_stats { atomic64_t huge_pages_since; /* no. of huge pages since zram set up */ atomic64_t pages_stored; /* no. of pages currently stored */ atomic_long_t max_used_pages; /* no. of maximum pages stored */ - atomic64_t writestall; /* no. of write slow paths */ atomic64_t miss_free; /* no. of missed free */ #ifdef CONFIG_ZRAM_WRITEBACK atomic64_t bd_count; /* no. of pages in backing device */ --=20 2.48.1.262.g85cc9f2d1e-goog From nobody Thu Jan 30 18:53:12 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5310D1FCCE7 for ; Mon, 27 Jan 2025 07:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963029; cv=none; b=NmpaPsQAdXmaMSgocJNtisS4Zg2zHhOyIFKIbNVrLnd0jXcyQoI3GY/OulhcjsUBfNSsNz2HPD2V4duddCeENBL1+WvuLPvmjKD4gPXk1dDRLiqI2Ox3X49jErf7J+qGGABMtNMu7sAkqXM+Qe+vcRNGGVCGWR9uN0quowmmSos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737963029; c=relaxed/simple; bh=Hf98AyQ6lwoMxllJeMlrmQv2v8eJCPBdKlL8SUemZ8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ieFxusF7psDYqg5T5h4vzz8cw0DdI23ybPw/KteJu5if3M/AXVvIpHgu2h1YlzbyOiZKdPUITvNSwBy+jgjOiIKCGddcOpMPfMS5JvQTNIR2Jm+89Y9chFc0VZA1SIblP/jMOMZy0lhUi1FCXTlZ7ITf7UrNHP8wcWa30qC7s8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=f+tmfVLf; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="f+tmfVLf" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21631789fcdso66709055ad.1 for ; Sun, 26 Jan 2025 23:30:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737963027; x=1738567827; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9PZlb0bpCrEa0EBxHNBCQaxxKLzdyJEYyXpra8I/P5g=; b=f+tmfVLfsftGBNYme/+V0lYO0auvCxTtMUnCLkGB4ko73CYC2jDAISLOy8e2iypF68 sz/kR23/NPlBIkLnuKkqpuj+XByjCc8JqHHysak6dHTZGP4nJXtPp9MfwOfFgNieWJKv eYgIRN1qwEq3N1smF64OxJVgJR52fdiC1DJBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737963027; x=1738567827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9PZlb0bpCrEa0EBxHNBCQaxxKLzdyJEYyXpra8I/P5g=; b=cac7WMg93yW4d8dzILRX2v8dVTiUY0EaCRGr0/rrrpXrk1gDqjGIqUeKfci9BaY33x Dsz5MJqLuRyA0rnVFGcb9jM90OAPZ/RdHQ7Twm6TSO4tCcAgFQ1rAt8kNCYUE2FzQogC esVd/dY4djBRZMhA6nqCSyuzwbI6Mfc2iktAsiu9Xf0hs+wCZUHQ0Uu5tHT3CrWbP55O JIOj67fwU+dxa88Xw9CVWXTs+U5EkK4HhejTEg8mA/Jz6y4hQ9L2rSEO2w/J92YtHMAJ 1pXO6ZKmj03GGUKb+Z5O4RdNO8mHAQ9X8v4uLtCv6b1jytxlEQo5f93exs0aImN3gu6Q 2zPg== X-Forwarded-Encrypted: i=1; AJvYcCWuusA/rzt7VuZTdRcMNG7GToVLxrJD5l3x2QdUE3z5ic9ISr825NURCB5CY39pxzu3W/r2fYzlK2yRR98=@vger.kernel.org X-Gm-Message-State: AOJu0YwVDKqdTj1bRrn2BNXvE8lLbcmo+Ytwn+cXewsbmnGKF/y6ZfG6 CYn+0cAWBdpVloo9KTKq3eRvHtbZ51ce/I1g7o9tt2vUvYOxsVnWGEDzSUUsKw== X-Gm-Gg: ASbGncvPOVcj+B1TdHPPdVKA1jmz121c/MLANL+lrYk61hO9i4KHR9estRKYRF/ZPtN BHa+D9jcfcDIgu0jVSbH+Hxm9p7Wr1uwl5fdIxcsXs+9PjrGwExkvpJOcRbwGkD3BfmzTZQXOV0 8N3GyJqeNK29EEcK+TpF3VxbLpft42a+JNYPTD/+KxXsP/LxcOSuDzUeX20kVsIdnqZ8lA8og0X Pj1Txq5S8T+1U07OFO6zZJochUPRQxaEZ9Pk75ATaZZ1K8qNjvYUX5kmiO4gdh/OoqxjIYdKK+f bpgzEss= X-Google-Smtp-Source: AGHT+IGG3TeaG4wWi40jK1p6mY3yatjcS1oAjwA+7dpgpn76mSRyGup3rx8p2HazaczZbRSX+r3sbw== X-Received: by 2002:a17:903:40c8:b0:216:6284:8a00 with SMTP id d9443c01a7336-21da4a11a0bmr202401385ad.2.1737963027560; Sun, 26 Jan 2025 23:30:27 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da4141123sm57299285ad.112.2025.01.26.23.30.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 23:30:27 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 9/9] zram: unlock slot during recompression Date: Mon, 27 Jan 2025 16:29:20 +0900 Message-ID: <20250127072932.1289973-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127072932.1289973-1-senozhatsky@chromium.org> References: <20250127072932.1289973-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Recompression, like writeback, makes a local copy of slot data (we need to decompress it anyway) before post-processing so we can unlock slot-entry once we have that local copy. Unlock the entry write-lock before recompression loop (secondary algorithms can be tried out one by one, in order of priority) and re-acquire it right after the loop. There is one more potentially costly operation recompress_slot() does - new zs_handle allocation, which can schedule(). Release the slot-entry write-lock before zsmalloc allocation and grab it again after the allocation. In both cases, once the slot-lock is re-acquired we examine slot's ZRAM_PP_SLOT flag to make sure that the slot has not been modified by a concurrent operation. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 53 +++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 07cae8fe9b66..ad3e8885b0d2 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1908,6 +1908,14 @@ static int recompress_slot(struct zram *zram, u32 in= dex, struct page *page, zram_clear_flag(zram, index, ZRAM_IDLE); =20 class_index_old =3D zs_lookup_class_index(zram->mem_pool, comp_len_old); + + /* + * Set prio to one past current slot's compression prio, so that + * we automatically skip lower priority algorithms. + */ + prio =3D zram_get_priority(zram, index) + 1; + /* Slot data copied out - unlock its bucket */ + zram_slot_write_unlock(zram, index); /* * Iterate the secondary comp algorithms list (in order of priority) * and try to recompress the page. @@ -1916,13 +1924,6 @@ static int recompress_slot(struct zram *zram, u32 in= dex, struct page *page, if (!zram->comps[prio]) continue; =20 - /* - * Skip if the object is already re-compressed with a higher - * priority algorithm (or same algorithm). - */ - if (prio <=3D zram_get_priority(zram, index)) - continue; - num_recomps++; zstrm =3D zcomp_stream_get(zram->comps[prio]); src =3D kmap_local_page(page); @@ -1930,10 +1931,8 @@ static int recompress_slot(struct zram *zram, u32 in= dex, struct page *page, src, &comp_len_new); kunmap_local(src); =20 - if (ret) { - zcomp_stream_put(zram->comps[prio], zstrm); - return ret; - } + if (ret) + break; =20 class_index_new =3D zs_lookup_class_index(zram->mem_pool, comp_len_new); @@ -1949,6 +1948,19 @@ static int recompress_slot(struct zram *zram, u32 in= dex, struct page *page, break; } =20 + zram_slot_write_lock(zram, index); + /* Compression error */ + if (ret) { + zcomp_stream_put(zram->comps[prio], zstrm); + return ret; + } + + /* Slot has been modified concurrently */ + if (!zram_test_flag(zram, index, ZRAM_PP_SLOT)) { + zcomp_stream_put(zram->comps[prio], zstrm); + return 0; + } + /* * We did not try to recompress, e.g. when we have only one * secondary algorithm and the page is already recompressed @@ -1986,17 +1998,28 @@ static int recompress_slot(struct zram *zram, u32 i= ndex, struct page *page, if (threshold && comp_len_new >=3D threshold) return 0; =20 - /* - * If we cannot alloc memory for recompressed object then we bail out - * and simply keep the old (existing) object in zsmalloc. - */ + /* zsmalloc handle allocation can schedule, unlock slot's bucket */ + zram_slot_write_unlock(zram, index); handle_new =3D zs_malloc(zram->mem_pool, comp_len_new, GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); + zram_slot_write_lock(zram, index); + + /* + * If we couldn't allocate memory for recompressed object then bail + * out and simply keep the old (existing) object in mempool. + */ if (IS_ERR_VALUE(handle_new)) { zcomp_stream_put(zram->comps[prio], zstrm); return PTR_ERR((void *)handle_new); } =20 + /* Slot has been modified concurrently */ + if (!zram_test_flag(zram, index, ZRAM_PP_SLOT)) { + zcomp_stream_put(zram->comps[prio], zstrm); + zs_free(zram->mem_pool, handle_new); + return 0; + } + dst =3D zs_map_object(zram->mem_pool, handle_new, ZS_MM_WO); memcpy(dst, zstrm->buffer, comp_len_new); zcomp_stream_put(zram->comps[prio], zstrm); --=20 2.48.1.262.g85cc9f2d1e-goog