Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3280439rdh; Mon, 27 Nov 2023 10:08:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6LSXOPoJWZytFYQqg5fNife2J1D0+618D2UHzIZNrknG7wPxz1FHpV8o5S5z+/exO4ZMJ X-Received: by 2002:a05:6820:61f:b0:58d:713d:a003 with SMTP id e31-20020a056820061f00b0058d713da003mr6215586oow.3.1701108482167; Mon, 27 Nov 2023 10:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701108482; cv=none; d=google.com; s=arc-20160816; b=ajv43/V62pdcpPTaqKzkWo3KAQy2jPvonLw5w+YPJPUJiKJZ/mQyeQ+zMYygXYb/QP gdis9U0RTfo4haoTwfnnU9mUSD9BCXNcyhj1R3mYawlFeeSROsJxtfsZHakpjePvBo5p WAdDOCsYc7EZCmPxSaRG1pevBv55ggeCmw4Dcy9rwUNNy2cP6A+56JGhJrZOdZe6DdYS 0Xz+IIM5mB4RsHzIrDPaV/ZKhXxoEeZKdLpQ0nFs2zSwKKaKm00IDpublQCT9MYGNcLd bN6J4vz8HZvq4GoPPNHtcnkg3mdf3E2s2xXS1tbsnwFhJGbEnnELrxzpk8GCrYFOzGY5 +uqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=B2Zx7+enx863bwmh/iEYdDd6JfbUcNFrDrlMu0iGHc8=; fh=jhYDS5QDgdaucF0aLnmRBoXdbwJuxm4ji0jaCW/ovTA=; b=vqE94XKY16XsCuJnCM+2XTeIsRurh68X46UrvoAhikh/mTJE0ozpOJJQvwmzVz6OSY 4qUxH0ITG4F8gQ+hhNC/WDLCOy43pszeEIBgQcdLEHYKA8dDb2vdfhdwBWGUrIFDXWWc I2IjmObB1SVyep05DG7kTGhFJRmrJey+aHhLzVfS7szIOHDOP2/Ub1mD5N30OCmRmH2L hfXT2kYmX+Ky5yxASV4lNlPSTvI1P7EdHtR9mFW2DaxrZMaqdftQRE0A5KdmR3SLEPwx yxutTmoQgTDSBv9B0p9Dk2P+I2eYZlRnsfqTUF/ay9iP0O6zxwDU6W1FmzFdERIoJ4Xi udPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FoQycJQr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z21-20020a4a6555000000b0058d210d8680si2137259oog.76.2023.11.27.10.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:08:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FoQycJQr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 863E3802209D; Mon, 27 Nov 2023 10:07:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjK0SHq (ORCPT + 99 others); Mon, 27 Nov 2023 13:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbjK0SHo (ORCPT ); Mon, 27 Nov 2023 13:07:44 -0500 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F1B718F for ; Mon, 27 Nov 2023 10:07:51 -0800 (PST) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1fa619735c1so491544fac.0 for ; Mon, 27 Nov 2023 10:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701108470; x=1701713270; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=B2Zx7+enx863bwmh/iEYdDd6JfbUcNFrDrlMu0iGHc8=; b=FoQycJQrQ6GO2SBUCHDLVgUWC1GnPpU9D9cZs/k8Gr9dfv6E9mC0E215odUZ5OAAln j7duhsj8Bw00bFYB3PND/t7qKrK9FHM1zwURLKws9SNWUZ5lqOA+w0zTJMBSW4iqHNPY jUQCcytpleuHz4yhdjLoeXBEGEiai8qPuvBKOmz+uVBRvFa2fQFvM/a++RZ5+txosBXZ /ddTlZI2DZ5IhSGGWDD297Caw8bK4fZZlD9b2kNnzaQ5tkbkq6jRHhO3VOk6uNf5YctX giSQYrLEQQ5e0DswljMAYgNycP39SOMbjMJA/1I1EvAXcDsT9X8vk8Z4L6IAnEBUz1sc qRqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701108470; x=1701713270; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B2Zx7+enx863bwmh/iEYdDd6JfbUcNFrDrlMu0iGHc8=; b=KuS1TthAMZIYJKC53h/ZcogztvQNDBGGElbLz39ehYIKBZ35CDzJkJBDAbaU1HRY0s kFfw+783pmsNBo6E12D2yNNvHVzdRoEvLGIkKgkl5wHkyX4YZehSDS90pWA/eBV+Sfjv 24cfZka8xTWR2zhX3tkLnT1q4qFN3pR2ix6454L1UOWHscg5wK7cX/X1pqENdGaarNz/ VLLhGYyZxmX4MK4vu1y2/TxrIVb6xltNHBFSITERie3yHRYzwIGGrunQiyz/u+wkgIXe DAJC3afc69kTf9KfY2ea1QlLZ4XIH7oUX8v2afV/SOMZmt7NWwcYyIPii2KfAKRas2xX w0gw== X-Gm-Message-State: AOJu0YyrYfXT6WFM0/q/wc4mk3y5MGPal2AhaqHWoGVpcU+crIc8v0X1 cAc5tVkZ3J5822NV6lF+SIDmib06P3+OJUvZNXo= X-Received: by 2002:a05:6870:1d06:b0:1fa:26e7:c428 with SMTP id pa6-20020a0568701d0600b001fa26e7c428mr10124465oab.19.1701108469637; Mon, 27 Nov 2023 10:07:49 -0800 (PST) MIME-Version: 1.0 References: <20231127160058.586446-1-fabio.maria.de.francesco@linux.intel.com> In-Reply-To: <20231127160058.586446-1-fabio.maria.de.francesco@linux.intel.com> From: Nhat Pham Date: Mon, 27 Nov 2023 10:07:38 -0800 Message-ID: Subject: Re: [PATCH] mm/zswap: Replace kmap_atomic() with kmap_local_page() To: "Fabio M. De Francesco" Cc: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ira Weiny Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 10:07:59 -0800 (PST) On Mon, Nov 27, 2023 at 8:03=E2=80=AFAM Fabio M. De Francesco wrote: > > kmap_atomic() has been deprecated in favor of kmap_local_page(). > > Therefore, replace kmap_atomic() with kmap_local_page() in > zswap.c. > > kmap_atomic() is implemented like a kmap_local_page() which also > disables page-faults and preemption (the latter only in !PREEMPT_RT > kernels). The kernel virtual addresses returned by these two API are > only valid in the context of the callers (i.e., they cannot be handed to > other threads). > > With kmap_local_page() the mappings are per thread and CPU local like > in kmap_atomic(); however, they can handle page-faults and can be called > from any context (including interrupts). The tasks that call > kmap_local_page() can be preempted and, when they are scheduled to run > again, the kernel virtual addresses are restored and are still valid. > > In mm/zswap.c, the blocks of code between the mappings and un-mappings > do not depend on the above-mentioned side effects of kmap_atomic(), so > that the mere replacements of the old API with the new one is all that is > required (i.e., there is no need to explicitly call pagefault_disable() > and/or preempt_disable()). > > Cc: Ira Weiny > Signed-off-by: Fabio M. De Francesco > --- > mm/zswap.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 74411dfdad92..699c6ee11222 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1267,16 +1267,16 @@ bool zswap_store(struct folio *folio) > } > > if (zswap_same_filled_pages_enabled) { > - src =3D kmap_atomic(page); > + src =3D kmap_local_page(page); > if (zswap_is_page_same_filled(src, &value)) { > - kunmap_atomic(src); > + kunmap_local(src); > entry->swpentry =3D swp_entry(type, offset); > entry->length =3D 0; > entry->value =3D value; > atomic_inc(&zswap_same_filled_pages); > goto insert_entry; > } > - kunmap_atomic(src); > + kunmap_local(src); > } > > if (!zswap_non_same_filled_pages_enabled) > @@ -1422,9 +1422,9 @@ bool zswap_load(struct folio *folio) > spin_unlock(&tree->lock); > > if (!entry->length) { > - dst =3D kmap_atomic(page); > + dst =3D kmap_local_page(page); > zswap_fill_page(dst, entry->value); > - kunmap_atomic(dst); > + kunmap_local(dst); > ret =3D true; > goto stats; > } > -- > 2.42.0 > > Probably worth running a couple rounds of stress tests, but otherwise LGTM. FWIW, I've wanted to do this ever since I worked on the storing-uncompressed-pages patch. Reviewed-by: Nhat Pham