From nobody Fri Dec 19 21:54:41 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 D51581A8F94 for ; Wed, 22 Jan 2025 05:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737525562; cv=none; b=ux4l/TKshWv5I5s9sou28O6iuFY//WDYoJ5nH+cr1ezoUGAepukQJD/abWwSwqmGGv6lgiZXF6zGTXVE7y7uIX6H4J320LMc2o2ZxbsNWS/d8T9W/Jk2ccy9M6g6OcnIJzT9ksqmJGPTYbUBY3iChOqe1RZXk9ZPxRMLFgM3gFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737525562; c=relaxed/simple; bh=rMlmjPFP36XUCLN8rl/OxWPYxn8c0sM8l7U36R66UPA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M20mslf7iqnDfCxEZgJJMZucdyCdsRNjYkJUV5rW6fN9ZoLeVgs4kueYhLet0oYmUTqkqDqHCz4k5TcyczFl49L17r/UXLQmTlYGpvPl9ORKfqTIeFRXivuXAGJYLYDgG8XArzA1U6oKk5pMvL6r5JKEk+hCRIEJh1JdUdRQ1mw= 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=COCGUhmZ; arc=none smtp.client-ip=209.85.214.181 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="COCGUhmZ" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2163b0c09afso117402645ad.0 for ; Tue, 21 Jan 2025 21:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737525560; x=1738130360; 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=SJ+ga7y6+gKF81TWcu7LgFAJ2gVF/zL45vImj5BpZyE=; b=COCGUhmZmlalaiqEp1hu5aWctrdZEgye+XdHo3fvH/vBAKu4Cj3PNrAjxk2fGCzjkn NQ92cPBdd5dwX8qJZ0uW/bMXc9bIcdmP8zcvJgn4uf+r9VrbdxC4Z02dSvWALKBFeFQU xpRdx/ElGOv4e6b03bDJJzpnvlPMIUFhBcNLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737525560; x=1738130360; 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=SJ+ga7y6+gKF81TWcu7LgFAJ2gVF/zL45vImj5BpZyE=; b=Ll7FC/vgpVOmVakfAxkChJ0nKP2Zxul1IjKNPIx9C7tjen8bISH7KhUhkF7EkDBCuH B5D6G8UPtxECfuOs1w1/bPHqR0GbP9g4627tZMVpwbS+IOXWwoUhE3qt1l62m7iMHmgo DIf0ZVlgS32rjZH1PF5fHjJgR3OmlQ06ml3G7v0PfuTfDNizuP4iHJ/5Y9Id2N7S2uNH dBMgB4YvCgYPs26rS44siBqrLGo8zZhnMv/MsZiXhfS6jBQnn63EECt8q0YpsYbvBQQv Y7GJt8BUTJob039aEJQIfAI1lONgPrjdkn5+ghAyq8UASXJXPbjewi7S7j3oq1pfC+H+ jIIw== X-Forwarded-Encrypted: i=1; AJvYcCVvzppTEpgH9tgz++YBop763g7iDAODM1lJEkv8eE94Cuxw5XpCWvrJiL92id5ctVTQoA46pyyaoH1fQvE=@vger.kernel.org X-Gm-Message-State: AOJu0YzIgtbHJvlMlUbCuKJDLDroILor2h6mYSHQe9vgQK6S/7Bh1mfj 9sj+RFgzuXrWejXobAYh05ZunQHUyPRniIXW5rL+Fddqbj1Syeq6SKB8Snrr9A== X-Gm-Gg: ASbGncts68XnxvyGvvzOyK+YvxeY8NeDvpTKqWpmaixlykEcoKy7wZyYXbUgJ4o2Zw0 aBWZYal7RIVL+yDPvUe6bsGtQ9CJPgAvsxx6vD+9D0zfcfUoC+7rSNLG4gLGicXWHbJy8nIXbbC u+N8TfNLrJv0dVqssU97XvjrFZQC93tFmQsCnbkXHv6eBd8FeFbqQPdw0cKiJLu4xHyXGEE2qIZ L4P1Y27yqPIyNx43cf45SPWgT1v71P2w9EVT9MPo/lx+59Wz0WDEvjCW/wrIPYUPSkkPg4ezhM4 feGWDR0= X-Google-Smtp-Source: AGHT+IFBMlFbJctVy/ypJUX6lRvd/RQFlHEGcsLvYlfwp9P4XLmEWnmR34KjHtXYACtXltbyrx4LEQ== X-Received: by 2002:a05:6a20:2455:b0:1d9:3957:8a14 with SMTP id adf61e73a8af0-1eb2146512cmr29760238637.1.1737525560105; Tue, 21 Jan 2025 21:59:20 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:2902:8f0f:12b3:c251]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-abe1a03aa6csm302287a12.2.2025.01.21.21.59.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2025 21:59:19 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 3/7] zram: remove two-staged handle allocation Date: Wed, 22 Jan 2025 14:57:41 +0900 Message-ID: <20250122055831.3341175-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog In-Reply-To: <20250122055831.3341175-1-senozhatsky@chromium.org> References: <20250122055831.3341175-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 | 39 ++++++----------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index b217c29448ce..8029e0fe864a 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1740,11 +1740,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) */ @@ -1758,7 +1758,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, @@ -1777,36 +1776,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.0.rc2.279.g1de40edade-goog