From patchwork Wed Jan 22 05:57:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13946860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34FE0C02181 for ; Wed, 22 Jan 2025 05:59:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC5306B008C; Wed, 22 Jan 2025 00:59:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B73E56B0092; Wed, 22 Jan 2025 00:59:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3D376B0093; Wed, 22 Jan 2025 00:59:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 82E1F6B008C for ; Wed, 22 Jan 2025 00:59:23 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2D5851C8696 for ; Wed, 22 Jan 2025 05:59:23 +0000 (UTC) X-FDA: 83034035406.27.CFDF3CD Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf24.hostedemail.com (Postfix) with ESMTP id 6223C180005 for ; Wed, 22 Jan 2025 05:59:21 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="R/PWTpVc"; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf24.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737525561; a=rsa-sha256; cv=none; b=7mUVo4H694+HHOxraRpxp/dRlN6ab4VC0F6Z94beBDlPgjJexQ0xh6AiQ9zqv2W1c7bSFA B5Hv1N1FUHIDPFerTtwbKMWhCfyKv346kxgCgK4vUDVxN58vV5XBhpivzlNE8pdMmYgV2l csuVueJYFmmLugpvqp5yjn9rDWx2AkU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="R/PWTpVc"; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf24.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737525561; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SJ+ga7y6+gKF81TWcu7LgFAJ2gVF/zL45vImj5BpZyE=; b=PyFzudcQQdziKr6Z1EhCcRRRwVOKlUNjDTe2v4RtUDhDbKLSV8ObQrXZCUl3yfwKizqgSU DZBwYZLNoWZj7jTRhsCmR303rWL4f9LafOFAElR5aRXsnegZ9kTHpopoN6wddXwKAIFLfs 2uemzmlwVbM2VM55BsBOp17Xy649CkU= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2166360285dso124805185ad.1 for ; Tue, 21 Jan 2025 21:59:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737525560; x=1738130360; darn=kvack.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=R/PWTpVc1dHOgs2i8++xc8+10Ufma15+j38nKJoJWd8jxmWvYprz/CcnNXBA3V6iyh y54R9VqZYO2Vg5xrqDVAg0PFFmeoQuXM3BSqoGJQJ2d/zorj1LRqfwOB2yiyLD3fVuZ8 GbQEu4b3u8bmOUlzn30aO3fpWvqC5hol15vbE= 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=t2+dxj5Yrx8oZs/mpmwhRjtiZDCC9YNiH1zdoAbZGkntiIHJHJCm2PgvngewHQZ2fo gddFHvu7mIH2HG4fGH353Bi5x4gbmasBQzd/CVt3AR8T289ceFcCVUgEislsxaqe0cpg mqORj0s1ljByvtD4G+oSCcmlFMwxkkjKSka1lU/Bj2xgH/0NI5k49Ijsu0xxQt/8AZ5a TFm80xMZaqqOuZi9MNNZBQYE0bz2XRW/80jhWXk/m4fbW35AZ8fi/dQXAMzoTSTSe6j9 6mTN8+cLDvC2JOLMsQ9gDXiwEFICEjuswpuZbHDmZIikeKzXpkxTAoDhd5mcamw7FukU jyug== X-Gm-Message-State: AOJu0YzUIChCxyYTaFSSiZ9ygry8zLIHdNjLhG7sZaFqtMyqCGSr3Aye pRR+kHBNNF7HcadQIMuFhaoJr/67/G9cAIV+m2HKA9kte7wy9gHsZ1TO+Bqi/A== X-Gm-Gg: ASbGnctngpJhcN13bawUP5g8zGnYaCSQ5/oMoFru5QRWO8UGl88ImAxnFzPWcRhuGjK iII75Vwt0SDeKr2/lj2iVhQuZ4AF4er+R+85cV7jLS6KUs9kUUiVSUK9teCzqMbdQF3E2X7a+w6 0yxoME7qvsekxppGkn9nYzO3CnxtprifYjSLa8pTIGo3DSzlfjj7cDWYKrozKR+akOw5P893w3D k2b/p8oDkYQWtoRCAofMqzK1hr72yxBomV1pzU3V3cJUi6WcUl9RoqQtWpv6mFLXlYbve4QDqWX 1tXWRWE= 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> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6223C180005 X-Rspamd-Server: rspam10 X-Stat-Signature: k5em9s54kiu7eraj14jjdgfeqwsprucy X-HE-Tag: 1737525561-78125 X-HE-Meta: U2FsdGVkX19v5mFQzjtC3Ayz4Zz2SimpIU+l2fs8dRfKYT41x0nzg+R2yiNoHxXnCEMpSIlq0ZWiqBpd2nEsm1Ss/AC4c8F3ITdWymv3wdZ7XU7ljxTj/Mjf0bstJdpuArk+b1EYqXmzz1AokFh8HIqYPEqeMSzVbmcr2FpBLukN6AGGhqlZkxkqf3U1uwp9UjTf1IzvpyPoN+c8WsREugNitCP4aqlRI6V1fAGcKr1qhsHJiW9cPtGSYcYPwRM7LzjxSKMwfzXq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ux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 *zram, struct page *page, static int zram_write_page(struct zram *zram, struct page *page, u32 index) { int ret = 0; - unsigned long handle = -ENOMEM; - unsigned int comp_len = 0; + unsigned long handle; + unsigned int comp_len; void *dst, *mem; struct zcomp_strm *zstrm; - unsigned long element = 0; + unsigned long element; bool same_filled; /* 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); -compress_again: zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); mem = kmap_local_page(page); ret = zcomp_compress(zram->comps[ZRAM_PRIMARY_COMP], zstrm, @@ -1777,36 +1776,10 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) return write_incompressible_page(zram, page, index); } - /* - * 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 = zs_malloc(zram->mem_pool, comp_len, + GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle)) - handle = 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 = 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); if (!zram_can_store_page(zram)) { zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm);