Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp692108ybt; Fri, 26 Jun 2020 09:14:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfc6cnIUYSjDjKoVTCFSVuSo6I36lDoE9ZIcoLhc/cYRO6x9mrWr6U018ZaYU5WJ364K02 X-Received: by 2002:a50:eb02:: with SMTP id y2mr1594043edp.281.1593188051488; Fri, 26 Jun 2020 09:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593188051; cv=none; d=google.com; s=arc-20160816; b=byy//d4D1lhZaKY0UB1OGmyZ1z3tIf17fTyAF6Ua+wLETNRDzi4Q5v2PEN+pu2gmyW lm5fNAhqE+3b20eoEoOFHuROF4Gn8dwjfFkZfzfHHlIvM9GCSYS07iGzoCRJonY51YeU 2whdLi69NzJ8egIvVA9ap/g6ig0NAtryKV36UR/Hlp4tt2MQuG/LxoUuUsxYvJ0Jbc0p kvmS887tb6a807TWyVeLG718FqT2XwmiVmB0T6YH0QnIsEnfmcMEuYYmzRtggCRQEzyO ojRpKXstPRVpZI6XPMeTW4elKctqrpF0U7a2AlY+t1fy3e1GCBNCtMSMJxPXgl3ywHMs uA8g== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5ygjSMBXqzqvuocqwOpXx0qg32Ox95PpCrLO1DFGzhA=; b=HxiA4ufp2Id8z0oZQX91TN9/WyRRSD8z96kmEpMSCPIjVAElz4nJ8h7lP5uATNimph qO09MNvxpzzme7V49gboHQBV3Z97I/HopjNZqzMtRhdtd9+3g1SEFL/2QL9j+ghnxeXv Bgfu4HSns5vDKQrYZO9t/1mMoCDSDqJ+dhD3JUJ6iSjeB2vKVvSIt3+MnnE2bAQKj1GY Sk1dcRRPzjzpoBaQqd+/UVgJRxHM3sGAwwnftKd0qxHJadZo413P3uIiKtm0UWb2Q0gB HCDW0j0jzCn/rQbK8Y8WKUUw552hoz/7Xi4+EjFgtXtBCQOOUZzZ84sCNm5yhWI1R0Hh 1vYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z8tPTVjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si995976ejc.390.2020.06.26.09.13.48; Fri, 26 Jun 2020 09:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z8tPTVjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729196AbgFZO36 (ORCPT + 99 others); Fri, 26 Jun 2020 10:29:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:34518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729051AbgFZO35 (ORCPT ); Fri, 26 Jun 2020 10:29:57 -0400 Received: from hump.s81c.com (unknown [87.71.40.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 479BB207D8; Fri, 26 Jun 2020 14:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593181797; bh=pXfSnelWu0zkpTRqVl3gQ/wQpREKKhl5bONcr16ELVY=; h=From:To:Cc:Subject:Date:From; b=Z8tPTVjEM1hiojjWk613mDvO/nGDqSsOXxT1S0e2K8tyPlyBI3ij/jHwr6yWB7t94 OT5tQFBwIjnE3D4xOnPcQFwDw9HksWCi5gWV4Ppca4XTDmd2RQv01WYJS4FQfD+cA9 BOHPr2SgtFHfs4X7Z9kjiRbxImCXP3KimSSCHPGU= From: Mike Rapoport To: Jonathan Corbet Cc: Michal Hocko , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , Mike Rapoport Subject: [PATCH] docs/core-api: memory-allocation: describe reclaim behaviour Date: Fri, 26 Jun 2020 17:29:50 +0300 Message-Id: <20200626142950.135184-1-rppt@kernel.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Rapoport Changelog of commit dcda9b04713c ("mm, tree wide: replace __GFP_REPEAT by __GFP_RETRY_MAYFAIL with more useful semantic") has very nice description of GFP flags that affect reclaim behaviour of the page allocator. It would be pity to keep this description buried in the log so let's expose it in the Documentation/ as well. Cc: Michal Hocko Signed-off-by: Mike Rapoport --- Hi, I've been looking for something completely unrealated and found this really nice piece of documentation. Thanks Michal! ;-) Documentation/core-api/memory-allocation.rst | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst index 4aa82ddd01b8..4446a1ac36cc 100644 --- a/Documentation/core-api/memory-allocation.rst +++ b/Documentation/core-api/memory-allocation.rst @@ -84,6 +84,50 @@ driver for a device with such restrictions, avoid using these flags. And even with hardware with restrictions it is preferable to use `dma_alloc*` APIs. +GFP flags and reclaim behavior +------------------------------ +Memory allocations may trigger direct or background reclaim and it is +useful to understand how hard the page allocator will try to satisfy that +or another request. + + * ``GFP_KERNEL & ~__GFP_RECLAIM`` - optimistic allocation without _any_ + attempt to free memory at all. The most light weight mode which even + doesn't kick the background reclaim. Should be used carefully because it + might deplete the memory and the next user might hit the more aggressive + reclaim. + + * ``GFP_KERNEL & ~__GFP_DIRECT_RECLAIM`` (or ``GFP_NOWAIT``)- optimistic + allocation without any attempt to free memory from the current + context but can wake kswapd to reclaim memory if the zone is below + the low watermark. Can be used from either atomic contexts or when + the request is a performance optimization and there is another + fallback for a slow path. + + * ``(GFP_KERNEL|__GFP_HIGH) & ~__GFP_DIRECT_RECLAIM`` (aka ``GFP_ATOMIC``) - + non sleeping allocation with an expensive fallback so it can access + some portion of memory reserves. Usually used from interrupt/bottom-half + context with an expensive slow path fallback. + + * ``GFP_KERNEL`` - both background and direct reclaim are allowed and the + **default** page allocator behavior is used. That means that not costly + allocation requests are basically no-fail but there is no guarantee of + that behavior so failures have to be checked properly by callers + (e.g. OOM killer victim is allowed to fail currently). + + * ``GFP_KERNEL | __GFP_NORETRY`` - overrides the default allocator behavior + and all allocation requests fail early rather than cause disruptive + reclaim (one round of reclaim in this implementation). The OOM killer + is not invoked. + + * ``GFP_KERNEL | __GFP_RETRY_MAYFAIL`` - overrides the default allocator + behavior and all allocation requests try really hard. The request + will fail if the reclaim cannot make any progress. The OOM killer + won't be triggered. + + * ``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. + Selecting memory allocator ========================== -- 2.25.4