Message ID | 20221122013338.3696079-1-senozhatsky@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1942139wrr; Mon, 21 Nov 2022 17:36:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4CLJFpTzIljicNlpaMI/DGH4yrQcQz+GkxmFQEgbIK+Gk9iFYypQCteitmKrGA4AqfUkv+ X-Received: by 2002:a17:906:130b:b0:7ad:92c5:637a with SMTP id w11-20020a170906130b00b007ad92c5637amr17762799ejb.87.1669080968416; Mon, 21 Nov 2022 17:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669080968; cv=none; d=google.com; s=arc-20160816; b=MAUGoaLLujsDMF35GTz2SV31SWqZsbVxhTm3ZTAxM7Ke3xdOFDwhZ8qZp/IMEsBQbL DHaYuVRxI/wz8RbPa6j6Rc0N6Kd6FdynS1UE2yL8FcWMGj+Qslj8YDgDK3cF/foecBqf NWM9h6zq2xCQCzSqxYR04YpaKsNZc4K6Qi+zEfE3397H9uS/TCpdgn3HMcr1Ic2D+Nzz gj1yj0q8t9lWAMy+zxG5Ju9V5ZvJWo7kwfqYcBc5w0PWh0MKLxtg2kaXluph08Ahhnzd JBkO4px33B24UryvvwybXvzfrO/3stKZdQvwx/L+kwqVh7KdPG+sqDK2YOObT+g/1DIW JNaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SUuSpc6C+EWicKThxRXH7zHFoDctbTavto9TGkNgwqg=; b=ItD9AR8ZeO2L7fTDo74SoWL6byLkZNd+zIfKu8zqLw0z9pB4gYlHg0KRnrZPoFjPUO kAokSzRXKwuIkvWZADPV4cqRMW7ZmBUrCt66SvPB0NzcxuqWWcyeba2FbHv54pL5jG5H QDTdoKT63nDv5t4LmUPmXp3ipzEm0jYnyS2VUzlvcFT0VDc8Z/rLKC7A8jO2H2vfRZ3w fWdgNQz/sTJnt4thXlEK2B6aeh6Sj1fUo/aehWBvu7R3YozTK7VBHUX1M7NU7O1phoea UC2S2/h0KmzaQvxUtvKamJLP22paKL5OLHFTqWdG6EFC+/e/FRAGWpCEsNUgEshf4Cl1 wuDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YDCgA5iL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020a170906251500b0078da3218b54si8045571ejb.171.2022.11.21.17.35.44; Mon, 21 Nov 2022 17:36:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YDCgA5iL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbiKVBeI (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Mon, 21 Nov 2022 20:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbiKVBdz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 20:33:55 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4E8E06A8 for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 17:33:54 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id p12so12206135plq.4 for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 17:33:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SUuSpc6C+EWicKThxRXH7zHFoDctbTavto9TGkNgwqg=; b=YDCgA5iLVRHov7CSFOzKyS+DAzYZ+IvJ03MR4Sv4SfTmjSMDNZHUUzCIBVUVmFT8uv JKfDo3JrYanqKt0RTFkeqYj5Xjo4DBrmSVvRJ5wQxDqvUUOAUjRDPWUmuyTB3qkQmO0D TfDuOJkS0w5/G+upcxqS2TjbFjppHHryLmxW8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SUuSpc6C+EWicKThxRXH7zHFoDctbTavto9TGkNgwqg=; b=cInZVNf3ukrSbid4Cp3Kz+O9DvwS4e+CYCGmxU2lPGc0vx0uMld1g2+9ANSj81OFxP 8AOb3Sas+gJuYiNhfcP/t5vZAwv1wNncSPbArb3uvndm4KCf38AfCHaJgA8zsjFyyBlh rImRJMA05wNWLtJmZdxtEV8+CcwL0KSFCtwYQve/C/raIg+GdP0f21D0eOqXN3cEgh3u A0UPoc0V2XjjqUJILvNSONJ6oMhZn/pWS/X/sQ4r4umEgfRj9UA+maIqv6ByCMWjDJ1Y 4iTlrKMkfLZKScrbDSXzwJVxWvuqjA0QnGIm6NWtll3mNRbVqkzUqQmr2mIVnQmYMiu4 pozg== X-Gm-Message-State: ANoB5pksXqUTgu74X1nm7t5yUY2fZot4PgyKoR5e7WeD0jdoJlF41G/T 8ovRIwDpOs4eCDmE4gpFGPzwqQ== X-Received: by 2002:a17:90b:364f:b0:218:b6d0:2529 with SMTP id nh15-20020a17090b364f00b00218b6d02529mr7023070pjb.75.1669080833896; Mon, 21 Nov 2022 17:33:53 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:9797:eb69:44a4:a633]) by smtp.gmail.com with ESMTPSA id z22-20020a63e116000000b0046ec0ef4a7esm8099914pgh.78.2022.11.21.17.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 17:33:53 -0800 (PST) From: Sergey Senozhatsky <senozhatsky@chromium.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Seth Jennings <sjenning@redhat.com>, Dan Streetman <ddstreet@ieee.org>, Vitaly Wool <vitaly.wool@konsulko.com>, Nhat Pham <nphamcs@gmail.com>, Johannes Weiner <hannes@cmpxchg.org>, Minchan Kim <minchan@kernel.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky <senozhatsky@chromium.org> Subject: [PATCH] zswap: do not allocate from atomic pool Date: Tue, 22 Nov 2022 10:33:38 +0900 Message-Id: <20221122013338.3696079-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750158245311845787?= X-GMAIL-MSGID: =?utf-8?q?1750158245311845787?= |
Series |
zswap: do not allocate from atomic pool
|
|
Commit Message
Sergey Senozhatsky
Nov. 22, 2022, 1:33 a.m. UTC
zswap_frontswap_load() should be called from preemptible
context (we even call mutex_lock() there) and it does not
look like we need to do GFP_ATOMIC allocaion for temp
buffer there. Use GFP_KERNEL instead.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
mm/zswap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue, 22 Nov 2022 10:33:38 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > zswap_frontswap_load() should be called from preemptible > context (we even call mutex_lock() there) and it does not > look like we need to do GFP_ATOMIC allocaion for temp > buffer there. Use GFP_KERNEL instead. > > ... > > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1314,7 +1314,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, > } > > if (!zpool_can_sleep_mapped(entry->pool->zpool)) { > - tmp = kmalloc(entry->length, GFP_ATOMIC); > + tmp = kmalloc(entry->length, GFP_KERNEL); > if (!tmp) { > ret = -ENOMEM; > goto freeentry; It seems strange to do if (! can sleep) do something which can sleep or am I misreading the intent of zpool_driver.sleep_mapped? If so, perhaps some explanatory code comments will help.
On (22/11/21 17:56), Andrew Morton wrote: > > zswap_frontswap_load() should be called from preemptible > > context (we even call mutex_lock() there) and it does not > > look like we need to do GFP_ATOMIC allocaion for temp > > buffer there. Use GFP_KERNEL instead. > > > > ... > > > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -1314,7 +1314,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, > > } > > > > if (!zpool_can_sleep_mapped(entry->pool->zpool)) { > > - tmp = kmalloc(entry->length, GFP_ATOMIC); > > + tmp = kmalloc(entry->length, GFP_KERNEL); > > if (!tmp) { > > ret = -ENOMEM; > > goto freeentry; > > It seems strange to do It does indeed. > if (! can sleep) > do something which can sleep Some allocators enter the non-preemptible context in ->map callback and exit that context in ->unmap. zswap uses async compression and needs to wait for crypto to finish decompression of the mapped object, which it cannot do when allocator disables preemption in ->map. So for allocators that do this zswap allocates a temp buffer, then maps the object, copies it to that temp buffer and unmaps the objects. So now it can wait for async crypto because we are in preemptible context and we use the temp copy of the object. > or am I misreading the intent of zpool_driver.sleep_mapped? If so, > perhaps some explanatory code comments will help. I can add one. I assume at mm/zpool.c zpool_can_sleep_mapped() would be the right place.
On Tue, Nov 22, 2022 at 10:33:38AM +0900, Sergey Senozhatsky wrote: > zswap_frontswap_load() should be called from preemptible > context (we even call mutex_lock() there) and it does not > look like we need to do GFP_ATOMIC allocaion for temp > buffer there. Use GFP_KERNEL instead. > > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> > --- > mm/zswap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 2d69c1d678fe..f6c89049cf70 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1314,7 +1314,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, > } > > if (!zpool_can_sleep_mapped(entry->pool->zpool)) { > - tmp = kmalloc(entry->length, GFP_ATOMIC); > + tmp = kmalloc(entry->length, GFP_KERNEL); There is another one in zswap_writeback_entry() that seems equally arbitrary. They came in through the same commit, with no further explanation as to this choice. Do you want to pick that up too?
On (22/11/21 22:16), Johannes Weiner wrote: > On Tue, Nov 22, 2022 at 10:33:38AM +0900, Sergey Senozhatsky wrote: > > zswap_frontswap_load() should be called from preemptible > > context (we even call mutex_lock() there) and it does not > > look like we need to do GFP_ATOMIC allocaion for temp > > buffer there. Use GFP_KERNEL instead. > > > > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> > > --- > > mm/zswap.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index 2d69c1d678fe..f6c89049cf70 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -1314,7 +1314,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, > > } > > > > if (!zpool_can_sleep_mapped(entry->pool->zpool)) { > > - tmp = kmalloc(entry->length, GFP_ATOMIC); > > + tmp = kmalloc(entry->length, GFP_KERNEL); > > There is another one in zswap_writeback_entry() that seems equally > arbitrary. They came in through the same commit, with no further > explanation as to this choice. Do you want to pick that up too? Yup, you patch it in https://lore.kernel.org/lkml/20221119001536.2086599-2-nphamcs@gmail.com/ and I guess it's there just by accident. We probably want a separate patch instead that touches those GFP_ATOMIC allocations in both places. So I have it like this at present --- From 66e4acffc0926498f818d11f2f57b9c772131f6e Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky <senozhatsky@chromium.org> Date: Tue, 22 Nov 2022 10:26:13 +0900 Subject: [PATCH] zswap: do not allocate from atomic pool zswap_frontswap_load() should be called from preemptible context (we even call mutex_lock() there) and it does not look like we need to do GFP_ATOMIC allocaion for temp buffer. The same applies to zswap_writeback_entry(). Use GFP_KERNEL for temporary buffer allocation in both cases. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Nhat Pham <nphamcs@gmail.com> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> --- mm/zpool.c | 7 +++++++ mm/zswap.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/zpool.c b/mm/zpool.c index 68facc193496..f46c0d5e766c 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -387,6 +387,13 @@ bool zpool_evictable(struct zpool *zpool) * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped. * @zpool: The zpool to test * + * Some allocators enter non-preemptible context in ->map() callback (e.g. + * disable pagefaults) and exit that context in ->unmap(), which limits what + * we can do with the mapped object. For instance, we cannot wait for + * asynchronous crypto API to decompress such an object or take mutexes + * since those will call into the scheduler. This function tells us whether + * we use such an allocator. + * * Returns: true if zpool can sleep; false otherwise. */ bool zpool_can_sleep_mapped(struct zpool *zpool) diff --git a/mm/zswap.c b/mm/zswap.c index 2d48fd59cc7a..3019f0bde194 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -958,7 +958,7 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle) }; if (!zpool_can_sleep_mapped(pool)) { - tmp = kmalloc(PAGE_SIZE, GFP_ATOMIC); + tmp = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!tmp) return -ENOMEM; } @@ -1311,7 +1311,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, } if (!zpool_can_sleep_mapped(entry->pool->zpool)) { - tmp = kmalloc(entry->length, GFP_ATOMIC); + tmp = kmalloc(entry->length, GFP_KERNEL); if (!tmp) { ret = -ENOMEM; goto freeentry;
On (22/11/22 12:30), Sergey Senozhatsky wrote: > zswap_frontswap_load() should be called from preemptible > context (we even call mutex_lock() there) and it does not > look like we need to do GFP_ATOMIC allocaion for temp > buffer. The same applies to zswap_writeback_entry(). > > Use GFP_KERNEL for temporary buffer allocation in both > cases. > > Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> > Signed-off-by: Nhat Pham <nphamcs@gmail.com> > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> > --- Folks, how do we want to proceed with this? One of the hunks here conflicts with https://lore.kernel.org/lkml/20221119001536.2086599-2-nphamcs@gmail.com/ Do we want to remove conflicting hunk from "[PATCH 1/6] zswap: fix writeback lock ordering for zsmalloc" and pick this patch up? > diff --git a/mm/zpool.c b/mm/zpool.c > index 68facc193496..f46c0d5e766c 100644 > --- a/mm/zpool.c > +++ b/mm/zpool.c > @@ -387,6 +387,13 @@ bool zpool_evictable(struct zpool *zpool) > * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped. > * @zpool: The zpool to test > * > + * Some allocators enter non-preemptible context in ->map() callback (e.g. > + * disable pagefaults) and exit that context in ->unmap(), which limits what > + * we can do with the mapped object. For instance, we cannot wait for > + * asynchronous crypto API to decompress such an object or take mutexes > + * since those will call into the scheduler. This function tells us whether > + * we use such an allocator. > + * > * Returns: true if zpool can sleep; false otherwise. > */ > bool zpool_can_sleep_mapped(struct zpool *zpool) > diff --git a/mm/zswap.c b/mm/zswap.c > index 2d48fd59cc7a..3019f0bde194 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -958,7 +958,7 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle) > }; > > if (!zpool_can_sleep_mapped(pool)) { > - tmp = kmalloc(PAGE_SIZE, GFP_ATOMIC); > + tmp = kmalloc(PAGE_SIZE, GFP_KERNEL); > if (!tmp) > return -ENOMEM; > } > @@ -1311,7 +1311,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, > } > > if (!zpool_can_sleep_mapped(entry->pool->zpool)) { > - tmp = kmalloc(entry->length, GFP_ATOMIC); > + tmp = kmalloc(entry->length, GFP_KERNEL); > if (!tmp) { > ret = -ENOMEM; > goto freeentry; > -- > 2.38.1.584.g0f3c55d4c2-goog >
On Thu, 24 Nov 2022 12:32:45 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > Folks, how do we want to proceed with this? One of the hunks here > conflicts with https://lore.kernel.org/lkml/20221119001536.2086599-2-nphamcs@gmail.com/ > > Do we want to remove conflicting hunk from "[PATCH 1/6] zswap: fix writeback > lock ordering for zsmalloc" and pick this patch up? > The "Implement writeback for zsmalloc" series is clearly due for one or more new versions, so I will drop that series and I will apply "zswap: do not allocate from atomic pool". Let's ask Nhat Pham to prepare future revisions of the "Implement writeback for zsmalloc" series against mm-unstable.
On Wed, Nov 23, 2022 at 7:42 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Thu, 24 Nov 2022 12:32:45 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > > > Folks, how do we want to proceed with this? One of the hunks here > > conflicts with https://lore.kernel.org/lkml/20221119001536.2086599-2-nphamcs@gmail.com/ > > > > Do we want to remove conflicting hunk from "[PATCH 1/6] zswap: fix writeback > > lock ordering for zsmalloc" and pick this patch up? > > > > The "Implement writeback for zsmalloc" series is clearly due for one or > more new versions, so I will drop that series and I will apply "zswap: do > not allocate from atomic pool". Let's ask Nhat Pham to prepare future > revisions of the "Implement writeback for zsmalloc" series against > mm-unstable. Will do! Apologies for the constant churning - but this should be a quick and easy change from my end. v7 should be out next week. Have a nice Thanksgiving everyone!
diff --git a/mm/zswap.c b/mm/zswap.c index 2d69c1d678fe..f6c89049cf70 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1314,7 +1314,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, } if (!zpool_can_sleep_mapped(entry->pool->zpool)) { - tmp = kmalloc(entry->length, GFP_ATOMIC); + tmp = kmalloc(entry->length, GFP_KERNEL); if (!tmp) { ret = -ENOMEM; goto freeentry;