From nobody Thu Jan 30 23:58:49 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