Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2926353imm; Thu, 24 May 2018 19:11:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoaYLb+mAwjH6cLOzCHEl6cJrx0WeL/TxBrrUppdsjdAl9g62NvGEKW/ijwifApnJymE8aq X-Received: by 2002:a17:902:24b:: with SMTP id 69-v6mr570428plc.54.1527214298581; Thu, 24 May 2018 19:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527214298; cv=none; d=google.com; s=arc-20160816; b=uB2xxxzmMt9YhysQ9L5BTpFFYVDIaY9Dy5xS5FClA17rdHo+H8QHWIkjMrfjJu6VIB a7xAFlZrBR780IVM9SFIT5XjEse0tTVaLGtXXiXRUdIutDnmCIayksTWSKCVkJh9rkI9 fVymB1fSTYlKIm/KzM4IbXYuBGS5m0UfdAJzbRjpsZgMjKGe9S0VVB17RQ3XZSE97Cx+ nI7JET4pfCunwVPHC3AQkpV0D9qflMFDN+iIDBn+znX+u6Wspdzh4I4itv+BHzJluC5c QHrxW4vwtLHsRE7dYbVzoTQorYjKVflcPeccd7URLcZVqJQRcgIgUxYBnoSNAvLUozg/ /DUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ZNbBlC+CSft2HJagKF5RFRvZxM49aYrMcFg7YfLea50=; b=TmMyt+yHhEr7SThZQXGfi8lOf6JwBeg/1tc+qFteVRRmWtTKbubB/vTJmTidvmCKFr Fo5F73MQcqgdM2lLSTI3f8Gz+yKn8rxrkAkhSDvRr43PkfJEx85l4R2Tg9FkWYsKtXkW r9Wbi5PRuUA0mSKW09sBHsRvOZa4rdSXd4BBsVnF7iWyjRxqSW47+uHEQosX4CGKGd4p ovDwp1kdIRmAYAI69b2H9M8XnwOmkn/dfgRnN2c2sian1WjkUqY78YH8NtbYEsKZ5MA8 yb5yhrkQp0/KzxTG4xDmYRvo0KZSkrJmuORZSfcMICZpBf/m7Mbbsox1zXJqnldezAw9 702A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DTttQfGx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b93-v6si22705471plb.536.2018.05.24.19.11.24; Thu, 24 May 2018 19:11:38 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=DTttQfGx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968210AbeEXOdp (ORCPT + 99 others); Thu, 24 May 2018 10:33:45 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38681 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965599AbeEXOdm (ORCPT ); Thu, 24 May 2018 10:33:42 -0400 Received: by mail-wm0-f65.google.com with SMTP id m129-v6so5926560wmb.3 for ; Thu, 24 May 2018 07:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ZNbBlC+CSft2HJagKF5RFRvZxM49aYrMcFg7YfLea50=; b=DTttQfGxSLINVxQCxsyJhwQDTLQZsyBsWO2E3+ziRI6hRP/LlhNVjclG4mI1g3KKCW uHZdZXVJ2UaL1O2paxzxCoF9H0azGCW4pATsHvTgXgzsP/vFDDRWw/78hWZ6LnGh7+Nv dwUcq3Ft1vxgT6c00yZTMwEJfkdolJMWNU0Fgdo7Yuhff2ZHzEEV/t5QILXF3QgTzPfa 5ahe9z9GGg+keP07tRgDwjc2nIG9NdIRvvVY4Xy2/+uQLDn2jAo2FO+DOA3E3GSZzh3m SJgPIZW04oF+/Bcqrz7X2kU3T3RTMzhvwWBrtynJoBVK6hWWySP60Txz6Sn4irCj3jhY 2kjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ZNbBlC+CSft2HJagKF5RFRvZxM49aYrMcFg7YfLea50=; b=j5JzwcCOHdZA4+OYf8OjjZkerb7hNEP2AqvRXzilS2G0z1P4XXlHfT2vtARB8X5Pk2 y4mPA1fRdDXAl6AgIWhh9EEJnZT9ymN42HczG6p0qym2kv/urfSptQaBfxgmgUg4q09d 0Nk4y3MoZBszpXr7/307zc98sBV0WL7T4GVHpZRrseg1yQpUj1osaBiKvZOoBps8F99w GZKN1DdhAvnF2m+3SiyrMO8XmdynVCkXQZ5Xzpw6mtkWnpNcG06TN25oAOa2BCz6/duF c/zvcmVOG1Q1OMesJ76ohpqbbxsuN0V2bFHUtrc4nZgh3nxQbWFgyLYe2jRKkHNHxWdD Hh5g== X-Gm-Message-State: ALKqPwcyoNCWXiEMZYH4md9n0oZq5RLjbeccghTqMmjiBLCUBYr/Kdgo QlUKXNelAk2jfgTRpJ0sKnIazN6Ot/eTTUPIVoV0Ng== X-Received: by 2002:a1c:4584:: with SMTP id l4-v6mr7395016wmi.142.1527172420432; Thu, 24 May 2018 07:33:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:1286:0:0:0:0:0 with HTTP; Thu, 24 May 2018 07:33:39 -0700 (PDT) In-Reply-To: <20180524114341.1101-1-mhocko@kernel.org> References: <20180424183536.GF30619@thunk.org> <20180524114341.1101-1-mhocko@kernel.org> From: Shakeel Butt Date: Thu, 24 May 2018 07:33:39 -0700 Message-ID: Subject: Re: [PATCH] doc: document scope NOFS, NOIO APIs To: Michal Hocko Cc: Jonathan Corbet , LKML , linux-fsdevel , Linux MM , Michal Hocko , "Darrick J. Wong" , David Sterba Content-Type: text/plain; charset="UTF-8" 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 4:43 AM, 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 > --- > > 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 Is resp. == respectively? Why not use the full word (here and below)? > +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. > + > +What about __vmalloc(GFP_NOFS) > +============================== > + > +vmalloc doesn't support GFP_NOFS semantic because there are hardcoded > +GFP_KERNEL allocations deep inside the allocator which are quite non-trivial > +to fix up. That means that calling ``vmalloc`` with GFP_NOFS/GFP_NOIO is > +almost always a bug. The good news is that the NOFS/NOIO semantic can be > +achieved by the scope api. > + > +In the ideal world, upper layers should already mark dangerous contexts > +and so no special care is required and vmalloc should be called without > +any problems. Sometimes if the context is not really clear or there are > +layering violations then the recommended way around that is to wrap ``vmalloc`` > +by the scope API with a comment explaining the problem. > -- > 2.17.0 >