Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2951760imm; Thu, 24 May 2018 19:45:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp68Dxkx9+FSIChYaTwmoq6r3AM8CA7FvNYkn1xxhQsGXrws3G4zsL+OhuJtfY6PCr4Xnju X-Received: by 2002:a17:902:848b:: with SMTP id c11-v6mr645173plo.132.1527216351266; Thu, 24 May 2018 19:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216351; cv=none; d=google.com; s=arc-20160816; b=kqIYINgT9J9W3wbv5EkXFQuYPIEcD3WbHIWqELqssVqHpELFbqEZyKD+Wxom1XGfnp 2lNwMie2Y1T8qRyUYx040N7EE+a3t4pa0FIWhHsuBUgFrKRWyTomW1XqUwLMYF00Opg6 01/XSfqoZUcUb/Y89K476Slj87I3KrogovyfDJADxu2A/uA/OR8rWbZx9WjjgkgUWQXZ nrhisQlTYYarKU3PXp7l5ABEd1VHn7D5gmDC3RBapRs/VhPF0BX3urs1WglbS5Wkc8i3 K2AWrG+UXHUQo/HMbvjzT+DppmXQJDu0Vl36dTitCD7eVncrGLZszpsKvSsJFEIEY7XF Dlww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=AzSo/AOvcB5qZao3YCr3N0XT0nGgItf0sLdyX2gvYvU=; b=Ul/FQVMEHzyeFuObAMpMDDO+kZmBq8djvvlc0sI7trF0LK6qCMnMU1BZuITlXRw8aN hCiSeRbvREBwr1hOSeSxQvFvZm5kzvfFRCnI2dBmhUMgU4BJvxbdptG+TrifJZsaM2OY dCUhhbqPdjilUI95SYQEH+RGdoBzVnXN+NlrLayUOmhlVeCkuMuKj8L35kSPkc/cgY8r wQhgRTDnxD/DDqoJLfn0G4kf5jc4mlrqp549OW5+i0C0H2dVZEPJ14ZlMZlc6Ngn1Q4A jV883zoacGFuUSUVMtwNhc3dGQhPkZNl7TUcFv94JwwA+YusZY9gQCO6BO8WSjUV+eLJ Pp6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3-v6si21717146plp.594.2018.05.24.19.45.36; Thu, 24 May 2018 19:45:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969762AbeEXWRW (ORCPT + 99 others); Thu, 24 May 2018 18:17:22 -0400 Received: from ipmail07.adl2.internode.on.net ([150.101.137.131]:41767 "EHLO ipmail07.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966031AbeEXWRS (ORCPT ); Thu, 24 May 2018 18:17:18 -0400 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail07.adl2.internode.on.net with ESMTP; 25 May 2018 07:47:16 +0930 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1fLyXr-000272-An; Fri, 25 May 2018 08:17:15 +1000 Date: Fri, 25 May 2018 08:17:15 +1000 From: Dave Chinner To: Michal Hocko Cc: Jonathan Corbet , LKML , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , "Darrick J. Wong" , David Sterba Subject: Re: [PATCH] doc: document scope NOFS, NOIO APIs Message-ID: <20180524221715.GY10363@dastard> References: <20180424183536.GF30619@thunk.org> <20180524114341.1101-1-mhocko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180524114341.1101-1-mhocko@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 24, 2018 at 01:43:41PM +0200, Michal Hocko wrote: > From: Michal Hocko > > Although the api is documented in the source code Ted has pointed out > that there is no mention in the core-api Documentation and there are > people looking there to find answers how to use a specific API. > > Cc: "Darrick J. Wong" > Cc: David Sterba > Requested-by: "Theodore Y. Ts'o" > Signed-off-by: Michal Hocko Yay, Documentation! :) > --- > > Hi Johnatan, > Ted has proposed this at LSFMM and then we discussed that briefly on the > mailing list [1]. I received some useful feedback from Darrick and Dave > which has been (hopefully) integrated. Then the thing fall off my radar > rediscovering it now when doing some cleanup. Could you take the patch > please? > > [1] http://lkml.kernel.org/r/20180424183536.GF30619@thunk.org > .../core-api/gfp_mask-from-fs-io.rst | 55 +++++++++++++++++++ > 1 file changed, 55 insertions(+) > create mode 100644 Documentation/core-api/gfp_mask-from-fs-io.rst > > diff --git a/Documentation/core-api/gfp_mask-from-fs-io.rst b/Documentation/core-api/gfp_mask-from-fs-io.rst > new file mode 100644 > index 000000000000..e8b2678e959b > --- /dev/null > +++ b/Documentation/core-api/gfp_mask-from-fs-io.rst > @@ -0,0 +1,55 @@ > +================================= > +GFP masks used from FS/IO context > +================================= > + > +:Date: Mapy, 2018 > +:Author: Michal Hocko > + > +Introduction > +============ > + > +Code paths in the filesystem and IO stacks must be careful when > +allocating memory to prevent recursion deadlocks caused by direct > +memory reclaim calling back into the FS or IO paths and blocking on > +already held resources (e.g. locks - most commonly those used for the > +transaction context). > + > +The traditional way to avoid this deadlock problem is to clear __GFP_FS > +resp. __GFP_IO (note the later implies clearing the first as well) in > +the gfp mask when calling an allocator. GFP_NOFS resp. GFP_NOIO can be > +used as shortcut. It turned out though that above approach has led to > +abuses when the restricted gfp mask is used "just in case" without a > +deeper consideration which leads to problems because an excessive use > +of GFP_NOFS/GFP_NOIO can lead to memory over-reclaim or other memory > +reclaim issues. > + > +New API > +======== > + > +Since 4.12 we do have a generic scope API for both NOFS and NOIO context > +``memalloc_nofs_save``, ``memalloc_nofs_restore`` resp. ``memalloc_noio_save``, > +``memalloc_noio_restore`` which allow to mark a scope to be a critical > +section from the memory reclaim recursion into FS/IO POV. Any allocation > +from that scope will inherently drop __GFP_FS resp. __GFP_IO from the given > +mask so no memory allocation can recurse back in the FS/IO. > + > +FS/IO code then simply calls the appropriate save function right at the > +layer where a lock taken from the reclaim context (e.g. shrinker) and > +the corresponding restore function when the lock is released. All that > +ideally along with an explanation what is the reclaim context for easier > +maintenance. This paragraph doesn't make much sense to me. I think you're trying to say that we should call the appropriate save function "before locks are taken that a reclaim context (e.g a shrinker) might require access to." I think it's also worth making a note about recursive/nested save/restore stacking, because it's not clear from this description that this is allowed and will work as long as inner save/restore calls are fully nested inside outer save/restore contexts. Cheers, Dave. -- Dave Chinner david@fromorbit.com