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); /** From patchwork Mon Aug 12 09:05:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13760335 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 2B939C52D7C for ; Mon, 12 Aug 2024 09:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2C336B00A0; Mon, 12 Aug 2024 05:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADBD56B00A1; Mon, 12 Aug 2024 05:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92FC26B00A2; Mon, 12 Aug 2024 05:08:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 737DF6B00A0 for ; Mon, 12 Aug 2024 05:08:17 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1893F121BAE for ; Mon, 12 Aug 2024 09:08:17 +0000 (UTC) X-FDA: 82443017034.19.723BAF6 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf22.hostedemail.com (Postfix) with ESMTP id 18513C0032 for ; Mon, 12 Aug 2024 09:08:14 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G3r8F5El; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=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=NACQ7ELOlfYjhnP0zeg6TZ0yzINb3WcQXKg7nf5cJS8=; b=wnpVoEPAuV6IGPpp5K9C3Zcx5E1Eq+ZWZzu15sTZe/wb/wTr8Y7BrWOg4H22QOjWLBmkwg 7t7X5RFSZiclPkVDxkoZl/AvtxEIb+Sb5HAgrRk7VUVMmyfvHWcRdICuBKggO5j35fvAHy uH3hfISy2LvhKCEv+QXdyDrJ020JSMg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=G3r8F5El; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723453640; a=rsa-sha256; cv=none; b=jQjyLWBoU71LilodzEu8Tj91xdd23VyfQCIdrOmxTjXm91q1/DR6lKahikMcZ+MBVYjYFb XL16xILDkzqJuBCY5d/oHddFxzkN9Wz8Kj3KSxQMDJJiKCf7P3ju6G/FIM1ZFQfy0EDOae GpXuVU/T8dj7INeWyRVkTVW5pDY/e6Q= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7a1be7b5d70so2914241a12.0 for ; Mon, 12 Aug 2024 02:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723453694; x=1724058494; 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=NACQ7ELOlfYjhnP0zeg6TZ0yzINb3WcQXKg7nf5cJS8=; b=G3r8F5ElhUrE96aHppaiZx+0bCmShidRPZndccWnJbCkfczuDLrWVjTIDoxLbQvxGK HEKe8KleqSOEPQm7MBwanXy+nRP+0SmnI4QTjQbihRy5aPnQA1Llofkh1yZInajZQwJL GP/Avm0aRWnORORQXch05V5CEpKXYhLiTDTqu0PufuYAfhBI+AUjtc0J3gmEXAjWNbPi sF3RM1G90M/cWcUBXM+LkHnvaCH+QwYYtnrYq+YB5cUtRXsghsuoI5Glvn5ZLBS31CRw AjjNIYvGesALvCKq2jAyg/6xd326ogoVJRLmvMv0qb1zCevciP+aeM4WPkcTkaGcKq+H Dutg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723453694; x=1724058494; 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=NACQ7ELOlfYjhnP0zeg6TZ0yzINb3WcQXKg7nf5cJS8=; b=LJhoqAM9hJYhrnZMAszlnF9MTE/NrI/p0LtAKr7eA7ldh7fpncOMYd/EhfXtpItI0z KaV2ZAhb5pWN+V+oW7SXYejcZOyYCEIwrLU9wH0Uty3eywAbBj7I96qtlRNQdLvmKHMP 2Cl0pHyaaMwTwbxcWDyF9W0GT4HY50jYV6FXePBYR69ERyX1j59yytLyaQ9tZc8YjinR sh4JfDtJsLwoynMLF00CtXBtNFo6ON84qkbzHi7fur1YDKJ5AzzyH9YfRadpaQB3VlY8 1CNZt75kRd6jSU9VCCEki2ZB+69Ubx19E46vslfa1VRjyhOKU75D0znu1H+m8m2ozlit oHEQ== X-Forwarded-Encrypted: i=1; AJvYcCVAzbzln0TRGQ9DW9isGik7ueF+bYAcnxARUhd4HDLT5I238Rs1M4kkUCirX+jBTzy+0tuveyCsZfuGepnPh5w+0LM= X-Gm-Message-State: AOJu0YwiHdYSqOJp1rF5278XMZhU6h3ZS75RhraAycenG6lvaKGpTehf aPPCinQWoED6rId1iuzm0LtCt/NYaEbNZdOCMJVSQgYo5FyV+SfJ X-Google-Smtp-Source: AGHT+IGJZX9ZcwD3zVcDl0RfaEongQHdZrDxDKxiWRmiIqWGUKGPjJtJ672FdIkDuHFOVdmglMnrhw== X-Received: by 2002:a17:90a:55c3:b0:2d1:c9f9:e871 with SMTP id 98e67ed59e1d1-2d1e7f07945mr14004654a91.8.1723453693692; Mon, 12 Aug 2024 02:08:13 -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.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Aug 2024 02:08:13 -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 , Jens Axboe , Matthew Wilcox Subject: [PATCH 2/2] mm: allow read-ahead with IOCB_NOWAIT set Date: Mon, 12 Aug 2024 17:05:25 +0800 Message-Id: <20240812090525.80299-3-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-Stat-Signature: dh36j4m4yq7f4uborh3drzk9ey3q7uak X-Rspam-User: X-Rspamd-Queue-Id: 18513C0032 X-Rspamd-Server: rspam02 X-HE-Tag: 1723453694-888413 X-HE-Meta: U2FsdGVkX1/r8+uuy2MPhP28eqSyoK0eSzqm5GQoyHUT8YX+OZSZu6v7h1z1+2sjVtqh/qM6M+dn8T89H6QFeW1JBMnlqOgm73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Lr+m7m79KjL3jXiNggX+udQcv73QFFHNppTi6veW2FsvvY0ToO0+u4zipltN91nLSwN3sOf5fAy5LnLhf85HhlpB93VP32usjH/yzlzJmn6mbgVwzo8AuNAo4PRkWQ4dSI8eP2w/CExU2pI63Oty8SAkM4nCPqlaOOZZfYen7wMj96A1ecCRv3SgHEqBXdtGUN5ZaK56chSkLSN+FMJq70rKPud8aGSDbmFOYJuQmUFxONiR00bqi79XeaD8WEUbMFNyuQ7WusQYtl7F/MZACkDJAiMjxifOK5GV3M4ef9FrTcutfQW4+DleNmzd+3HUb5VpmHZqY7+Z2qOd1t35DiFSPeCAjYXy84jsefdXbQHfPgs2TbYG2sv9BWwSVYAnRWcU27Ag72G3mSQzKhfcAq/FNSULvkUl2nRQzXDX5bXiXC2nxNrtbAzoPbQHN7ettfcMLFSQmhgwQojefUbh75eGxkkiPKV7eME6loEn56DNqP028g9JEBW84pHtoL+5YWZhJwug2DA/P46o24DplioeeiYKwmKA= 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: List-Subscribe: List-Unsubscribe: Readahead support for IOCB_NOWAIT was introduced in commit 2e85abf053b9 ("mm: allow read-ahead with IOCB_NOWAIT set"). However, this behavior was altered in commit efa8480a8316 ("fs: RWF_NOWAIT should imply IOCB_NOIO") to prevent potential blocking during memory reclamation. To address the blocking issue during memory reclamation, we can use memalloc_nowait_{save,restore} to ensure non-blocking behavior. With this change, we can restore the original functionality, allowing preadv2(IOCB_NOWAIT) to read data directly from the disk if it's not already in the page cache. Link: https://lore.gnuweeb.org/io-uring/20200624164127.GP21350@casper.infradead.org/ Signed-off-by: Yafang Shao Cc: Jens Axboe Cc: Matthew Wilcox Cc: Dave Chinner Cc: Jan Kara Cc: Christian Brauner --- include/linux/fs.h | 1 - mm/filemap.c | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..ced74b1b350d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3455,7 +3455,6 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags, if (flags & RWF_NOWAIT) { if (!(ki->ki_filp->f_mode & FMODE_NOWAIT)) return -EOPNOTSUPP; - kiocb_flags |= IOCB_NOIO; } if (flags & RWF_ATOMIC) { if (rw_type != WRITE) diff --git a/mm/filemap.c b/mm/filemap.c index 657bcd887fdb..93c690e1d1fd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -2514,6 +2515,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; pgoff_t last_index; struct folio *folio; + unsigned int flags; int err = 0; /* "last_index" is the index of the page beyond the end of the read */ @@ -2526,8 +2528,12 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & IOCB_NOIO) return -EAGAIN; + if (iocb->ki_flags & IOCB_NOWAIT) + flags = memalloc_nowait_save(); page_cache_sync_readahead(mapping, ra, filp, index, last_index - index); + if (iocb->ki_flags & IOCB_NOWAIT) + memalloc_nowait_restore(flags); filemap_get_read_batch(mapping, index, last_index - 1, fbatch); } if (!folio_batch_count(fbatch)) {