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 A0DD8C35274 for ; Mon, 18 Dec 2023 08:06:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D1E06B007B; Mon, 18 Dec 2023 03:06:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 15B256B007D; Mon, 18 Dec 2023 03:06:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F16646B007E; Mon, 18 Dec 2023 03:06:47 -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 DC4156B007B for ; Mon, 18 Dec 2023 03:06:47 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A4E3FA02BE for ; Mon, 18 Dec 2023 08:06:47 +0000 (UTC) X-FDA: 81579207654.05.0A91DEA Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf23.hostedemail.com (Postfix) with ESMTP id D72CB140021 for ; Mon, 18 Dec 2023 08:06:44 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VziTFb6P; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702886805; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NKpKYYK42lyrlJVZUzEtCbY2uWIDCagMFLNrbzTht/c=; b=D2FI2T2PbnaY0v6Yc2ypPnpkXmOP7LjU5kpwmlFBTQ2mJlZeWFdEeqiBWP0692o+SpUiYv xA5VVVIdsQS2HOsl7ztCtVNbA/WzjhM/1Uh0ctq+Ab8b38LBfy+oLQFUuI7yn4XJeBxO3x Fpn5GdhtHTyz+eQAnGpmLUtY1r4gXCs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VziTFb6P; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702886805; a=rsa-sha256; cv=none; b=Vcm3BEXHvnAtrwckkAiLMtSBAGx3CXIr12KIjapDt31EDY52b/NzIaZMW5y8rfSgfglKSz PuBE0WWen3NESU37JD/UZNibcQlzLB+k49T7W+IYmvGo+BS5jPsYQBCkSogRUWZxa3a7Br Z38whtYXT1LMfVeNhOznXXKrVI0ZaZU= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d0c4d84bf6so9749845ad.1 for ; Mon, 18 Dec 2023 00:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1702886803; x=1703491603; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=NKpKYYK42lyrlJVZUzEtCbY2uWIDCagMFLNrbzTht/c=; b=VziTFb6PL3GXAPRFAczFTEH8QvkR+6uk3dfG8TYmlNReuhl4VJIUO5Cfjre6h7ge49 XDvAtbNSbu8vTgnMfGGaZoc6kUX4csBmhJBoLcHAYUhisvi8Do6Aj2F0orZLTNDvpf6P cymvFtiw9+peh8+3rqC8jPs06F+Cr94FOXNeXZnMpHg76mjMhJohOmhqc8POzD46Nbei 2C6wvNvlWCy0s2zkfG1AXt69ctM7Wo+9wAH4n2GVZDuTgWRNgmEe56iCexmVpkYDclgu LIYTjBJFDzz0PzbsPru0k1HD192Pe9fhjUlwlfaK5ysNQP2LJyKVzaBEroYXVrGfuW2h qaGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702886803; x=1703491603; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NKpKYYK42lyrlJVZUzEtCbY2uWIDCagMFLNrbzTht/c=; b=DOwV8mom5l6pP18mryNlUFdEqygo5t5qLtCbFzw2NSkt2P3n0muxIR/F64tVduKdMr aYsn2CnfaDeUM4CZYftZILmBNwQtwx2svC0pzIv/MA2E6h5mgwfRYbkAso4z1P9oOapk RN2uAebD5rcJx9o45BJ3xZKuMfbifOPgeP2WhTiDBkOmbZk2Q2mdjsKkUutXhU0bYWVX adZexydd/SGcxQ3RVnAH57sQ0P61zCC2XbTzpYI3s1NZi0sxxms1D3+tktf5pLeBVcYu iPejocOik/lY4CDcyBNXptzQNb3ixoAOjtDfJDvbr6gw/F0823QNyOUw8p8n+36SuSzh FFgQ== X-Gm-Message-State: AOJu0YwI5M1ggDI4L2o3Q8HRR4WBI6XqoO6RK5PFpujxu1ASUIIKMlyQ zzmZ5hecPq5WcIvaQpJ22TgV+g== X-Google-Smtp-Source: AGHT+IEmBpCgHNY3z24DRgeInDn/ZQYlcH3au2XzyksRfAJCYpV0kqf7zyoMsEDi0od3TsN7l4Z/tA== X-Received: by 2002:a17:903:2b03:b0:1d3:6df0:840d with SMTP id mc3-20020a1709032b0300b001d36df0840dmr3174222plb.138.1702886803356; Mon, 18 Dec 2023 00:06:43 -0800 (PST) Received: from [10.4.170.32] ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id s22-20020a170902989600b001d0b6ba60fdsm18404547plp.175.2023.12.18.00.06.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 00:06:42 -0800 (PST) Message-ID: Date: Mon, 18 Dec 2023 16:06:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/5] mm/zswap: reuse dstmem when decompress To: Yosry Ahmed Cc: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> <20231213-zswap-dstmem-v1-1-896763369d04@bytedance.com> <8f80fe3e-a8c7-463d-896b-99575c362839@bytedance.com> Content-Language: en-US From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: f13hkfgk8ebrjgk5mrzrjgodifd8wres X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D72CB140021 X-HE-Tag: 1702886804-539688 X-HE-Meta: U2FsdGVkX1/Vh1YqMVo0yM8w0lwX5Z7gOn7zXaJKVh/7Lr9ef9eAb2Epp8eMTc4kZATokcDoDQdgP/MjRCKUgVLRFgM5nLyRRkyoJ0M6fjqx7kDULfOt3A6G2aml1eBR4OPcz0+HMjJ7M9/Fv+U4Z3xqv3xbhijN3B2C/jk4mV6mA10grKkARadfeIWit9Qk6iUrNWhuTG6oXUg4trP2cxoakvm4/NJrcUo8/vNWAqoyCB9Eqsdp3CdzqGSD5g4/Qh97sCB3oMkhenoH0YVgmJa22tpGwtOiDRLf6dkLInNYHz6FMhwRPuAKGdVBazFgWDiGsaCJYiJKoS0UQbfJFzbaTpXAVHPOPBmf0Uxc22bR86UZ/6wiITl5WWYoFe9LqVMudtC4RxN3pdv3sREkoDwMM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=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 2023/12/15 02:24, Yosry Ahmed wrote: > On Thu, Dec 14, 2023 at 6:42 AM Chengming Zhou > wrote: > [..] >>>>>> - >>>>>> /* decompress */ >>>>>> - dlen = PAGE_SIZE; >>>>>> - src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); >>>>>> + acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); >>>>>> + mutex_lock(acomp_ctx->mutex); >>>>>> >>>>>> + zpool = zswap_find_zpool(entry); >>>>>> + src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); >>>>>> if (!zpool_can_sleep_mapped(zpool)) { >>>>>> - memcpy(tmp, src, entry->length); >>>>>> - src = tmp; >>>>>> + memcpy(acomp_ctx->dstmem, src, entry->length); >>>>>> + src = acomp_ctx->dstmem; >>>>> >>>>> I don't like that we are now using acomp_ctx->dstmem and >>>>> acomp_ctx->mutex now for purposes other than what the naming suggests. >>>> >>>> The "mutex" name is coherent, "dstmem" depends on how we use IMHO. >>>> Change to just "mem"? Or do you have a better name to replace? >>>> >>>>> >>>>> How about removing these two fields from acomp_ctx, and directly using >>>>> zswap_dstmem and zswap_mutex in both the load and store paths, rename >>>>> them, and add proper comments above their definitions that they are >>>>> for generic percpu buffering on the load and store paths? >>>> >>>> Yes, they are percpu memory and lock, but they are used by per acomp_ctx, >>>> and the cpu maybe changing in the middle, so maybe better to keep them. >>> >>> I don't mean to remove completely. Keep them as (for example) >>> zswap_mem and zswap_mutex global percpu variables, and not have >>> pointers in acomp_ctx to them. Instead of using acomp_ctx->dstmem >>> today, we directly use the global zswap_mem (same for the mutex). >>> >>> This makes it clear that the buffers are not owned or exclusively used >>> by the acomp_ctx. WDYT? >> >> Does this look good to you? >> >> ``` >> int cpu = raw_smp_processor_id(); >> >> mutex = per_cpu(zswap_mutex, cpu); >> mutex_lock(mutex); >> >> dstmem = per_cpu(zswap_dstmem, cpu); > > Renaming to zswap_buffer or zswap_mem would be better I think, but > yeah what I had in mind is having zswap_mutex and > zswap_[dstmem/mem/buffer] be generic percpu buffers that are used by > store and load paths for different purposes, not directly linked to > acomp_ctx. > Ok, I'll append a patch to do the refactor & cleanup: remove mutex and dstmem from acomp_ctx, and rename to zswap_buffer, then directly use them on the load/store paths. >> acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu); >> >> /* compress or decompress */ >> ``` >> >> Another way I just think of is to make acomp_ctx own its lock and buffer, >> and we could delete these percpu zswap_mutex and zswap_dstmem instead. > > You mean have two separate set of percpu buffers for zswap load & > stores paths? This is probably unnecessary. Alright. Thanks.