From patchwork Mon Aug 12 09:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13760334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34545C3DA7F for ; Mon, 12 Aug 2024 09:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2BB56B009E; Mon, 12 Aug 2024 05:08:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC7C6B009F; Mon, 12 Aug 2024 05:08:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CB286B00A0; Mon, 12 Aug 2024 05:08:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 791166B009E for ; Mon, 12 Aug 2024 05:08:13 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 308341A1C4D for ; Mon, 12 Aug 2024 09:08:13 +0000 (UTC) X-FDA: 82443016866.10.ECC767C Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf01.hostedemail.com (Postfix) with ESMTP id 4408240012 for ; Mon, 12 Aug 2024 09:08:11 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LEOq4+WE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723453640; a=rsa-sha256; cv=none; b=Gi/Py1pRLYPnvVgS6umkoxu0vEGWS3zs9Up88ApcKo+9gy3tIXJ+Tht25QlYU4FumFQx5d L2bzM9INdb0slquwRX1Sl/WeaNrc1lgg6rfBlfgcJNWf0ri0c6ve7+VXDS+9vZHbEhRn8M 4ErdmNCH4Cc12/z9NtjoDpRjhoLZaE8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LEOq4+WE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723453640; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uW/wggQt4+fC5FS7O2qa+UrIg3yhUVffXpSgh2WeTHM=; b=n/ghCOZUZjP5f3ESyMm4/DiPFPPmF9LNEKbPxJOCUOneGVrzT27IxOs1Oo4CA+9X2kHzVE yTpEwCeqzFqoO++PiZbYt9aTnpexf15ORXIF/d/agI2XpQhiKdU4FguF8W7BxONli999/L e8H/gT3di7BWhvzx8jNKWRqvghYq8/I= Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7a1be7b5d70so2914193a12.0 for ; Mon, 12 Aug 2024 02:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723453690; x=1724058490; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uW/wggQt4+fC5FS7O2qa+UrIg3yhUVffXpSgh2WeTHM=; b=LEOq4+WEcq9/Qecv1WAL3PyHkfYBY0mkNhMHS8gBfIBMom6Gk+Qr+EL4b8O202dbnh eye/dclH8nlCO+MXUjqnDXXNUaF+9Owk8pZl6aaqYgi4dKFenlvArF7d3kihOhAIAfMT /1McPKbSVg8fXCeeZPirfnWtdM9iw6wn7dGI+4/J+YFdLV5wr4E7+EvxwpVnCWismN0c 1/bVJGal+JW0428+rLYw6vTvOD2AxWm1IniW5S2CWwVIP+ak7hy3KtYcToquWZLEq3GN Kkm0RDsMrO6Mkvr2MH50GlcvvfQtY5gE8we4Y2/c7CYeRUeJ7e5XDPCsYuadA7oT3IDT 1FoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723453690; x=1724058490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uW/wggQt4+fC5FS7O2qa+UrIg3yhUVffXpSgh2WeTHM=; b=w1bLDpoFFcVrRfzE70BgFXn35IU+/+Trj8xT0QwXTtxjWkbDS+hpo+PiyxhItsqmS7 81HTGVwqa4TCqZih/s0rSvmJBxkg1Qr1fXTrsEIT1Cwx1Tvb8PdMpq8TT45E4mjAffyG bLpEghe4iV/f05oIX7RR2FWrS6bCotR/PCb5aIjowmaX0Dex7WX9BfbXVXmYV1jAz8l/ VEnWMWkbXim4vWavycdwORPEKCVzVQ4izF0qGZXrOvBC9TDW03xcBdhbaqVJwkJsHU55 N98gZhhCPQRo1PoP//6EV4int5mVvLii/Y2gSmt0RruA3PXOj9gGrdzAnEriauskLxtl bMLA== X-Forwarded-Encrypted: i=1; AJvYcCVBPnMEpynYCTxyVBUmE9vE1pnv3OZkXRGzDBCWTvs8HzvRs20+bw2OSaSXbGR9NAzi9L5ohH408ReCLF2F4S6qQrI= X-Gm-Message-State: AOJu0YwSZKpbyGi/gulYOHFHtpn5StIL2cglMefgsEvXhjKznqt5fePC kxA0xu22SJ/l8B1oMo5WSEagDOsNEJevp0wYOZFJDE/G2oXjXy/p X-Google-Smtp-Source: AGHT+IE1i6xyCeItPKPHLZKTP2IE8z8mnnUgaQUwOgbT0kf6fXpWdfbwyKP6TfANTizn3kIlf0hKgA== X-Received: by 2002:a17:90b:3557:b0:2cb:58e1:abc8 with SMTP id 98e67ed59e1d1-2d1e7fe73acmr12996541a91.21.1723453689637; Mon, 12 Aug 2024 02:08:09 -0700 (PDT) Received: from localhost.localdomain ([39.144.39.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1fce6cfc1sm4450262a91.6.2024.08.12.02.08.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Aug 2024 02:08:09 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, david@fromorbit.com Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Yafang Shao , Kent Overstreet Subject: [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Date: Mon, 12 Aug 2024 17:05:24 +0800 Message-Id: <20240812090525.80299-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240812090525.80299-1-laoar.shao@gmail.com> References: <20240812090525.80299-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4408240012 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qohtxr1fxs4nksnhqwy168w8muksq4zo X-HE-Tag: 1723453691-857358 X-HE-Meta: U2FsdGVkX19e+JAbXlwuCS5uTx3QQaK3BQWkd8UxBZKWyVaKvF8Qr7jJY6QSAJ9DeIn/9kuh//ANgIw5wh2rv5Oci7bAeMJT1iA83q/E9NrKxz7p+pY3vm7MRXUnmZ20sR00kmXlrXe+fkgdnZKSMVLvSu1zSkVwXohLGRtJNsy9+FvzvZaynoiEhReBUBf7YzHJ5YpQw2CS5JlRfMB8OEOVzbk1fJhHWmFfIozPfZM6FV2rRyV/uTHwzD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wmGLUcHWebQ75MnUGFVmRZv7F0+7+Ta3LIy35kNIKfAtoHtrmYT5HsE9mhJs5ClmET3fJQHHdx6ks1eUjA0nU+//zARnWjytHeVvy1c1n4dqqPb2M3oueUdMIZh/GKDUr/uRH91bVmcW6/9zG79aldrC+gU9mkB+u+ZDZSt+hwFQGd+kIu33TZA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000243, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The PF_MEMALLOC_NORECLAIM flag was introduced in commit eab0af905bfc ("mm: introduce PF_MEMALLOC_NORECLAIM, PF_MEMALLOC_NOWARN"). To complement this, let's add two helper functions, memalloc_nowait_{save,restore}, which will be useful in scenarios where we want to avoid waiting for memory reclamation. Signed-off-by: Yafang Shao Cc: Kent Overstreet --- include/linux/sched/mm.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 91546493c43d..4fbae0013166 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -484,6 +484,36 @@ static inline void memalloc_pin_restore(unsigned int flags) memalloc_flags_restore(flags); } +/** + * memalloc_nowait_save - Marks implicit ~__GFP_DIRECT_RECLAIM allocation scope. + * + * This functions marks the beginning of the ~__GFP_DIRECT_RECLAIM allocation + * scope. All further allocations will implicitly drop __GFP_DIRECT_RECLAIM flag + * and so they are won't wait for direct memory reclaiming. Use + * memalloc_nowait_restore to end the scope with flags returned by this + * function. + * + * Context: This function is safe to be used from any context. + * Return: The saved flags to be passed to memalloc_nowait_restore. + */ +static inline unsigned int memalloc_nowait_save(void) +{ + return memalloc_flags_save(PF_MEMALLOC_NORECLAIM); +} + +/** + * memalloc_nofs_restore - Ends the implicit ~__GFP_DIRECT_RECLAIM scope. + * @flags: Flags to restore. + * + * Ends the implicit ~__GFP_DIRECT_RECLAIM scope started by memalloc_nowait_save + * function. Always make sure that the given flags is the return value from the + * pairing memalloc_nowait_save call. + */ +static inline void memalloc_nowait_restore(unsigned int flags) +{ + memalloc_flags_restore(flags); +} + #ifdef CONFIG_MEMCG DECLARE_PER_CPU(struct mem_cgroup *, int_active_memcg); /**