lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed,  6 May 2020 17:41:58 -0700
From:   Anthony Yznaga <anthony.yznaga@...cle.com>
To:     linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc:     willy@...radead.org, corbet@....net, tglx@...utronix.de,
        mingo@...hat.com, bp@...en8.de, x86@...nel.org, hpa@...or.com,
        dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
        rppt@...ux.ibm.com, akpm@...ux-foundation.org, hughd@...gle.com,
        ebiederm@...ssion.com, masahiroy@...nel.org, ardb@...nel.org,
        ndesaulniers@...gle.com, dima@...ovin.in, daniel.kiper@...cle.com,
        nivedita@...m.mit.edu, rafael.j.wysocki@...el.com,
        dan.j.williams@...el.com, zhenzhong.duan@...cle.com,
        jroedel@...e.de, bhe@...hat.com, guro@...com,
        Thomas.Lendacky@....com, andriy.shevchenko@...ux.intel.com,
        keescook@...omium.org, hannes@...xchg.org, minchan@...nel.org,
        mhocko@...nel.org, ying.huang@...el.com,
        yang.shi@...ux.alibaba.com, gustavo@...eddedor.com,
        ziqian.lzq@...fin.com, vdavydov.dev@...il.com,
        jason.zeng@...el.com, kevin.tian@...el.com, zhiyuan.lv@...el.com,
        lei.l.li@...el.com, paul.c.lai@...el.com, ashok.raj@...el.com,
        linux-fsdevel@...r.kernel.org, linux-doc@...r.kernel.org,
        kexec@...ts.infradead.org
Subject: [RFC 32/43] shmem: PKRAM: preserve shmem files a chunk at a time

To prepare for multithreading the work done to a preserve a file,
divide the work into subranges of the total index range of the file.
The chunk size is a rather arbitrary 256k indices.

A new API call, pkram_prepare_save_chunk(), is added.  It is called
after calling pkram_prepare_save_obj(), and it initializes pkram_stream
with the index range of the next available range of pages to save.
find_get_pages_range() can then be used to get the pages in the range.
When no more index ranges are available, pkram_prepare_save_chunk()
returns -ENODATA.

Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
 include/linux/pkram.h |  6 +++++
 mm/pkram.c            | 26 +++++++++++++++++++++
 mm/shmem_pkram.c      | 63 +++++++++++++++++++++++++++++++++++----------------
 3 files changed, 75 insertions(+), 20 deletions(-)

