From mboxrd@z Thu Jan 1 00:00:00 1970 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 CDCB7C02194 for ; Fri, 7 Feb 2025 21:07:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C6056B008A; Fri, 7 Feb 2025 16:07:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4752A6B008C; Fri, 7 Feb 2025 16:07:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33CBF6B0092; Fri, 7 Feb 2025 16:07:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 106A26B008A for ; Fri, 7 Feb 2025 16:07:20 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A3BBEB1930 for ; Fri, 7 Feb 2025 21:07:19 +0000 (UTC) X-FDA: 83094384198.14.FA4C592 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf19.hostedemail.com (Postfix) with ESMTP id AEA091A0009 for ; Fri, 7 Feb 2025 21:07:17 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qcsVvhJo; spf=pass (imf19.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738962438; a=rsa-sha256; cv=none; b=lh6Ckm6EBQO++wGFfgpzx5mLL73/DIOLUrZa0JcMDjLPtKp4GYzmD31WGwoadNsnqt82Pk p5c+i4z725mApXkRI9PJ8WNYKvO/M/jL+t7npbP3VrIP7r4Bdf+tUxVwC4OiKb0fvBzYXM 6z9WpN+sfQu+Ff94th1Qf4i7oPuePts= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qcsVvhJo; spf=pass (imf19.hostedemail.com: domain of yosry.ahmed@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738962438; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VmviEOCCZ3FEayvBoB30A6/sggUbm9MiOK3KTy0XkVE=; b=aMDjZywu4pgi48hMrmnX8Y8iTPjRl95hI+b95QQfnqGXVDMJSzgyO+dIq7I0jw/JgBOXou FBM6G5vvRXg1UGGDD47Zga4ykhk0+MC7oOzUc3LoXKu40M0fPCaC8l+EvRnwZd0iJnuquM Nzhp8VbPUPSxfYNAPH28TwjbIo7HD+0= Date: Fri, 7 Feb 2025 21:07:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1738962435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VmviEOCCZ3FEayvBoB30A6/sggUbm9MiOK3KTy0XkVE=; b=qcsVvhJo/u937201RK+UEopjyM3wUvdWfdiDJLWQ/TGHdsmsz7PUbUecjmNK5c+LfQujmC SMNVqs6U2nRaVEyilFbtv2LTRObkeQWO6LS2SaL/8Ofay3BgXUbO37t9JGTyU4NQdJgpP7 9u2+9jRFuiX33Fx08o/gp6mCxUa5o1o= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Sergey Senozhatsky Cc: Kairui Song , Andrew Morton , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv4 02/17] zram: do not use per-CPU compression streams Message-ID: References: <20250131090658.3386285-1-senozhatsky@chromium.org> <20250131090658.3386285-3-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: AEA091A0009 X-Stat-Signature: aj5a3kps4fo393c5zc1zk4mhxgruugyr X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1738962437-435496 X-HE-Meta: U2FsdGVkX19mhuNIg7dkNTRBkM+1jwJUhquwvpKeg6oRjx7pclwVjj+zdG35hLntGiZtxXSvkyWO4/mMm//oI4Jm12bw7r9vuAFmGKNsY4LiEcJRZAI8f+9vA8GvehTCZtc4TvMUW6l0R5ZmpqHhnZMQFsUAIXTb1FWuHtqBrzbQBYQBqjPBkhz49+2HyU6tThcmOWAw5iysgxSyP9ssQpNKVwxke4g3khKYeGazO5kXvBZbjgTPBjMTjJ0eBBCGRLLJqnEd5uS686iP7Uodrxi/gdSSXD66zZpn00AOzg9Tq4lUCnGnhnYEt5CJI1oJmbIKWPp4gCH4q5N5Fird7XWPMsvbBtnByZBhECgMMtjJsjTGaxJMyaJJsuJ0JCtdc3/sQf0RcImYeFfs/goiDJByXhKikx3HKxZ0m/JFW3ljNa5KhDCm7yaby39PKJHoONvpVJWJ3urpc2R3saaBPy4rd3DzEM5ANOcr3j9FXhyEMSycSNW64IhJ2+4Z6SRDxhTA00GCAC8WEetULBoaMj4mPj787U/AryWRYg8fvIWfu1OGerwSculAYMpVUCuqaZOPEb1ETpKNEJea/u+im2m8MBmdRoWtVrOeznpni/LxBTETmLrgbwpRLh4tcZ3F7mHoQ9NVnwmfyE9FXpRaauNWeLXEEZ+dE4RASGyXs1o7mpdMhv/w/HOPuLeYGIkxBKAjBaoQHrsX+Vl1gPfW288a29nAZHhbYbgO+4H6fVo1zWZmLAI2pzpuvBZnlyuZnje1H5YdKMQGtAd2ZlSCs5FoX3oJpnszTkLk1ILuI3HoJwY12lXzhP9kvvutm176eV6rd4aQauyn6RuZUvKu9FK8y6MMPlK2DTGqCrwo1Ss8cnH9fEgqgGk9kz9vyi03Xvrczr0SP6ZQBNRLijuDL29ivgitW1qdW0NpQ9XrBRH+G9oqG786GmkK6b2GLbHRaTIeIQN8PVIMDyHkl2Y M0YlP9i7 hcs46OoJVNsjR8C4SQdfXxlBgDApMKaN1C7M9QIX8VYyCxQzNLLjcb9xD6fCCD8Kia/loszrCmnunuXzp6qoCrfSE3Eu8ISADGc+x9Hv4A7E2OrHs6OJixrCoPZ3nzh4PxY4rpZjngEIU2HDVzhAkTs90h/32Fixz16J4/8Llc2Jea0c7GJrKhsUCp8ikqvhuyRLGhjpp+ashbvukOaaFdFSB3w== 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: List-Subscribe: List-Unsubscribe: On Fri, Feb 07, 2025 at 03:12:59PM +0900, Sergey Senozhatsky wrote: > On (25/02/07 11:56), Sergey Senozhatsky wrote: > > struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) > > { > > for (;;) { > > struct zcomp_strm *zstrm = raw_cpu_ptr(comp->stream); > > > > /* > > * Inspired by zswap > > * > > * stream is returned with ->mutex locked which prevents > > * cpu_dead() from releasing this stream under us, however > > * there is still a race window between raw_cpu_ptr() and > > * mutex_lock(), during which we could have been migrated > > * to a CPU that has already destroyed its stream. If so > > * then unlock and re-try on the current CPU. > > */ > > mutex_lock(&zstrm->lock); > > if (likely(zstrm->buffer)) > > return zstrm; > > mutex_unlock(&zstrm->lock); > > } > > } > > > > void zcomp_stream_put(struct zcomp_strm *zstrm) > > { > > mutex_unlock(&zstrm->lock); > > } > > > > int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node) > > { > > struct zcomp *comp = hlist_entry(node, struct zcomp, node); > > struct zcomp_strm *zstrm = per_cpu_ptr(comp->stream, cpu); > > > > mutex_lock(&zstrm->lock); > > zcomp_strm_free(comp, zstrm); > > mutex_unlock(&zstrm->lock); > > return 0; > > } > > One downside of this is that this adds mutex to the locking graph and > limits what zram can do. In particular we cannot do GFP_NOIO zsmalloc > handle allocations, because NOIO still does reclaim (doesn't reach the > block layer) which grabs some locks internally and this looks a bit > problematics: > zram strm mutex -> zsmalloc GFP_NOIO -> reclaim > vs > reclaim -> zram strm mutex -> zsmalloc > > GFP_NOWAIT allocation has lower success chances. I assume this problem is unique to zram and not zswap because zram can be used with normal IO (and then recurse through reclaim), while zswap is only reachable thorugh reclaim (which cannot recurse)?