LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] mm: tweaks for improving use of vmap_area
@ 2018-04-26 23:42 Igor Stoppa
  2018-04-26 23:42 ` [PATCH 1/2] struct page: add field for vm_struct Igor Stoppa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Igor Stoppa @ 2018-04-26 23:42 UTC (permalink / raw)
  To: willy, mhocko, akpm, linux-mm; +Cc: linux-kernel, igor.stoppa

These two patches were written in preparation for the creation of
protectable memory, however their use is not limited to pmalloc and can
improve the use of virtally contigous memory.

The first provides a faster path from struct page to the vm_struct that
tracks it.

The second patch renames a single linked list field inside of vmap_area.
The list is currently used only for disposing of the data structure, once
it is not in use anymore.
Which means that it cold be used for other purposes while it'not queued
for destruction.

The patches can also be obtained from here:

https://github.com/Igor-security/linux/tree/preparations-for-mm


Igor Stoppa (2):
  struct page: add field for vm_struct
  vmalloc: rename llist field in vmap_area

 include/linux/mm_types.h | 1 +
 include/linux/vmalloc.h  | 2 +-
 mm/vmalloc.c             | 8 +++++---
 3 files changed, 7 insertions(+), 4 deletions(-)

-- 
2.14.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] struct page: add field for vm_struct
  2018-04-26 23:42 [PATCH 0/2] mm: tweaks for improving use of vmap_area Igor Stoppa
@ 2018-04-26 23:42 ` Igor Stoppa
  2018-04-26 23:42 ` [PATCH 2/2] vmalloc: rename llist field in vmap_area Igor Stoppa
  2018-04-30 23:15 ` [PATCH 0/2] mm: tweaks for improving use of vmap_area Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: Igor Stoppa @ 2018-04-26 23:42 UTC (permalink / raw)
  To: willy, mhocko, akpm, linux-mm; +Cc: linux-kernel, igor.stoppa

When a page is used for virtual memory, it is often necessary to obtain
a handler to the corresponding vm_struct, which refers to the virtually
continuous area generated when invoking vmalloc.

The struct page has a "mapping" field, which can be re-used, to store a
pointer to the parent area.

This will avoid more expensive searches, later on.

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
Reviewed-by: Jay Freyensee <why2jjj.linux@gmail.com>
Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
---
 include/linux/mm_types.h | 1 +
 mm/vmalloc.c             | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 21612347d311..c74e2aa9a48b 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -86,6 +86,7 @@ struct page {
 		void *s_mem;			/* slab first object */
 		atomic_t compound_mapcount;	/* first tail page */
 		/* page_deferred_list().next	 -- second tail page */
+		struct vm_struct *area;
 	};
 
 	/* Second double word */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ebff729cc956..61a1ca22b0f6 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1536,6 +1536,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
 			struct page *page = area->pages[i];
 
 			BUG_ON(!page);
+			page->area = NULL;
 			__free_pages(page, 0);
 		}
 
@@ -1705,6 +1706,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 			area->nr_pages = i;
 			goto fail;
 		}
+		page->area = area;
 		area->pages[i] = page;
 		if (gfpflags_allow_blocking(gfp_mask|highmem_mask))
 			cond_resched();
