From: Sooyong Suk <s.suk@samsung.com>
To: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, linux-mm@kvack.org
Cc: jaewon31.kim@gmail.com, spssyr@gmail.com,
Sooyong Suk <s.suk@samsung.com>
Subject: [RFC PATCH] block, fs: use FOLL_LONGTERM as gup_flags for direct IO
Date: Thu, 6 Mar 2025 16:40:56 +0900 [thread overview]
Message-ID: <20250306074056.246582-1-s.suk@samsung.com> (raw)
In-Reply-To: <CGME20250306074101epcas1p4b24ac546f93df2c7fe3176607b20e47f@epcas1p4.samsung.com>
There are GUP references to pages that are serving as direct IO buffers.
Those pages can be allocated from CMA pageblocks despite they can be
pinned until the DIO is completed.
Generally, pinning for each DIO might be considered as a transient
operation as described at the documentation. But if a large amount of
direct IO is requested constantly, this can make pages in CMA pageblocks
pinned and unable to migrate outside of the pageblock, which can result
in CMA allocation failure.
In Android devices, on first boot after OTA, snapuserd requests a huge
amount of direct IO reads which might occasionally disturb CMA
allocations.
To prevent this, use FOLL_LONGTERM as gup_flags for direct IO requests
via blkdev_direct_IO or __iomap_dio_rw by default not to allocate buffer
pages from CMA pageblocks.
Signed-off-by: Sooyong Suk <s.suk@samsung.com>
---
block/bio.c | 2 +-
include/linux/uio.h | 2 ++
lib/iov_iter.c | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/block/bio.c b/block/bio.c
index d5bdc31d88d3..683113b3e35a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1247,7 +1247,7 @@ static unsigned int get_contig_folio_len(unsigned int *num_pages,
*/
static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
{
- iov_iter_extraction_t extraction_flags = 0;
+ iov_iter_extraction_t extraction_flags = ITER_ALLOW_LONGTERM;
unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt;
unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt;
struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt;
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 853f9de5aa05..d1e9174ee29a 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -377,6 +377,8 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction,
/* Flags for iov_iter_get/extract_pages*() */
/* Allow P2PDMA on the extracted pages */
#define ITER_ALLOW_P2PDMA ((__force iov_iter_extraction_t)0x01)
+/* Allow LONGTERM on the extracted pages */
+#define ITER_ALLOW_LONGTERM ((__force iov_iter_extraction_t)0x02)
ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages,
size_t maxsize, unsigned int maxpages,
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 9ec806f989f2..4b5c7c30cd4d 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1832,6 +1832,8 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i,
gup_flags |= FOLL_WRITE;
if (extraction_flags & ITER_ALLOW_P2PDMA)
gup_flags |= FOLL_PCI_P2PDMA;
+ if (extraction_flags & ITER_ALLOW_LONGTERM)
+ gup_flags |= FOLL_LONGTERM;
if (i->nofault)
gup_flags |= FOLL_NOFAULT;
--
2.25.1
next parent reply other threads:[~2025-03-06 7:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250306074101epcas1p4b24ac546f93df2c7fe3176607b20e47f@epcas1p4.samsung.com>
2025-03-06 7:40 ` Sooyong Suk [this message]
2025-03-06 15:26 ` Christoph Hellwig
2025-03-06 23:28 ` Jaewon Kim
2025-03-07 2:07 ` Sooyong Suk
2025-03-07 2:28 ` Suren Baghdasaryan
2025-03-07 6:38 ` Sooyong Suk
2025-03-12 15:17 ` Christoph Hellwig
2025-03-12 15:20 ` Suren Baghdasaryan
2025-03-12 15:25 ` Christoph Hellwig
2025-03-12 15:38 ` Suren Baghdasaryan
2025-03-12 15:52 ` Christoph Hellwig
2025-03-12 16:03 ` Bart Van Assche
2025-03-12 16:06 ` Suren Baghdasaryan
2025-03-12 16:21 ` Christoph Hellwig
2025-03-07 20:23 ` Matthew Wilcox
2025-03-07 21:37 ` Suren Baghdasaryan
2025-03-12 15:21 ` Christoph Hellwig
2025-03-13 22:49 ` David Hildenbrand
2025-03-15 1:04 ` John Hubbard
2025-03-15 23:00 ` David Hildenbrand
2025-03-15 23:09 ` Zi Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250306074056.246582-1-s.suk@samsung.com \
--to=s.suk@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=jaewon31.kim@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=spssyr@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®