diff --git a/include/linux/pkram.h b/include/linux/pkram.h
index cbb79d2803c0..e71ccb91d6a6 100644
--- a/include/linux/pkram.h
+++ b/include/linux/pkram.h
@@ -20,6 +20,11 @@ struct pkram_stream {
 	struct address_space *mapping;
 	struct mm_struct *mm;
 
+	unsigned long start_idx;	/* first index in range to save */
+	unsigned long end_idx;		/* last index in range to save */
+	unsigned long max_idx;		/* maximum index to save */
+	atomic64_t *next_idx;		/* first index of next range to save */
+
 	/* byte data */
 	struct page *data_page;
 	unsigned int data_offset;
@@ -46,6 +51,7 @@ void pkram_free_pgt_walk_pgd(pgd_t *pgd);
 int pkram_prepare_save(struct pkram_stream *ps, const char *name,
 		       gfp_t gfp_mask);
 int pkram_prepare_save_obj(struct pkram_stream *ps);
+int pkram_prepare_save_chunk(struct pkram_stream *ps);
 void pkram_finish_save(struct pkram_stream *ps);
 void pkram_finish_save_obj(struct pkram_stream *ps);
 void pkram_discard_save(struct pkram_stream *ps);
diff --git a/mm/pkram.c b/mm/pkram.c
index b83d31740619..5f4e4d12865f 100644
--- a/mm/pkram.c
+++ b/mm/pkram.c
@@ -638,6 +638,25 @@ int pkram_prepare_save(struct pkram_stream *ps, const char *name, gfp_t gfp_mask
 	return 0;
 }
 
+unsigned long max_pages_per_chunk = 512 * 512;
+
+/*
+ * Initialize the stream @ps for the next index range to save.
+ *
+ * Returns 0 on success, -ENODATA if no index range is available
+ *
+ */
+int pkram_prepare_save_chunk(struct pkram_stream *ps)
+{
+	ps->start_idx = atomic64_fetch_add(max_pages_per_chunk, ps->next_idx);
+	if (ps->start_idx >= ps->max_idx)
+		return -ENODATA;
+
+	ps->end_idx = ps->start_idx + max_pages_per_chunk - 1;
+
+	return 0;
+}
+
 /**
  * Create a preserved memory object and initialize stream @ps for saving data
  * to it.
@@ -667,6 +686,11 @@ int pkram_prepare_save_obj(struct pkram_stream *ps)
 		obj->obj_pfn = node->obj_pfn;
 	node->obj_pfn = page_to_pfn(page);
 
+	ps->next_idx = kmalloc(sizeof(atomic64_t), GFP_KERNEL);
+	if (!ps->next_idx)
+		return -ENOMEM;
+	atomic64_set(ps->next_idx, 0);
+
 	pkram_stream_init_obj(ps, obj);
 	return 0;
 }
@@ -679,6 +703,8 @@ void pkram_finish_save_obj(struct pkram_stream *ps)
 	struct pkram_node *node = ps->node;
 
 	BUG_ON((node->flags & PKRAM_ACCMODE_MASK) != PKRAM_SAVE);
+
+	kfree(ps->next_idx);
 }
 
 /**
diff --git a/mm/shmem_pkram.c b/mm/shmem_pkram.c
index c97d64393822..2f4d0bdf3e05 100644
--- a/mm/shmem_pkram.c
+++ b/mm/shmem_pkram.c
@@ -74,58 +74,81 @@ static int save_page(struct page *page, struct pkram_stream *ps)
 	return err;
 }
 
-static int save_file_content(struct pkram_stream *ps)
+static int save_file_content_range(struct address_space *mapping,
+				   struct pkram_stream *ps)
 {
+	unsigned long index, end;
 	struct pagevec pvec;
-	pgoff_t indices[PAGEVEC_SIZE];
-	pgoff_t index = 0;
 	struct page *page;
-	int i, err = 0;
+	int err = 0;
+	int i;
+
+	index = ps->start_idx;
+	end = ps->end_idx;
 
 	pagevec_init(&pvec);
 	for ( ; ; ) {
-		pvec.nr = find_get_entries(ps->mapping, index, PAGEVEC_SIZE,
-				pvec.pages, indices);
+		pvec.nr = find_get_pages_range(mapping, &index, end,
+				PAGEVEC_SIZE, pvec.pages);
 		if (!pvec.nr)
 			break;
-		for (i = 0; i < pagevec_count(&pvec); i++) {
+		for (i = 0; i < pagevec_count(&pvec); ) {
 			page = pvec.pages[i];
-			index = indices[i];
-
-			if (WARN_ON_ONCE(xa_is_value(page))) {
-				err = -EINVAL;
-				break;
-			}
-
 			lock_page(page);
 
 			if (PageTransTail(page)) {
 				WARN_ONCE(1, "PageTransTail returned true\n");
 				unlock_page(page);
+				i++;
 				continue;
 			}
 
-			BUG_ON(page->mapping != ps->mapping);
+			BUG_ON(page->mapping != mapping);
 			err = save_page(page, ps);
 
-			i += compound_nr(page) - 1;
-			index += compound_nr(page) - 1;
+			if (PageCompound(page)) {
+				index = page->index + compound_nr(page);
+				i += compound_nr(page);
+			} else {
+				i++;
+			}
 
 			unlock_page(page);
 			if (err)
 				break;
 		}
-		pagevec_remove_exceptionals(&pvec);
 		pagevec_release(&pvec);
-		if (err)
+		if (err || (index > end))
 			break;
 		cond_resched();
-		index++;
 	}
 
 	return err;
 }
 
+static int do_save_file_content(struct pkram_stream *ps)
+{
+	int ret;
+
+	do {
+		ret = pkram_prepare_save_chunk(ps);
+		if (!ret)
+			ret = save_file_content_range(ps->mapping, ps);
+	} while (!ret);
+
+	if (ret == -ENODATA)
+		ret = 0;
+
+	return ret;
+}
+
+static int save_file_content(struct pkram_stream *ps)
+{
+	ps->max_idx = DIV_ROUND_UP(i_size_read(ps->mapping->host), PAGE_SIZE);
+
+	return do_save_file_content(ps);
+}
+
 static int save_file(struct dentry *dentry, struct pkram_stream *ps)
 {
 	struct inode *inode = dentry->d_inode;
-- 
2.13.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