Message ID | 20201009195033.3208459-34-ira.weiny@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | PMEM: Introduce stray write protection for PMEM | expand |
On Fri, 9 Oct 2020, ira.weiny@intel.com wrote: > From: Ira Weiny <ira.weiny@intel.com> > > The kmap() calls in this FS are localized to a single thread. To avoid > the over head of global PKRS updates use the new kmap_thread() call. > > Cc: Nicolas Pitre <nico@fluxnic.net> > Signed-off-by: Ira Weiny <ira.weiny@intel.com> Acked-by: Nicolas Pitre <nico@fluxnic.net> > fs/cramfs/inode.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > index 912308600d39..003c014a42ed 100644 > --- a/fs/cramfs/inode.c > +++ b/fs/cramfs/inode.c > @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, > struct page *page = pages[i]; > > if (page) { > - memcpy(data, kmap(page), PAGE_SIZE); > - kunmap(page); > + memcpy(data, kmap_thread(page), PAGE_SIZE); > + kunmap_thread(page); > put_page(page); > } else > memset(data, 0, PAGE_SIZE); > @@ -826,7 +826,7 @@ static int cramfs_readpage(struct file *file, struct page *page) > > maxblock = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT; > bytes_filled = 0; > - pgdata = kmap(page); > + pgdata = kmap_thread(page); > > if (page->index < maxblock) { > struct super_block *sb = inode->i_sb; > @@ -914,13 +914,13 @@ static int cramfs_readpage(struct file *file, struct page *page) > > memset(pgdata + bytes_filled, 0, PAGE_SIZE - bytes_filled); > flush_dcache_page(page); > - kunmap(page); > + kunmap_thread(page); > SetPageUptodate(page); > unlock_page(page); > return 0; > > err: > - kunmap(page); > + kunmap_thread(page); > ClearPageUptodate(page); > SetPageError(page); > unlock_page(page); > -- > 2.28.0.rc0.12.gb6a658bd00c9 > >
On Fri, Oct 9, 2020 at 12:52 PM <ira.weiny@intel.com> wrote: > > From: Ira Weiny <ira.weiny@intel.com> > > The kmap() calls in this FS are localized to a single thread. To avoid > the over head of global PKRS updates use the new kmap_thread() call. > > Cc: Nicolas Pitre <nico@fluxnic.net> > Signed-off-by: Ira Weiny <ira.weiny@intel.com> > --- > fs/cramfs/inode.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > index 912308600d39..003c014a42ed 100644 > --- a/fs/cramfs/inode.c > +++ b/fs/cramfs/inode.c > @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, > struct page *page = pages[i]; > > if (page) { > - memcpy(data, kmap(page), PAGE_SIZE); > - kunmap(page); > + memcpy(data, kmap_thread(page), PAGE_SIZE); > + kunmap_thread(page); Why does this need a sleepable kmap? This looks like a textbook kmap_atomic() use case.
On Tue, Oct 13, 2020 at 11:44:29AM -0700, Dan Williams wrote: > On Fri, Oct 9, 2020 at 12:52 PM <ira.weiny@intel.com> wrote: > > > > From: Ira Weiny <ira.weiny@intel.com> > > > > The kmap() calls in this FS are localized to a single thread. To avoid > > the over head of global PKRS updates use the new kmap_thread() call. > > > > Cc: Nicolas Pitre <nico@fluxnic.net> > > Signed-off-by: Ira Weiny <ira.weiny@intel.com> > > --- > > fs/cramfs/inode.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > > index 912308600d39..003c014a42ed 100644 > > --- a/fs/cramfs/inode.c > > +++ b/fs/cramfs/inode.c > > @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, > > struct page *page = pages[i]; > > > > if (page) { > > - memcpy(data, kmap(page), PAGE_SIZE); > > - kunmap(page); > > + memcpy(data, kmap_thread(page), PAGE_SIZE); > > + kunmap_thread(page); > > Why does this need a sleepable kmap? This looks like a textbook > kmap_atomic() use case. There's a lot of code of this form. Could we perhaps have: static inline void copy_to_highpage(struct page *to, void *vfrom, unsigned int size) { char *vto = kmap_atomic(to); memcpy(vto, vfrom, size); kunmap_atomic(vto); } in linux/highmem.h ?
On Tue, Oct 13, 2020 at 12:37 PM Matthew Wilcox <willy@infradead.org> wrote: > > On Tue, Oct 13, 2020 at 11:44:29AM -0700, Dan Williams wrote: > > On Fri, Oct 9, 2020 at 12:52 PM <ira.weiny@intel.com> wrote: > > > > > > From: Ira Weiny <ira.weiny@intel.com> > > > > > > The kmap() calls in this FS are localized to a single thread. To avoid > > > the over head of global PKRS updates use the new kmap_thread() call. > > > > > > Cc: Nicolas Pitre <nico@fluxnic.net> > > > Signed-off-by: Ira Weiny <ira.weiny@intel.com> > > > --- > > > fs/cramfs/inode.c | 10 +++++----- > > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > > > index 912308600d39..003c014a42ed 100644 > > > --- a/fs/cramfs/inode.c > > > +++ b/fs/cramfs/inode.c > > > @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, > > > struct page *page = pages[i]; > > > > > > if (page) { > > > - memcpy(data, kmap(page), PAGE_SIZE); > > > - kunmap(page); > > > + memcpy(data, kmap_thread(page), PAGE_SIZE); > > > + kunmap_thread(page); > > > > Why does this need a sleepable kmap? This looks like a textbook > > kmap_atomic() use case. > > There's a lot of code of this form. Could we perhaps have: > > static inline void copy_to_highpage(struct page *to, void *vfrom, unsigned int size) > { > char *vto = kmap_atomic(to); > > memcpy(vto, vfrom, size); > kunmap_atomic(vto); > } > > in linux/highmem.h ? Nice, yes, that could also replace the local ones in lib/iov_iter.c (memcpy_{to,from}_page())
On Tue, Oct 13, 2020 at 08:36:43PM +0100, Matthew Wilcox wrote: > static inline void copy_to_highpage(struct page *to, void *vfrom, unsigned int size) > { > char *vto = kmap_atomic(to); > > memcpy(vto, vfrom, size); > kunmap_atomic(vto); > } > > in linux/highmem.h ? You mean, like static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len) { char *from = kmap_atomic(page); memcpy(to, from + offset, len); kunmap_atomic(from); } static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len) { char *to = kmap_atomic(page); memcpy(to + offset, from, len); kunmap_atomic(to); } static void memzero_page(struct page *page, size_t offset, size_t len) { char *addr = kmap_atomic(page); memset(addr + offset, 0, len); kunmap_atomic(addr); } in lib/iov_iter.c? FWIW, I don't like that "highpage" in the name and highmem.h as location - these make perfect sense regardless of highmem; they are normal memory operations with page + offset used instead of a pointer...
On Tue, Oct 13, 2020 at 08:36:43PM +0100, Matthew Wilcox wrote: > On Tue, Oct 13, 2020 at 11:44:29AM -0700, Dan Williams wrote: > > On Fri, Oct 9, 2020 at 12:52 PM <ira.weiny@intel.com> wrote: > > > > > > From: Ira Weiny <ira.weiny@intel.com> > > > > > > The kmap() calls in this FS are localized to a single thread. To avoid > > > the over head of global PKRS updates use the new kmap_thread() call. > > > > > > Cc: Nicolas Pitre <nico@fluxnic.net> > > > Signed-off-by: Ira Weiny <ira.weiny@intel.com> > > > --- > > > fs/cramfs/inode.c | 10 +++++----- > > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > > > index 912308600d39..003c014a42ed 100644 > > > --- a/fs/cramfs/inode.c > > > +++ b/fs/cramfs/inode.c > > > @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, > > > struct page *page = pages[i]; > > > > > > if (page) { > > > - memcpy(data, kmap(page), PAGE_SIZE); > > > - kunmap(page); > > > + memcpy(data, kmap_thread(page), PAGE_SIZE); > > > + kunmap_thread(page); > > > > Why does this need a sleepable kmap? This looks like a textbook > > kmap_atomic() use case. > > There's a lot of code of this form. Could we perhaps have: > > static inline void copy_to_highpage(struct page *to, void *vfrom, unsigned int size) > { > char *vto = kmap_atomic(to); > > memcpy(vto, vfrom, size); > kunmap_atomic(vto); > } > > in linux/highmem.h ? Christoph had the same idea. I'll work on it. Ira
On Tue, Oct 13, 2020 at 09:01:49PM +0100, Al Viro wrote: > On Tue, Oct 13, 2020 at 08:36:43PM +0100, Matthew Wilcox wrote: > > > static inline void copy_to_highpage(struct page *to, void *vfrom, unsigned int size) > > { > > char *vto = kmap_atomic(to); > > > > memcpy(vto, vfrom, size); > > kunmap_atomic(vto); > > } > > > > in linux/highmem.h ? > > You mean, like > static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len) > { > char *from = kmap_atomic(page); > memcpy(to, from + offset, len); > kunmap_atomic(from); > } > > static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len) > { > char *to = kmap_atomic(page); > memcpy(to + offset, from, len); > kunmap_atomic(to); > } > > static void memzero_page(struct page *page, size_t offset, size_t len) > { > char *addr = kmap_atomic(page); > memset(addr + offset, 0, len); > kunmap_atomic(addr); > } > > in lib/iov_iter.c? FWIW, I don't like that "highpage" in the name and > highmem.h as location - these make perfect sense regardless of highmem; > they are normal memory operations with page + offset used instead of > a pointer... I was thinking along those lines as well especially because of the direction this patch set takes kmap(). Thanks for pointing these out to me. How about I lift them to a common header? But if not highmem.h where? Ira
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 912308600d39..003c014a42ed 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -247,8 +247,8 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, struct page *page = pages[i]; if (page) { - memcpy(data, kmap(page), PAGE_SIZE); - kunmap(page); + memcpy(data, kmap_thread(page), PAGE_SIZE); + kunmap_thread(page); put_page(page); } else memset(data, 0, PAGE_SIZE); @@ -826,7 +826,7 @@ static int cramfs_readpage(struct file *file, struct page *page) maxblock = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT; bytes_filled = 0; - pgdata = kmap(page); + pgdata = kmap_thread(page); if (page->index < maxblock) { struct super_block *sb = inode->i_sb; @@ -914,13 +914,13 @@ static int cramfs_readpage(struct file *file, struct page *page) memset(pgdata + bytes_filled, 0, PAGE_SIZE - bytes_filled); flush_dcache_page(page); - kunmap(page); + kunmap_thread(page); SetPageUptodate(page); unlock_page(page); return 0; err: - kunmap(page); + kunmap_thread(page); ClearPageUptodate(page); SetPageError(page); unlock_page(page);