-- 
2.14.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] vmalloc: rename llist field in vmap_area
  2018-04-26 23:42 [PATCH 0/2] mm: tweaks for improving use of vmap_area Igor Stoppa
  2018-04-26 23:42 ` [PATCH 1/2] struct page: add field for vm_struct Igor Stoppa
@ 2018-04-26 23:42 ` Igor Stoppa
  2018-04-30 23:15 ` [PATCH 0/2] mm: tweaks for improving use of vmap_area Andrew Morton
  2 siblings, 0 replies; 5+ messages in thread
From: Igor Stoppa @ 2018-04-26 23:42 UTC (permalink / raw)
  To: willy, mhocko, akpm, linux-mm; +Cc: linux-kernel, igor.stoppa

The vmap_area structure has a field of type struct llist_node, named
purge_list and is used when performing lazy purge of the area.

Such field is left unused during the actual utilization of the
structure.

This patch renames the field to a more generic "area_list", to allow for
utilization outside of the purging phase.

Since the purging happens after the vmap_area is dismissed, its use is
mutually exclusive with any use performed while the area is allocated.

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
---
 include/linux/vmalloc.h | 2 +-
 mm/vmalloc.c            | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 1e5d8c392f15..2d07dfef3cfd 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -47,7 +47,7 @@ struct vmap_area {
 	unsigned long flags;
 	struct rb_node rb_node;         /* address sorted rbtree */
 	struct list_head list;          /* address sorted list */
-	struct llist_node purge_list;    /* "lazy purge" list */
+	struct llist_node area_list;    /* generic list of areas */
 	struct vm_struct *vm;
 	struct rcu_head rcu_head;
 };
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 61a1ca22b0f6..1bb2233bb262 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -682,7 +682,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end)
 	lockdep_assert_held(&vmap_purge_lock);
 
 	valist = llist_del_all(&vmap_purge_list);
-	llist_for_each_entry(va, valist, purge_list) {
+	llist_for_each_entry(va, valist, area_list) {
 		if (va->va_start < start)
 			start = va->va_start;
 		if (va->va_end > end)
@@ -696,7 +696,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end)
 	flush_tlb_kernel_range(start, end);
 
 	spin_lock(&vmap_area_lock);
-	llist_for_each_entry_safe(va, n_va, valist, purge_list) {
+	llist_for_each_entry_safe(va, n_va, valist, area_list) {
 		int nr = (va->va_end - va->va_start) >> PAGE_SHIFT;
 
 		__free_vmap_area(va);
@@ -743,7 +743,7 @@ static void free_vmap_area_noflush(struct vmap_area *va)
 				    &vmap_lazy_nr);
 
 	/* After this point, we may free va at any time */
-	llist_add(&va->purge_list, &vmap_purge_list);
+	llist_add(&va->area_list, &vmap_purge_list);
 
 	if (unlikely(nr_lazy > lazy_max_pages()))
 		try_purge_vmap_area_lazy();
-- 
2.14.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] mm: tweaks for improving use of vmap_area
  2018-04-26 23:42 [PATCH 0/2] mm: tweaks for improving use of vmap_area Igor Stoppa
  2018-04-26 23:42 ` [PATCH 1/2] struct page: add field for vm_struct Igor Stoppa
  2018-04-26 23:42 ` [PATCH 2/2] vmalloc: rename llist field in vmap_area Igor Stoppa
@ 2018-04-30 23:15 ` Andrew Morton
  2018-05-02  0:05   ` Igor Stoppa
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2018-04-30 23:15 UTC (permalink / raw)
  To: Igor Stoppa; +Cc: willy, mhocko, linux-mm, linux-kernel, igor.stoppa

On Fri, 27 Apr 2018 03:42:41 +0400 Igor Stoppa <igor.stoppa@gmail.com> wrote:

> These two patches were written in preparation for the creation of
> protectable memory, however their use is not limited to pmalloc and can
> improve the use of virtally contigous memory.
> 
> The first provides a faster path from struct page to the vm_struct that
> tracks it.
> 
> The second patch renames a single linked list field inside of vmap_area.
> The list is currently used only for disposing of the data structure, once
> it is not in use anymore.
> Which means that it cold be used for other purposes while it'not queued
> for destruction.

The patches look benign to me (feel free to add my ack), but I'm not
seeing a reason to apply them at this time?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] mm: tweaks for improving use of vmap_area
  2018-04-30 23:15 ` [PATCH 0/2] mm: tweaks for improving use of vmap_area Andrew Morton
@ 2018-05-02  0:05   ` Igor Stoppa
  0 siblings, 0 replies; 5+ messages in thread
From: Igor Stoppa @ 2018-05-02  0:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: willy, mhocko, linux-mm, linux-kernel, igor.stoppa


On 01/05/18 03:15, Andrew Morton wrote:
> On Fri, 27 Apr 2018 03:42:41 +0400 Igor Stoppa <igor.stoppa@gmail.com> wrote:
> 
>> These two patches were written in preparation for the creation of
>> protectable memory, however their use is not limited to pmalloc and can
>> improve the use of virtually contiguous memory.
>>
>> The first provides a faster path from struct page to the vm_struct that
>> tracks it.
>>
>> The second patch renames a single linked list field inside of vmap_area.
>> The list is currently used only for disposing of the data structure, once
>> it is not in use anymore.
>> Which means that it cold be used for other purposes while it's not queued
>> for destruction.
> 
> The patches look benign to me (feel free to add my ack),

thank you

> but I'm not seeing a reason to apply them at this time?

I thought they might come useful to others playing with vmap_areas, I'll 
resubmit them anyway with the protected memory set.

But I was also hoping to get some more review, especially for the 
second, which had not received any definitive ACK/NACK, till now.

So, I'm also ok if they can be merged once the others are ACK'ed.

--
igor

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-02  0:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 23:42 [PATCH 0/2] mm: tweaks for improving use of vmap_area Igor Stoppa
2018-04-26 23:42 ` [PATCH 1/2] struct page: add field for vm_struct Igor Stoppa
2018-04-26 23:42 ` [PATCH 2/2] vmalloc: rename llist field in vmap_area Igor Stoppa
2018-04-30 23:15 ` [PATCH 0/2] mm: tweaks for improving use of vmap_area Andrew Morton
2018-05-02  0:05   ` Igor Stoppa

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).