Message ID | 20240103095006.608744-3-21cnbao@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4922669dyb; Wed, 3 Jan 2024 01:51:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IG88vne6BOzNn7+Q1JHxTw/6V7g8e81HGqgWlBEKaJXez4mXR2CoTn8tR1yQRS8N/wqrYby X-Received: by 2002:a05:6214:2463:b0:67f:8e5a:a54b with SMTP id im3-20020a056214246300b0067f8e5aa54bmr25471308qvb.111.1704275507875; Wed, 03 Jan 2024 01:51:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704275507; cv=none; d=google.com; s=arc-20160816; b=BSbz1lQDG5+YWrngcQYOOUygHa3q9DyVYA1ktTExth8cq7snhTd+z+UPJnAnWns7Vd 5jRz/WaYIuNfVtpWEGhVu8UnaT8hZT1acbbxvh+JsXS2AiESphkcRNJTesGylL9YziHc 7CMVmmpT2Ml2Y45pDMaIvbODxikF2JhheYocKPmkZWtkJqE1TVEMqwvkOxFLKAhShAjL vMrBrj3sCWZpCBUZOxqEfW2yxbhFa+JJiOTe6vuwhlzDAVO4oZ6Jm6jvbOXNx3T4/3Wr BmmJyPbb4l5+VYaoqE0vFcGFIHacfoWm2qGZgpmPj0D5gaKhXTGrE6GOrXL01ddOFCme JxOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HF2P2SEmq7vRAtkf5d5h6lFP1PY7Yzig5CUd/10AwIg=; fh=LpUaAS5DrShE4mZd8jnG6UaKv7TDk+xEj/1xHkMmhA4=; b=KhO7VcW5/rx7QkFYOta7kvq3c0Q9QMaHMYAUL+672w2p7UIcRAFqFBOntKDe3vQfo6 AxrpkfnJuiHwi4vhhN17akplsihlEiaMwFwqcxP6tiyPtzNM6SdgtjH93OEls8InBOZl U6eXoKEB2WQCUIKSaBZYgXkbAhIUXCXmO68KBiaQW/UVNQU7Jxudz0kcDtbZ7R+9wNUZ QlWwR/CrUnq5A/IqR3db9BbnlXcAbgP9LY95CGZ0MjPXeUjuzqsdpTjl5N10TBI3UN58 KrJUbwW6i7SRt743mmx41WDr8wY8fd7l8x3EDpxofxIgHnmmSafjpAwhdAtODkOCuF4T +YJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VTRu68CT; spf=pass (google.com: domain of linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m13-20020a0cdb8d000000b0067a94bcd063si29116939qvk.178.2024.01.03.01.51.47 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:51:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VTRu68CT; spf=pass (google.com: domain of linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15355-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A7DCB1C23195 for <ouuuleilei@gmail.com>; Wed, 3 Jan 2024 09:51:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA63618E37; Wed, 3 Jan 2024 09:50:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VTRu68CT" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 0D61118E0C; Wed, 3 Jan 2024 09:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6d9bec20980so2479131b3a.2; Wed, 03 Jan 2024 01:50:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704275440; x=1704880240; 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=HF2P2SEmq7vRAtkf5d5h6lFP1PY7Yzig5CUd/10AwIg=; b=VTRu68CTFBoX1r0Mj1eTNq+EXifaN3iJsc1gO40YkQrHijbSbvHDsMwEQiuK2uPR0v eEy2MTuIU7ZJ7VJRIMeOy2tkaQAIJ2PkVEPPzipSzaww4UXcS/6y9Nf1cISOEwDhMiXW XK72tIQ0TkIO6Z8jDkF+xMHUMsYJ7a2+Mvd5jCBhe91OHy9LXQRpL08y7J3rjFxKe9o/ lJhzlVF1suxWh2uhSpFVLISKc/xxWV2BvwZj47DQfpGXmyigc36402nkY4b3SJdzBZKr S3Xm7pgmnWmSVbusBgNQ9USXOgMBbdmIgVGmSan+xCSHhzrjoJ0jrX7oJxGzTi3D5osD MjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704275440; x=1704880240; 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=HF2P2SEmq7vRAtkf5d5h6lFP1PY7Yzig5CUd/10AwIg=; b=p2jnxtZdG/aM6y0jSNjjx4HgTzpP3U63bUFfWqemL/n0RCIl2hf5c70BwFlBvYuZGx T5IuLBTNGT0IHUXiKPse6yPxS7iDmMyu3mRvs/JOUK82SicQmUlU1Fv4x5gtATmIeSXQ 1Twgu5bbXh7SdOwYa+kkgE3HDhRSE9tquc00ASaj9c+da1XCQl4hCGTYLbECzBmmzVoH SzNdZlm18AMaGEFNP569KygghG7XgJrp+dEwhdEubeoR77NEZkgMIX1CQDnq/rfO2sWQ FMM0HApetX/TnCH2fIbNJOd0SrXPsuXIkDbCVKRLFBzvJbV96lEBrT8bURKCDVzQDZus /s4A== X-Gm-Message-State: AOJu0Yzbgs2kc9oot2B901oHR0IR+mfvM3gRL6rWm3oYncbJ4AwMvjo1 h4xrpDN92mhIa4/QLwWvOM8= X-Received: by 2002:a05:6a21:a585:b0:197:7997:b69 with SMTP id gd5-20020a056a21a58500b0019779970b69mr296409pzc.69.1704275440398; Wed, 03 Jan 2024 01:50:40 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a7d6:f37a:9130:cd96]) by smtp.gmail.com with ESMTPSA id a34-20020a631a22000000b005c65e82a0cbsm21823483pga.17.2024.01.03.01.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:50:40 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, ddstreet@ieee.org, sjenning@redhat.com, vitaly.wool@konsulko.com, linux-crypto@vger.kernel.org Cc: chriscli@google.com, chrisl@kernel.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH 2/3] mm/zswap: remove the memcpy if acomp is not asynchronous Date: Wed, 3 Jan 2024 22:50:05 +1300 Message-Id: <20240103095006.608744-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240103095006.608744-1-21cnbao@gmail.com> References: <20240103095006.608744-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787062394901936578 X-GMAIL-MSGID: 1787062394901936578 |
Series |
mm/zswap & crypto/acompress: remove a couple of memcpy
|
|
Commit Message
Barry Song
Jan. 3, 2024, 9:50 a.m. UTC
From: Barry Song <v-songbaohua@oppo.com> Most compressors are actually CPU-based and won't sleep during compression and decompression. We should remove the redundant memcpy for them. Signed-off-by: Barry Song <v-songbaohua@oppo.com> Tested-by: Chengming Zhou <zhouchengming@bytedance.com> --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On Wed, Jan 3, 2024 at 1:50 AM Barry Song <21cnbao@gmail.com> wrote: > > From: Barry Song <v-songbaohua@oppo.com> > > Most compressors are actually CPU-based and won't sleep during > compression and decompression. We should remove the redundant > memcpy for them. > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> nit: it might help to include the test numbers in the changelog in this patch here too. Save a couple of clicks to dig out the original patch cover for the numbers :) > --- > mm/zswap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index ca25b676048e..36898614ebcc 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > struct crypto_wait wait; > u8 *buffer; > struct mutex mutex; > + bool is_async; /* if acomp can sleep */ nit: seems like this comment isn't necessary. is_async is pretty self-explanatory to me. But definitely not a show stopper tho :) > }; > > /* > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > goto acomp_fail; > } > acomp_ctx->acomp = acomp; > + acomp_ctx->is_async = acomp_is_async(acomp); > > req = acomp_request_alloc(acomp_ctx->acomp); > if (!req) { > @@ -1370,7 +1372,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > mutex_lock(&acomp_ctx->mutex); > > src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > - if (!zpool_can_sleep_mapped(zpool)) { > + if (acomp_ctx->is_async && !zpool_can_sleep_mapped(zpool)) { > memcpy(acomp_ctx->buffer, src, entry->length); > src = acomp_ctx->buffer; > zpool_unmap_handle(zpool, entry->handle); > @@ -1384,7 +1386,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); > mutex_unlock(&acomp_ctx->mutex); > > - if (zpool_can_sleep_mapped(zpool)) > + if (!acomp_ctx->is_async || zpool_can_sleep_mapped(zpool)) > zpool_unmap_handle(zpool, entry->handle); > } > > -- > 2.34.1 > The zswap side looks good to me. I don't have expertise/authority to ack the crypto API change (but FWIW it LGTM too based on a cursory code read). Reviewed-by: Nhat Pham <nphamcs@gmail.com>
On Wed, Jan 3, 2024 at 1:50 AM Barry Song <21cnbao@gmail.com> wrote: > > From: Barry Song <v-songbaohua@oppo.com> > > Most compressors are actually CPU-based and won't sleep during > compression and decompression. We should remove the redundant > memcpy for them. > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > --- > mm/zswap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index ca25b676048e..36898614ebcc 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > struct crypto_wait wait; > u8 *buffer; > struct mutex mutex; > + bool is_async; /* if acomp can sleep */ As pointed out in patch 1, I think we should name this explicitly to be about sleep-ability (e.g. sleepable or can_sleep).
On Thu, Jan 4, 2024 at 1:38 PM Nhat Pham <nphamcs@gmail.com> wrote: > > On Wed, Jan 3, 2024 at 1:50 AM Barry Song <21cnbao@gmail.com> wrote: > > > > From: Barry Song <v-songbaohua@oppo.com> > > > > Most compressors are actually CPU-based and won't sleep during > > compression and decompression. We should remove the redundant > > memcpy for them. > > > > Signed-off-by: Barry Song <v-songbaohua@oppo.com> > > Tested-by: Chengming Zhou <zhouchengming@bytedance.com> > Hi Nhat, Thanks for reviewing! > nit: it might help to include the test numbers in the changelog in > this patch here too. Save a couple of clicks to dig out the original > patch cover for the numbers :) Chengming's test data is for the whole series. so i can't find the proper commit to put the data. but it seems Andrew does have a good habit to collect some important cover-letter info to commits, so in v2, i'd keep the commit message as is. > > > --- > > mm/zswap.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index ca25b676048e..36898614ebcc 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { > > struct crypto_wait wait; > > u8 *buffer; > > struct mutex mutex; > > + bool is_async; /* if acomp can sleep */ > > nit: seems like this comment isn't necessary. is_async is pretty > self-explanatory to me. But definitely not a show stopper tho :) Thanks. I am changing the name to is_sleepable according to Yosry's suggestion. As a result, the comment is removed as well. > > > }; > > > > /* > > @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) > > goto acomp_fail; > > } > > acomp_ctx->acomp = acomp; > > + acomp_ctx->is_async = acomp_is_async(acomp); > > > > req = acomp_request_alloc(acomp_ctx->acomp); > > if (!req) { > > @@ -1370,7 +1372,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > > mutex_lock(&acomp_ctx->mutex); > > > > src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); > > - if (!zpool_can_sleep_mapped(zpool)) { > > + if (acomp_ctx->is_async && !zpool_can_sleep_mapped(zpool)) { > > memcpy(acomp_ctx->buffer, src, entry->length); > > src = acomp_ctx->buffer; > > zpool_unmap_handle(zpool, entry->handle); > > @@ -1384,7 +1386,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) > > BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); > > mutex_unlock(&acomp_ctx->mutex); > > > > - if (zpool_can_sleep_mapped(zpool)) > > + if (!acomp_ctx->is_async || zpool_can_sleep_mapped(zpool)) > > zpool_unmap_handle(zpool, entry->handle); > > } > > > > -- > > 2.34.1 > > > > The zswap side looks good to me. I don't have expertise/authority to > ack the crypto API change (but FWIW it LGTM too based on a cursory > code read). > Reviewed-by: Nhat Pham <nphamcs@gmail.com> Thanks! Barry
diff --git a/mm/zswap.c b/mm/zswap.c index ca25b676048e..36898614ebcc 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { struct crypto_wait wait; u8 *buffer; struct mutex mutex; + bool is_async; /* if acomp can sleep */ }; /* @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) goto acomp_fail; } acomp_ctx->acomp = acomp; + acomp_ctx->is_async = acomp_is_async(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1370,7 +1372,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) mutex_lock(&acomp_ctx->mutex); src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { + if (acomp_ctx->is_async && !zpool_can_sleep_mapped(zpool)) { memcpy(acomp_ctx->buffer, src, entry->length); src = acomp_ctx->buffer; zpool_unmap_handle(zpool, entry->handle); @@ -1384,7 +1386,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); mutex_unlock(&acomp_ctx->mutex); - if (zpool_can_sleep_mapped(zpool)) + if (!acomp_ctx->is_async || zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); }