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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFB47C4363A for ; Fri, 23 Oct 2020 14:49:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09F092168B for ; Fri, 23 Oct 2020 14:49:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="MvGnx9vk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09F092168B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 64A816B005D; Fri, 23 Oct 2020 10:49:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FC9C6B0062; Fri, 23 Oct 2020 10:49:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EC936B0068; Fri, 23 Oct 2020 10:49:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id 1E83B6B005D for ; Fri, 23 Oct 2020 10:49:54 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 98F26181AC9CC for ; Fri, 23 Oct 2020 14:49:53 +0000 (UTC) X-FDA: 77403474666.16.taste95_49069492725a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 708C5102AFC93 for ; Fri, 23 Oct 2020 14:49:53 +0000 (UTC) X-HE-Tag: taste95_49069492725a X-Filterd-Recvd-Size: 8287 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 23 Oct 2020 14:49:52 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id e17so2164389wru.12 for ; Fri, 23 Oct 2020 07:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=xePUgVqudoa7FnGpfppkhLWoCoDAn7O+IxyLYMvs6Sc=; b=MvGnx9vkHwpizYCI9ky1WftlKGJyu8gfslaoAiKEIdj22q0PhnMpWAUsJSBX3MFBXx q5Kgm1gIGuREOXqi72Ng1uZ1jttei9ar/c7saDblVfEOptFy7Byma67mTyG2MP3lGf7Q aRqtc82yNyZlus4h+wpJdbS3QLBLSNleBXB9I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=xePUgVqudoa7FnGpfppkhLWoCoDAn7O+IxyLYMvs6Sc=; b=WxbX3mKMJYkHQyX+5ELadtOC5nuNLmHWMFbeEEqhfiviQpMX72TT9lTyHRAEpAaKZK v+2V8ebvAn1lgkMpYaDIawbtdl3cisd55FheGd0szniUtcSuFter3FyJMXNuvM1FdVIQ 37GgLS6yyIbGHyOqc+LW87klJP5m+7whB1PJdzArDnhO2mu4XRYjrY2o2jLGxbRq3v08 2ZSBEz0GxbfB2Ru9kE3mINsnfYx6I91OlauJXC8GYIROzHdwuClJ35jzgOwqpcR5mBa+ xdfZV632CuCbpyl/J2g08FjOT3X5sVq1B5SHEv0qHBd8QY0SL86IWhURF2ewMLf2BBqA Isuw== X-Gm-Message-State: AOAM533T1Aisi35y2tVsJYIFx914DBV9jjjrCEJu3YoI68WrrNhsZwUY 3AXOt6Nqkcvfp4mmxzHUp9R+5w== X-Google-Smtp-Source: ABdhPJyQZR2dXG0RjIsq+LQh8IIHllK8eRs8oeqmDRQIBDJg1umlU3uJqlUglPGV6YHm5CpOm9JoMg== X-Received: by 2002:adf:ef06:: with SMTP id e6mr2966269wro.397.1603464591080; Fri, 23 Oct 2020 07:49:51 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e25sm4069542wra.71.2020.10.23.07.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 07:49:50 -0700 (PDT) Date: Fri, 23 Oct 2020 16:49:48 +0200 From: Daniel Vetter To: "Matthew Wilcox (Oracle)" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@redhat.com, Mikulas Patocka , Jens Axboe , NeilBrown Subject: Re: [PATCH 6/6] mm: Add memalloc_nowait Message-ID: <20201023144948.GE401619@phenom.ffwll.local> Mail-Followup-To: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@redhat.com, Mikulas Patocka , Jens Axboe , NeilBrown References: <20200625113122.7540-1-willy@infradead.org> <20200625113122.7540-7-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625113122.7540-7-willy@infradead.org> X-Operating-System: Linux phenom 5.7.0-1-amd64 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: On Thu, Jun 25, 2020 at 12:31:22PM +0100, Matthew Wilcox (Oracle) wrote: > Similar to memalloc_noio() and memalloc_nofs(), memalloc_nowait() > guarantees we will not sleep to reclaim memory. Use it to simplify > dm-bufio's allocations. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > drivers/md/dm-bufio.c | 30 ++++++++---------------------- > include/linux/sched.h | 1 + > include/linux/sched/mm.h | 12 ++++++++---- > 3 files changed, 17 insertions(+), 26 deletions(-) > > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c > index 6d1565021d74..140ada9a2c8f 100644 > --- a/drivers/md/dm-bufio.c > +++ b/drivers/md/dm-bufio.c > @@ -412,23 +412,6 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask, > > *data_mode = DATA_MODE_VMALLOC; > > - /* > - * __vmalloc allocates the data pages and auxiliary structures with > - * gfp_flags that were specified, but pagetables are always allocated > - * with GFP_KERNEL, no matter what was specified as gfp_mask. > - * > - * Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that > - * all allocations done by this process (including pagetables) are done > - * as if GFP_NOIO was specified. > - */ > - if (gfp_mask & __GFP_NORETRY) { > - unsigned noio_flag = memalloc_noio_save(); > - void *ptr = __vmalloc(c->block_size, gfp_mask); > - > - memalloc_noio_restore(noio_flag); > - return ptr; > - } > - > return __vmalloc(c->block_size, gfp_mask); > } > > @@ -866,9 +849,6 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > * dm-bufio is resistant to allocation failures (it just keeps > * one buffer reserved in cases all the allocations fail). > * So set flags to not try too hard: > - * GFP_NOWAIT: don't wait; if we need to sleep we'll release our > - * mutex and wait ourselves. > - * __GFP_NORETRY: don't retry and rather return failure > * __GFP_NOMEMALLOC: don't use emergency reserves > * __GFP_NOWARN: don't print a warning in case of failure > * > @@ -877,7 +857,9 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > */ > while (1) { > if (dm_bufio_cache_size_latch != 1) { > - b = alloc_buffer(c, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); > + unsigned nowait_flag = memalloc_nowait_save(); > + b = alloc_buffer(c, GFP_KERNEL | __GFP_NOMEMALLOC | __GFP_NOWARN); > + memalloc_nowait_restore(nowait_flag); > if (b) > return b; > } > @@ -886,8 +868,12 @@ static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client > return NULL; > > if (dm_bufio_cache_size_latch != 1 && !tried_noio_alloc) { > + unsigned noio_flag; > + > dm_bufio_unlock(c); > - b = alloc_buffer(c, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); > + noio_flag = memalloc_noio_save(); > + b = alloc_buffer(c, GFP_KERNEL | __GFP_NOMEMALLOC | __GFP_NOWARN); > + memalloc_noio_restore(noio_flag); > dm_bufio_lock(c); > if (b) > return b; > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 90336850e940..b1c2cddd366c 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -803,6 +803,7 @@ struct task_struct { > #endif > unsigned memalloc_noio:1; > unsigned memalloc_nofs:1; > + unsigned memalloc_nowait:1; I think you also need to update gfpflags_allow_blocking() to take your new flag into account, or some debug checks all over the place might misfire. Plus I have a patch which rolls this out to a few more places in all the allocators. -Daniel > unsigned memalloc_nocma:1; > > unsigned long atomic_flags; /* Flags requiring atomic access. */ > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 6f7b59a848a6..6484569f50df 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -179,12 +179,16 @@ static inline bool in_vfork(struct task_struct *tsk) > static inline gfp_t current_gfp_context(gfp_t flags) > { > if (unlikely(current->memalloc_noio || current->memalloc_nofs || > - current->memalloc_nocma)) { > + current->memalloc_nocma) || current->memalloc_nowait) { > /* > - * NOIO implies both NOIO and NOFS and it is a weaker context > - * so always make sure it makes precedence > + * Clearing DIRECT_RECLAIM means we won't get to the point > + * of testing IO or FS, so we don't need to bother clearing > + * them. noio implies neither IO nor FS and it is a weaker > + * context so always make sure it takes precedence. > */ > - if (current->memalloc_noio) > + if (current->memalloc_nowait) > + flags &= ~__GFP_DIRECT_RECLAIM; > + else if (current->memalloc_noio) > flags &= ~(__GFP_IO | __GFP_FS); > else if (current->memalloc_nofs) > flags &= ~__GFP_FS; > -- > 2.27.0 > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch