Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp639070pxu; Fri, 23 Oct 2020 09:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGvDa9XdyGWRYZUyH+U9jJLJPk9DQW5ShqCuZDLvZ5X/eWE0VSP0/5bDU6q7abFgEib7b9 X-Received: by 2002:a17:906:aed9:: with SMTP id me25mr2878282ejb.52.1603470778042; Fri, 23 Oct 2020 09:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603470778; cv=none; d=google.com; s=arc-20160816; b=Mu5XfpyNcL6WTx/WkgT6aS+sxQYLpEmu7zRQ6XkyuxKmK0DOBA1CcQPO5/zueyP6uZ +Om2YJoIKZnNmmI4JFT4HDKI8jNh4HuMosKjP3UpVCpByp4QHUcWCl1w9sQ1U2/5hWYq va82+0/nz2AFeOo+ZgxuJvNk9AGPBuy3a7vsemZULjIhkL45c8c95v6V5Qc8QtaREbv3 rmqvMVYonwO9+oRu+AMzdxb7TKHoMxydn1rHVdxowbJm6s4xntCQtb6hWaJ5XsB/mLmb b6bgTDL38niqCUA3FR1L0N/3MalMdiQIQLOUcLsAY895p3OJGhjeyENt0zoSHY3EvdVL MUDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xePUgVqudoa7FnGpfppkhLWoCoDAn7O+IxyLYMvs6Sc=; b=ZhEbbfPeIy2lTitfgznbNwNzQK2/G7RUmDbTq8nvQAeGY3rgNUAIyXvydvXAZ5V1bM Oz19SA6AHRmVZP7N6+925qYnvsiAB5l4Y+1aDum+aSzzocxNwgTBKMj9LWDzlEJGyDbN 98/TS7XOa0vNqZq87hARNWgepM6d8flXHhcaUJF7e6rn2UAhNDDoI24BpZsfMaeAMqX5 fPVvFJo9mm4eSo2T5xNVnFlmw3K6gvW+tLmWTroKIRHH3Ka4Hs9r8zZYq1N1Nnyr13mq JYBbaE1hgxPdyD7MR4tN3gz5IY0+LvzwORtgWr6/4YLTDl3n3X4neM+IvEvHdkZCpvAY uZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=MvGnx9vk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd22si1489468ejb.101.2020.10.23.09.32.35; Fri, 23 Oct 2020 09:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=MvGnx9vk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S460564AbgJWOtx (ORCPT + 99 others); Fri, 23 Oct 2020 10:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896924AbgJWOtx (ORCPT ); Fri, 23 Oct 2020 10:49:53 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65309C0613CE for ; Fri, 23 Oct 2020 07:49:52 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id s9so2169169wro.8 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=d3JOEDPIb+nUGC3b9IKtdeIpq/jCAQ9AEaEcIJu42cLTeJUyErYHbz3asGGBj0gQsJ ihiH+jc81s3+eTDxX9KXhQYu6J7snKeZsSA8ePLGBbdndwhP6Y35HCRr4pn3LfPubFyG /2VtJcAUYqkADyCcK8F/Rv/g/8QWlSuGQXutGU8zPS+nA9ju84H2jpzrRYdXnolpDdJe gB68gQbuHPYRKX+C6GY9TXTVDA5lkmfaD/hnkurlpyUtc7m7lZ8puUTDVNk5TeGs/V9r Uq/Wz5/u+n8e/N1CglxPGnDiRDOiycZpc28jAaXspGzVot8saWUjtvODvXnMVo8aqU8v EXcw== X-Gm-Message-State: AOAM533uhQ6iV+qnqFYJ9uHIEBzoaVUCacCAdQUO/KsRy4JxrTBpBn7w 214JW+kfjFTYh1Gh5hDzpHTR8g== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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