From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
David Sterba <dsterba@suse.com>,
linux-fsdevel@vger.kernel.org,
Pankaj Raghav <p.raghav@samsung.com>,
Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
ntfs3@lists.linux.dev, "Theodore Tso" <tytso@mit.edu>,
Jan Kara <jack@suse.com>,
linux-ext4@vger.kernel.org
Subject: [PATCH 1/7] highmem: Add memcpy_to_folio() and memcpy_from_folio()
Date: Thu, 13 Jul 2023 04:55:06 +0100 [thread overview]
Message-ID: <20230713035512.4139457-2-willy@infradead.org> (raw)
In-Reply-To: <20230713035512.4139457-1-willy@infradead.org>
These are the folio equivalent of memcpy_to_page() and memcpy_from_page().
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/highmem.h | 44 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 68da30625a6c..0280f57d4744 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -439,6 +439,50 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len)
kunmap_local(addr);
}
+static inline void memcpy_from_folio(char *to, struct folio *folio,
+ size_t offset, size_t len)
+{
+ VM_BUG_ON(offset + len > folio_size(folio));
+
+ do {
+ char *from = kmap_local_folio(folio, offset);
+ size_t chunk = len;
+
+ if (folio_test_highmem(folio) &&
+ (chunk > (PAGE_SIZE - offset_in_page(offset))))
+ chunk = PAGE_SIZE - offset_in_page(offset);
+ memcpy(to, from, len);
+ kunmap_local(from);
+
+ from += chunk;
+ offset += chunk;
+ len -= chunk;
+ } while (len > 0);
+}
+
+static inline void memcpy_to_folio(struct folio *folio, size_t offset,
+ const char *from, size_t len)
+{
+ VM_BUG_ON(offset + len > folio_size(folio));
+
+ do {
+ char *to = kmap_local_folio(folio, offset);
+ size_t chunk = len;
+
+ if (folio_test_highmem(folio) &&
+ (chunk > (PAGE_SIZE - offset_in_page(offset))))
+ chunk = PAGE_SIZE - offset_in_page(offset);
+ memcpy(to, from, len);
+ kunmap_local(to);
+
+ from += chunk;
+ offset += chunk;
+ len -= chunk;
+ } while (len > 0);
+
+ flush_dcache_folio(folio);
+}
+
/**
* memcpy_from_file_folio - Copy some bytes from a file folio.
* @to: The destination buffer.
--
2.39.2
next prev parent reply other threads:[~2023-07-13 3:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-13 3:55 [PATCH 0/7] More filesystem folio conversions for 6.6 Matthew Wilcox (Oracle)
2023-07-13 3:55 ` Matthew Wilcox (Oracle) [this message]
2023-07-22 0:06 ` [PATCH 1/7] highmem: Add memcpy_to_folio() and memcpy_from_folio() Andreas Grünbacher
2023-07-13 3:55 ` [PATCH 2/7] affs: Convert affs_symlink_read_folio() to use the folio Matthew Wilcox (Oracle)
2023-07-21 16:50 ` David Sterba
2023-07-13 3:55 ` [PATCH 3/7] affs: Convert data read and write to use folios Matthew Wilcox (Oracle)
2023-07-13 10:36 ` Pankaj Raghav
2023-07-21 16:51 ` David Sterba
2023-07-13 3:55 ` [PATCH 4/7] migrate: Use folio_set_bh() instead of set_bh_page() Matthew Wilcox (Oracle)
2023-07-31 14:44 ` Jan Kara
2023-07-13 3:55 ` [PATCH 5/7] ntfs3: Convert ntfs_get_block_vbo() to use a folio Matthew Wilcox (Oracle)
2023-07-13 3:55 ` [PATCH 6/7] jbd2: Use a folio in jbd2_journal_write_metadata_buffer() Matthew Wilcox (Oracle)
2023-07-31 14:43 ` Jan Kara
2023-07-13 3:55 ` [PATCH 7/7] buffer: Remove set_bh_page() Matthew Wilcox (Oracle)
2023-07-31 14:46 ` Jan Kara
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=20230713035512.4139457-2-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=dsterba@suse.com \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
--cc=p.raghav@samsung.com \
--cc=tytso@mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).