Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2939986imm; Thu, 24 May 2018 19:30:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqH7cY3g2VKeBvJH85LxlviOVAfIbNPYOsGabgoGn5o86uA6WI9S3vOOudNlZBBprz42lN5 X-Received: by 2002:a63:9741:: with SMTP id d1-v6mr422088pgo.447.1527215430647; Thu, 24 May 2018 19:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527215430; cv=none; d=google.com; s=arc-20160816; b=zeBA9rWp7KeHKmnBl+eMA7YBntKVoeuTazba0As9+m28wfuCZ57snKwDaeWHZT9O2l gCdIu+Zc8LKygnyz8y1nmJ9O/QihQe8xu/UGPi9rq1FeqWQHyAFWSOIHkgKGmLM2+nrp N+tIozS09SP4dbGm0hZfNBgJGS8LCDBTnvDshVvCQwPqCBCSwY2St3D6s/hwVUjjYsxC lI+GVq4ePRRsoL2dSB8w+8GeucXHotlp9r+g5T5Ogm4G1iOnmQoWW6nMxa4GE9t25h5j vtWkTwIFsLLxF0MokiINhzfbrfAUQ5XgGngAgHdWNhLJ4RP+RM7Mvs0ERpyle6GFMkSN t4Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=7UWXz5xYim6Lu3I6BOsGfyzPfE5cUSOCH4xmaNGsd2g=; b=w1cTp8/4GDJB9DRxBs2E7d5nFK3zVJnFd/OIV4LGlQ5huT4nuyUuvQ1FW/c8mHEPzW 4uGk/Ma5cLFxFXrqvfmH766eTJuAG59e+9mG78blikcoXt2LAMrBM7ZPrGQMZmiIU5NB sHBsqYxf+SxTn16ofZZU7JVzhhVJ+d/OLI6kfSYbj8hR8TCVdAMUeDDnrFtvTy5YsBbP zepEFw/SclT4MQ0wgfTLEbBqYbdpqGUhTT0IoeIjDNMa8V3PWOGzxGOfYb4NtgbKcHIw Xcjx7l1SstPtJ0+bsuHGeOXm0OQW0h0AX6UapiZWs4YxUuslIISNWcn1vYEGgmK2O2kp 4iWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=jmX3UDa7; 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 u10-v6si3484754plr.553.2018.05.24.19.30.16; Thu, 24 May 2018 19:30:30 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=jmX3UDa7; 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 S1161112AbeEXQh3 (ORCPT + 99 others); Thu, 24 May 2018 12:37:29 -0400 Received: from merlin.infradead.org ([205.233.59.134]:51006 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031249AbeEXQh1 (ORCPT ); Thu, 24 May 2018 12:37:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7UWXz5xYim6Lu3I6BOsGfyzPfE5cUSOCH4xmaNGsd2g=; b=jmX3UDa7mBNXGIzL1m3I0f2RKk siAi6IZUCqXXgmQiLYpBkCcQy6WZDr0jmTPjEHYOakq2khHGhTr9RXOtt9qgC0x2sLbKquqYFXQes JNbBV//FrRmHlJH6pk57lS2GTs07RAjfHF0rrgpU3HIC31SawmggP+j8jRtfclpstLEpB1JYJYY6w Z7Z8lHTBOSN4O+2rSYqA10yn5sN600vEIdLB+3Qxyoc3uCnIq2qlJaN/8Cp4pFOoD+R/+u2oLdbFC Asklig+JpYmgE+MfGshvREWe5UrBvhAHiZ7p3jBPXzla2+f25aj59rV/7gpEyYPQYKSAZBTG43YzV IVKsfDbg==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLtEu-0002Au-N6; Thu, 24 May 2018 16:37:20 +0000 Subject: Re: [PATCH] doc: document scope NOFS, NOIO APIs To: Michal Hocko , Jonathan Corbet Cc: LKML , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , "Darrick J. Wong" , David Sterba References: <20180424183536.GF30619@thunk.org> <20180524114341.1101-1-mhocko@kernel.org> From: Randy Dunlap Message-ID: <6c9df175-df6c-2531-b90c-318e4fff72bb@infradead.org> Date: Thu, 24 May 2018 09:37:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180524114341.1101-1-mhocko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/24/2018 04: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 latter > +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 s/POV/point of view/ or whatever it is. > +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. I would prefer s/api/API/ throughout. > + > +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. > -- ~Randy