From patchwork Fri Sep 17 02:56:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 12500875 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 07E5BC433F5 for ; Fri, 17 Sep 2021 02:59:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 90D0F61019 for ; Fri, 17 Sep 2021 02:59:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 90D0F61019 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3669D6B0073; Thu, 16 Sep 2021 22:59:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 316DE6B0074; Thu, 16 Sep 2021 22:59:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DED0900002; Thu, 16 Sep 2021 22:59:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 0F4956B0073 for ; Thu, 16 Sep 2021 22:59:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C3578184B609B for ; Fri, 17 Sep 2021 02:59:38 +0000 (UTC) X-FDA: 78595560036.15.4B86504 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf09.hostedemail.com (Postfix) with ESMTP id 6E07E3000109 for ; Fri, 17 Sep 2021 02:59:38 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6D480223BD; Fri, 17 Sep 2021 02:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1631847577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SCmYAExKah/x4HefNwJ6SI3ygmGtoGw6YCC4JX6hn1A=; b=ZD08jNr3STpxIH2zhAj9vQ08PCu/q3GNJLyXZgVVTvIjd9eXcLIYJhnhXbjSrigDBUIuC2 WQBHbIGiQMBjRXzZr9ZH/nF1atOn2t78ukiAIiA1h/5IZocoG6GGgoBBxuLpGXgSci4yfF OkJ4ZwgFwbPkHnuIb/g+WH804uf8Z8c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1631847577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SCmYAExKah/x4HefNwJ6SI3ygmGtoGw6YCC4JX6hn1A=; b=kBS9mRBLg9S4WsHwdwYdezpuGLpU07TMQfxxihZAV7Xevvz28AvWtdhEVRCrBuOlLwSmy+ 6vS8wGL3Y8Oq9MDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 029DC13D0B; Fri, 17 Sep 2021 02:59:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WSX/LJQERGF0MwAAMHmgww (envelope-from ); Fri, 17 Sep 2021 02:59:32 +0000 Subject: [PATCH 2/6] MM: improve documentation for __GFP_NOFAIL From: NeilBrown To: Andrew Morton , Theodore Ts'o , Andreas Dilger , "Darrick J. Wong" , Matthew Wilcox , Mel Gorman , Michal Hocko , ". Dave Chinner" , Jonathan Corbet Cc: linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Date: Fri, 17 Sep 2021 12:56:57 +1000 Message-ID: <163184741778.29351.16920832234899124642.stgit@noble.brown> In-Reply-To: <163184698512.29351.4735492251524335974.stgit@noble.brown> References: <163184698512.29351.4735492251524335974.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6E07E3000109 X-Stat-Signature: whjwgxcigty8x7siidjmuphs3ujzrmuh Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZD08jNr3; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=kBS9mRBL; spf=pass (imf09.hostedemail.com: domain of neilb@suse.de designates 195.135.220.28 as permitted sender) smtp.mailfrom=neilb@suse.de; dmarc=pass (policy=none) header.from=suse.de X-HE-Tag: 1631847578-298526 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: __GFP_NOFAIL is documented both in gfp.h and memory-allocation.rst. The details are not entirely consistent. This patch ensures both places state that: - there is a risk of deadlock with reclaim/writeback/oom-kill - it should only be used when there is no real alternative - it is preferable to an endless loop - it is strongly discourages for costly-order allocations. Signed-off-by: NeilBrown Acked-by: Vlastimil Babka --- Documentation/core-api/memory-allocation.rst | 25 ++++++++++++++++++++++++- include/linux/gfp.h | 6 +++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst index 5954ddf6ee13..8ea077465446 100644 --- a/Documentation/core-api/memory-allocation.rst +++ b/Documentation/core-api/memory-allocation.rst @@ -126,7 +126,30 @@ or another request. * ``GFP_KERNEL | __GFP_NOFAIL`` - overrides the default allocator behavior and all allocation requests will loop endlessly until they succeed. - This might be really dangerous especially for larger orders. + Any attempt to use ``__GFP_NOFAIL`` for allocations larger than + order-1 (2 pages) will trigger a warning. + + Use of ``__GFP_NOFAIL`` can cause deadlocks so it should only be used + when there is no alternative, and then should be used with caution. + Deadlocks can happen if the calling process holds any resources + (e.g. locks) which might be needed for memory reclaim or write-back, + or which might prevent a process killed by the OOM killer from + successfully exiting. Where possible, locks should be released + before using ``__GFP_NOFAIL``. + + While this flag is best avoided, it is still preferable to endless + loops around the allocator. Endless loops may still be used when + there is a need to test for the process being killed + (fatal_signal_pending(current)). + + * ``GFP_NOFS | __GFP_NOFAIL`` - Loop endlessly instead of failing + when performing allocations in file system code. The same guidance + as for ``GFP_KERNEL | __GFP_NOFAIL`` applies with extra emphasis on + the possibility of deadlocks. ``GFP_NOFS`` often implies that + filesystem locks are held which might lead to blocking reclaim. + Preemptively flushing or reclaiming memory associated with such + locks might be appropriate before requesting a ``__GFP_NOFAIL`` + allocation. Selecting memory allocator ========================== diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 55b2ec1f965a..1d2a89e20b8b 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -209,7 +209,11 @@ struct vm_area_struct; * used only when there is no reasonable failure policy) but it is * definitely preferable to use the flag rather than opencode endless * loop around allocator. - * Using this flag for costly allocations is _highly_ discouraged. + * Use of this flag may lead to deadlocks if locks are held which would + * be needed for memory reclaim, write-back, or the timely exit of a + * process killed by the OOM-killer. Dropping any locks not absolutely + * needed is advisable before requesting a %__GFP_NOFAIL allocate. + * Using this flag for costly allocations (order>1) is _highly_ discouraged. */ #define __GFP_IO ((__force gfp_t)___GFP_IO) #define __GFP_FS ((__force gfp_t)___GFP_FS)