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=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,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, USER_AGENT_SANE_1 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 6CF92C2BA1E for ; Mon, 6 Apr 2020 19:02:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B32820748 for ; Mon, 6 Apr 2020 19:02:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="QwlBA16h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B32820748 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B26AA8E0005; Mon, 6 Apr 2020 15:02:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD6758E0001; Mon, 6 Apr 2020 15:02:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C4A18E0005; Mon, 6 Apr 2020 15:02:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id 83EBC8E0001 for ; Mon, 6 Apr 2020 15:02:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 49058180AD801 for ; Mon, 6 Apr 2020 19:02:08 +0000 (UTC) X-FDA: 76678350336.13.crow83_69e1d081e1c1a X-HE-Tag: crow83_69e1d081e1c1a X-Filterd-Recvd-Size: 6075 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Apr 2020 19:02:07 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 06 Apr 2020 12:01:53 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 06 Apr 2020 12:02:06 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 06 Apr 2020 12:02:06 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 6 Apr 2020 19:02:05 +0000 Received: from [10.2.56.115] (10.124.1.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 6 Apr 2020 19:02:05 +0000 Subject: Re: [PATCH 1/2] mm: clarify __GFP_MEMALLOC usage To: Michal Hocko , NeilBrown CC: David Rientjes , Andrew Morton , Joel Fernandes , "Paul E. McKenney" , , LKML References: <20200403083543.11552-1-mhocko@kernel.org> <20200403083543.11552-2-mhocko@kernel.org> <87blo8xnz2.fsf@notabene.neil.brown.name> <20200406070137.GC19426@dhcp22.suse.cz> From: John Hubbard X-Nvconfidentiality: public Message-ID: <4f861f07-4b47-8ddc-f783-10201ea302d3@nvidia.com> Date: Mon, 6 Apr 2020 12:02:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200406070137.GC19426@dhcp22.suse.cz> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To DRHQMAIL107.nvidia.com (10.27.9.16) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1586199713; bh=qqIagahZ8DDUVZjQFUcg1ElI28hwEI0fMAZ7/LsRukU=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=QwlBA16h2D+ju7OlUihZ+T1QjkFLn7SmhlvkVp0UAszXqAXFqG6hOvTaMGyC8kEMv 2Bwp8DReIQmyzNvzYLEMkZk6Of3WrGsdc6ekAFuiHv6Y+OE5NEIyfASD0M+XKnE7K1 RRW59KqyDHfbZgc4xDXn7CQEMIa8qHcZU9VjN1dEBfI8H3IoAEwIe1gmO1cjg8tFYV 7APrla5bTSEE76b0grIPPluxmWdv7avTTP+wXZaWnSDwQshqAKJfjoc3TW7pwyXZn1 V7hrmPYdjTn+taq5vCRuDHRPjAn8uy/6zyWCqYE3XW1zD2tsaGoVeqUJtNfrBsi6c6 fgLnMMOdhREeQ== 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 4/6/20 12:01 AM, Michal Hocko wrote: ... > From 6c90b0a19a07c87d24ad576e69b33c6e19c2f9a2 Mon Sep 17 00:00:00 2001 > From: Michal Hocko > Date: Wed, 1 Apr 2020 14:00:56 +0200 > Subject: [PATCH] mm: clarify __GFP_MEMALLOC usage > > It seems that the existing documentation is not explicit about the > expected usage and potential risks enough. While it is calls out > that users have to free memory when using this flag it is not really > apparent that users have to careful to not deplete memory reserves > and that they should implement some sort of throttling wrt. freeing > process. > > This is partly based on Neil's explanation [1]. > > Let's also call out that a pre allocated pool allocator should be > considered. > > [1] http://lkml.kernel.org/r/877dz0yxoa.fsf@notabene.neil.brown.name > Signed-off-by: Michal Hocko > --- > include/linux/gfp.h | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/include/linux/gfp.h b/include/linux/gfp.h > index e5b817cb86e7..9cacef1a3ee0 100644 > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -110,6 +110,11 @@ struct vm_area_struct; > * the caller guarantees the allocation will allow more memory to be freed > * very shortly e.g. process exiting or swapping. Users either should > * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). > + * Users of this flag have to be extremely careful to not deplete the reserve > + * completely and implement a throttling mechanism which controls the consumption > + * of the reserve based on the amount of freed memory. > + * Usage of a pre-allocated pool (e.g. mempool) should be always considered before > + * using this flag. > * > * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. > * This takes precedence over the %__GFP_MEMALLOC flag if both are set. > Hi Michal and all, How about using approximately this wording instead? I found Neil's wording to be especially helpful so I mixed it in. (Also fixed a couple of slight 80-col overruns.) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index be2754841369..c247a911d8c7 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -111,6 +111,15 @@ struct vm_area_struct; * very shortly e.g. process exiting or swapping. Users either should * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). * + * To be extra clear: users of __GFP_MEMALLOC must be working to free other + * memory, and that other memory needs to be freed "soon"; specifically, before + * the reserve is exhausted. This generally implies a throttling mechanism that + * balances the amount of __GFP_MEMALLOC memory used against the amount that the + * caller is about to free. + * + * Usage of a pre-allocated pool (e.g. mempool) should be always considered + * before using this flag. + * * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. * This takes precedence over the %__GFP_MEMALLOC flag if both are set. */ thanks, -- John Hubbard NVIDIA