Message ID | 20250130111105.2861324-7-senozhatsky@chromium.org (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 19914C0218D for <linux-mm@archiver.kernel.org>; Thu, 30 Jan 2025 11:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2CE7280282; Thu, 30 Jan 2025 06:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B6302800D6; Thu, 30 Jan 2025 06:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85854280282; Thu, 30 Jan 2025 06:12:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 640352800D6 for <linux-mm@kvack.org>; Thu, 30 Jan 2025 06:12:08 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7694C42C04 for <linux-mm@kvack.org>; Thu, 30 Jan 2025 11:11:45 +0000 (UTC) X-FDA: 83063852970.30.DD3A6CA Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 907D7100011 for <linux-mm@kvack.org>; Thu, 30 Jan 2025 11:11:43 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=mAdAWVYR; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738235503; 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=5g614UtqxTvOkBYeQdwAP9Uo/j0Alc44lQaUMvbAkkk=; b=U3DisQqBkmpljGGwjMNqYqDJYO7iWZcaTV0trZ8JUoLvOtdUQbO1YJt0T+xpLl1rxg4DGS GzgxfmbbPMAkOhQOPjtW4FowHDjHN0UBww/vBjbP0EwtxybdW9mn+n8aIA25ZT6xPDP2H8 08buMJDZGbes/kC/4ozk/11wnLiV6y0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738235503; a=rsa-sha256; cv=none; b=Nae6ETYO/r0hxI/YHOeMKyPZv4WLmMQuursCtXWyZs8zOPq/X7B5P+Ob5A1+UOYXrizsxu Yt6eBSoxbwAMa20sqfGgrkpx/dm3YSaV+KPqxUqArPT1sjAK51ZxL39lsY4dK/3BMqAuF1 nLP17emVGnSyVoYydS/xfRqx230fEBA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=mAdAWVYR; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ee46851b5eso754819a91.1 for <linux-mm@kvack.org>; Thu, 30 Jan 2025 03:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1738235502; x=1738840302; 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=5g614UtqxTvOkBYeQdwAP9Uo/j0Alc44lQaUMvbAkkk=; b=mAdAWVYRF0L0jjsF7eggi0Znyb8Fy0G50U3EjOb/QkLoWaSdCZY/pTh7LRizx4LISw OirGfTFSIVzjfnEXJqTUms+/fpq0OSDT9N+I/Ju+p9VZXKuMt4aHsl7lEKalYaaypYrF ui0AJqDVwps8wxA6MOAOhDLOsp5pqMtr/WY44= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738235502; x=1738840302; 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=XasRq1dpRwaIJ6YBjLzdF8CFdBcuHSMvCCR9XJl3exbt1ZT9QJGZeRqzQgwDiJ/Tae gfiNhM/BzHGAkSeJb6ge4cfM/dvCkihaPy2O6nVI3+YcBb2U3iFa6nxc11o8POdtaX24 CW6Ckcf+t/0jE2UyMzCni+EE2vZ6k3J+gZ3yhpAFVw9vtcUAjhVFIYouliqZTL0TH4Xb j3WZRTp9thKt1P+tWZsIj9/vmTtyWG9UtMrE1VpUZQ3+YMWu5PyU8+6TqJeT0wEPgK26 eeW81b2tnxfIezT+vvcDGIt2/dD0+FENRjFd0nWDA43nVmkVWJt0JjeIGToGoxhCkzRb ocqw== X-Forwarded-Encrypted: i=1; AJvYcCVeHeWX2RldG4SnxUXB27wP1eHmLmjBeaNFSoH6khJFQuUb1hO/ttiPtz7mEtfSmYK/GPql9d2s5Q==@kvack.org X-Gm-Message-State: AOJu0YybxF7ewDW67JgcvmN9bMesphFdwzRBhI9xbQNwY7k8wKRND6/n CM49Shax5r/XvlcgOctfIlbJWp48mAkicfqMeTDYFgZJ9GLPWbXgqdJ4q3vFeQ== X-Gm-Gg: ASbGncvufV5jYCqgv+UYZsERuEpSKDt0nbtC0QVAvBjlrRJRDAsFdHaz5Exi65x6gFW nhQ4v8Rc2fWJ39eznkie6x/3uEZaVsSDkmCkMSk8LyeD1/hyqti3hwHgr/NsM3Eal6KCa+P4Ry8 euG9rgd6Sh/jBOuyfAJ7hXdJgKVZiA3+mlGiq9Fm65i+qn8sldwqfD5OmyoFnsVOFYdACwst994 UR+siVeDUR+YBxvpUuCUyaYe8KoogOvorcZ7w19hdpqoN3AtgWUMQO+9M7oZypSSDafWr8eAaot +E3gHqKc8y2BjylU X-Google-Smtp-Source: AGHT+IHg3heFJ21F+Ok092BsmeTSf/u5V4ef9+jPuKs0cnRlT5yUCtdKYPEIddDVnItYsVqEn0xRFg== X-Received: by 2002:a17:90b:4d06:b0:2f4:49d8:e6f6 with SMTP id 98e67ed59e1d1-2f83aba9d34mr9404404a91.3.1738235502347; Thu, 30 Jan 2025 03:11:42 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:d4ce:e744:f46b:4fb]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f848acbda4sm1333892a91.45.2025.01.30.03.11.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Jan 2025 03:11:42 -0800 (PST) From: Sergey Senozhatsky <senozhatsky@chromium.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Minchan Kim <minchan@kernel.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky <senozhatsky@chromium.org> Subject: [PATCHv3 06/11] zram: permit reclaim in zstd custom allocator Date: Thu, 30 Jan 2025 20:10:51 +0900 Message-ID: <20250130111105.2861324-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250130111105.2861324-1-senozhatsky@chromium.org> References: <20250130111105.2861324-1-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: zobe6tt6jpuw3kp4fftkkuujy8xao5kq X-Rspam-User: X-Rspamd-Queue-Id: 907D7100011 X-Rspamd-Server: rspam03 X-HE-Tag: 1738235503-717894 X-HE-Meta: U2FsdGVkX196m0uFYSDbyKpuBEicjOeqvRCzA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zk54wRydmiCD4DX2IMVXjDPBWFQajKXhBgP2cnubhOfMDWcCxelCpeOO0Yk23177Y3KvztDW6lHoGizS8aGW8Idusj4oHCaNnkb6HR7biXxrKhB+iV1JMZnc85HZb/b7Woj3aq5nzh+c3uFrB9jX9AHbsZ62UGvPSYOsQisxIbLRqGzQw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
zram: preemptible writes and occasionally preemptible reads
|
expand
|
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_compress() - * 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); - return kvzalloc(size, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN); + return kvzalloc(size, GFP_NOIO | __GFP_NOWARN); } static void zstd_custom_free(void *opaque, void *address)
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 <senozhatsky@chromium.org> --- drivers/block/zram/backend_zstd.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)