Skip to contentSkip to conversation

staging: Updates from the Android tree

PATCH In review John Stultz 3 participants 16 messages Jan 30, 2016 – Feb 8, 2016 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: Updates from the Android tree

In reviewing the experimental/android-4.4 tree from AOSP, I realized there were a handful of patches to code in the staging/android directory.

So I wanted to send these along for review, so if there were no objections they could be queued for 4.6.

Let me know if there is any comments or feedback

thanks
-john

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>

Amit Pundir (1):
staging: ion: Fix page pool cache policy

Colin Cross (1):
staging: lowmemorykiller: Make default lowmemorykiller debug message
useful

Daniel Rosenberg (1):
staging: ion: Add X86 dependency for ION_POOL_CACHE_POLICY

Laura Abbott (1):
staging: ashmem: Avoid deadlock with mmap/shrink

Martijn Coenen (1):
staging: lowmemorykiller: Trace kill events.

Rajmal Menariya (1):
staging: ion: Set minimum carveout heap allocation order to PAGE_SHIFT

Rom Lemarchand (1):
staging: ashmem: Add missing include

San Mehat (1):
staging: lowmemorykiller: Fix task_struct leak

Vinil Cheeramvelil (1):
staging: ion: Handle the memory mapping correctly on x86

 drivers/staging/android/ashmem.c                |  4 ++-
 drivers/staging/android/ion/Kconfig             |  8 +++++
 drivers/staging/android/ion/ion_carveout_heap.c |  2 +-
 drivers/staging/android/ion/ion_page_pool.c     |  8 +++++
 drivers/staging/android/ion/ion_priv.h          | 33 ++++++++++++++++++++
 drivers/staging/android/ion/ion_system_heap.c   |  8 +++--
 drivers/staging/android/lowmemorykiller.c       | 33 +++++++++++++++-----
 drivers/staging/android/trace/lowmemorykiller.h | 40 +++++++++++++++++++++++++
 drivers/staging/android/uapi/ashmem.h           |  1 +
 9 files changed, 124 insertions(+), 13 deletions(-)
 create mode 100644 drivers/staging/android/trace/lowmemorykiller.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/9 staging: ashmem: Avoid deadlock with mmap/shrink

From: Laura Abbott <[email protected]>

Both ashmem_mmap and ashmem_shrink take the ashmem_lock. It may be possible for ashmem_mmap to invoke ashmem_shrink:

-000|mutex_lock(lock = 0x0)
-001|ashmem_shrink(?, sc = 0x0) <--- try to take ashmem_mutex again
-002|shrink_slab(shrink = 0xDA5F1CC0, nr_pages_scanned = 0, lru_pages
-002|=
-002|124)
-003|try_to_free_pages(zonelist = 0x0, ?, ?, ?)
-004|__alloc_pages_nodemask(gfp_mask = 21200, order = 1, zonelist =
-004|0xC11D0940,
-005|new_slab(s = 0xE4841E80, ?, node = -1)
-006|__slab_alloc.isra.43.constprop.50(s = 0xE4841E80, gfpflags =
-006|2148925462, ad
-007|kmem_cache_alloc(s = 0xE4841E80, gfpflags = 208)
-008|shmem_alloc_inode(?)
-009|alloc_inode(sb = 0xE480E800)
-010|new_inode_pseudo(?)
-011|new_inode(?)
-012|shmem_get_inode(sb = 0xE480E800, dir = 0x0, ?, dev = 0, flags =
-012|187)
-013|shmem_file_setup(?, ?, flags = 187)
-014|ashmem_mmap(?, vma = 0xC5D64210) <---- Acquire ashmem_mutex
-015|mmap_region(file = 0xDF8E2C00, addr = 1772974080, len = 233472,
-015|flags = 57,
-016|sys_mmap_pgoff(addr = 0, len = 230400, prot = 3, flags = 1, fd =
-016|157, pgoff
-017|ret_fast_syscall(asm)

-->|exception
-018|NUR:0x40097508(asm)
---|end of frame

Avoid this deadlock by using mutex_trylock in ashmem_shrink; if the mutex is already held, do not attempt to shrink.

---
 drivers/staging/android/ashmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/android/ashmem.c +3 -1
index 5bb1283..8ae1308 100644
@@ -441,7 +441,9 @@ ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 	if (!(sc->gfp_mask & __GFP_FS))
 		return SHRINK_STOP;
 
-	mutex_lock(&ashmem_mutex);
+	if (!mutex_trylock(&ashmem_mutex))
+		return -1;
+
 	list_for_each_entry_safe(range, next, &ashmem_lru_list, lru) {
 		loff_t start = range->pgstart * PAGE_SIZE;
 		loff_t end = (range->pgend + 1) * PAGE_SIZE;
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/9 staging: ashmem: Add missing include

In reply to John Stultz

From: Rom Lemarchand <[email protected]>

Include <linux/types.h> into ashmem.h to ensure referenced types are defined

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Minor commit message tweaks]
---
 drivers/staging/android/uapi/ashmem.h | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/android/uapi/ashmem.h +1 -0
index ba4743c..13df42d 100644
@@ -13,6 +13,7 @@
 #define _UAPI_LINUX_ASHMEM_H
 
 #include <linux/ioctl.h>
+#include <linux/types.h>
 
 #define ASHMEM_NAME_LEN		256
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/9 staging: lowmemorykiller: Fix task_struct leak

In reply to John Stultz

From: San Mehat <[email protected]>

As it turns out, the CONFIG_PROFILING interfaces leak a task struct if the notifier chain returns NOTIFY_OK.. doh.

This patch reworks lowmemkiller to use the new generic task free notifier chain.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Commit subject tweak]
---
 drivers/staging/android/lowmemorykiller.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/android/lowmemorykiller.c +0 -1
index 8b5a4a8..806643d 100644
@@ -40,7 +40,6 @@
 #include <linux/sched.h>
 #include <linux/swap.h>
 #include <linux/rcupdate.h>
-#include <linux/profile.h>
 #include <linux/notifier.h>
 
 static u32 lowmem_debug_level = 1;
Signature · 1 line
1.9.1
maintainer
#4 lore raw

Re: [PATCH 3/9] staging: lowmemorykiller: Fix task_struct leak

Quoted 31 lines · John Stultz

From: San Mehat <[email protected]>

As it turns out, the CONFIG_PROFILING interfaces leak a task struct if the notifier chain returns NOTIFY_OK.. doh.

This patch reworks lowmemkiller to use the new generic task free notifier chain.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Commit subject tweak]
---
 drivers/staging/android/lowmemorykiller.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/android/lowmemorykiller.c +0 -1
index 8b5a4a8..806643d 100644
@@ -40,7 +40,6 @@
 #include <linux/sched.h>
 #include <linux/swap.h>
 #include <linux/rcupdate.h>
-#include <linux/profile.h>
 #include <linux/notifier.h>
 
 static u32 lowmem_debug_level = 1;
Signature · 1 line
1.9.1

The changelog comment seems a bit "odd" when looking at the patch here. Is the patch really correct? The changelog?

totally confused,

greg k-h

#5 lore raw

Re: [PATCH 3/9] staging: lowmemorykiller: Fix task_struct leak

Quoted 29 lines · Greg KH
Quoted 28 lines · John Stultz

From: San Mehat <[email protected]>

As it turns out, the CONFIG_PROFILING interfaces leak a task struct if the notifier chain returns NOTIFY_OK.. doh.

This patch reworks lowmemkiller to use the new generic task free notifier chain.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Commit subject tweak]
---
 drivers/staging/android/lowmemorykiller.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/android/lowmemorykiller.c +0 -1
index 8b5a4a8..806643d 100644
@@ -40,7 +40,6 @@
 #include <linux/sched.h>
 #include <linux/swap.h>
 #include <linux/rcupdate.h>
-#include <linux/profile.h>
 #include <linux/notifier.h>
 
Quoted 6 lines
Quoted 3 lines
drivers/staging/android/lowmemorykiller.c +0 -1
 static u32 lowmem_debug_level = 1;
--

1.9.1

The changelog comment seems a bit "odd" when looking at the patch here. Is the patch really correct? The changelog?

Yea. Sorry for my oversight here. Had to do some patch archaeology and found that the content of that patch basically dropped out when 83dbbdbb38 ("android, lowmemorykiller: remove task handoff notifier") landed upstream in 3.4. Since then its been rebased along being basically content-less.

So please ignore it. I'll try to get it dropped from the AOSP tree.

thanks
-john

#6 lore raw

PATCH 4/9 staging: lowmemorykiller: Make default lowmemorykiller debug message useful

In reply to John Stultz

From: Colin Cross <[email protected]>

lowmemorykiller debug messages are inscrutable and mostly useful for debugging the lowmemorykiller, not explaining why a process was killed. Make the messages more useful by prefixing them with "lowmemorykiller: " and explaining in more readable terms what was killed, who it was killed for, and why it was killed.

The messages now look like:

[   76.997631] lowmemorykiller: Killing 'droid.gallery3d' (2172), adj 1000,
[   76.997635]    to free 27436kB on behalf of 'kswapd0' (29) because
[   76.997638]    cache 122624kB is below limit 122880kB for oom_score_adj 1000
[   76.997641]    Free memory is -53356kB above reserved

A negative number for free memory above reserved means some of the reserved memory has been used and is being regenerated by kswapd, which is likely what called the shrinkers.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Minor checkpatch tweaks]
---
 drivers/staging/android/lowmemorykiller.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/staging/android/lowmemorykiller.c +17 -7
index 806643d..98abec7 100644
@@ -83,6 +83,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 	int tasksize;
 	int i;
 	short min_score_adj = OOM_SCORE_ADJ_MAX + 1;
+	int minfree = 0;
 	int selected_tasksize = 0;
 	short selected_oom_score_adj;
 	int array_size = ARRAY_SIZE(lowmem_adj);
@@ -96,8 +97,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 	if (lowmem_minfree_size < array_size)
 		array_size = lowmem_minfree_size;
 	for (i = 0; i < array_size; i++) {
-		if (other_free < lowmem_minfree[i] &&
-		    other_file < lowmem_minfree[i]) {
+		minfree = lowmem_minfree[i];
+		if (other_free < minfree && other_file < minfree) {
 			min_score_adj = lowmem_adj[i];
 			break;
 		}
@@ -152,8 +153,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 		selected = p;
 		selected_tasksize = tasksize;
 		selected_oom_score_adj = oom_score_adj;
-		lowmem_print(2, "select %d (%s), adj %hd, size %d, to kill\n",
-			     p->pid, p->comm, oom_score_adj, tasksize);
+		lowmem_print(2, "select '%s' (%d), adj %hd, size %d, to kill\n",
+			     p->comm, p->pid, oom_score_adj, tasksize);
 	}
 	if (selected) {
 		task_lock(selected);
@@ -166,9 +167,18 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 		if (selected->mm)
 			mark_oom_victim(selected);
 		task_unlock(selected);
-		lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n",
-			     selected->pid, selected->comm,
-			     selected_oom_score_adj, selected_tasksize);
+		lowmem_print(1, "Killing '%s' (%d), adj %hd,\n"
+				 "   to free %ldkB on behalf of '%s' (%d) because\n"
+				 "   cache %ldkB is below limit %ldkB for oom_score_adj %hd\n"
+				 "   Free memory is %ldkB above reserved\n",
+			     selected->comm, selected->pid,
+			     selected_oom_score_adj,
+			     selected_tasksize * (long)(PAGE_SIZE / 1024),
+			     current->comm, current->pid,
+			     other_file * (long)(PAGE_SIZE / 1024),
+			     minfree * (long)(PAGE_SIZE / 1024),
+			     min_score_adj,
+			     other_free * (long)(PAGE_SIZE / 1024));
 		lowmem_deathpending_timeout = jiffies + HZ;
 		rem += selected_tasksize;
 	}
Signature · 1 line
1.9.1
#7 lore raw

PATCH 5/9 staging: lowmemorykiller: Trace kill events.

In reply to John Stultz

From: Martijn Coenen <[email protected]>

Allows for capturing lmk kill events and
their rationale.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
[jstultz: Checkpatch fixups]
---
 drivers/staging/android/lowmemorykiller.c       | 14 +++++++--
 drivers/staging/android/trace/lowmemorykiller.h | 40 +++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)
 create mode 100644 drivers/staging/android/trace/lowmemorykiller.h
drivers/staging/android/lowmemorykiller.c +11 -3
index 98abec7..bda0e8a 100644
@@ -42,6 +42,9 @@
 #include <linux/rcupdate.h>
 #include <linux/notifier.h>
 
+#define CREATE_TRACE_POINTS
+#include "trace/lowmemorykiller.h"
+
 static u32 lowmem_debug_level = 1;
 static short lowmem_adj[6] = {
 	0,
@@ -157,6 +160,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 			     p->comm, p->pid, oom_score_adj, tasksize);
 	}
 	if (selected) {
+		long cache_size, cache_limit, free;
+
 		task_lock(selected);
 		send_sig(SIGKILL, selected, 0);
 		/*
@@ -167,6 +172,10 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 		if (selected->mm)
 			mark_oom_victim(selected);
 		task_unlock(selected);
+		cache_size = other_file * (long)(PAGE_SIZE / 1024);
+		cache_limit = minfree * (long)(PAGE_SIZE / 1024);
+		free = other_free * (long)(PAGE_SIZE / 1024);
+		trace_lowmemory_kill(selected, cache_size, cache_limit, free);
 		lowmem_print(1, "Killing '%s' (%d), adj %hd,\n"
 				 "   to free %ldkB on behalf of '%s' (%d) because\n"
 				 "   cache %ldkB is below limit %ldkB for oom_score_adj %hd\n"
@@ -175,10 +184,9 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 			     selected_oom_score_adj,
 			     selected_tasksize * (long)(PAGE_SIZE / 1024),
 			     current->comm, current->pid,
-			     other_file * (long)(PAGE_SIZE / 1024),
-			     minfree * (long)(PAGE_SIZE / 1024),
+			     cache_size, cache_limit,
 			     min_score_adj,
-			     other_free * (long)(PAGE_SIZE / 1024));
+			     free);
 		lowmem_deathpending_timeout = jiffies + HZ;
 		rem += selected_tasksize;
 	}
drivers/staging/android/trace/lowmemorykiller.h new file +40 -0
new file mode 100644
index 0000000..7d01bd4
@@ -0,0 +1,40 @@
+#undef TRACE_SYSTEM
+#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
+#define TRACE_SYSTEM lowmemorykiller
+
+#if !defined(_TRACE_LOWMEMORYKILLER_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_LOWMEMORYKILLER_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(lowmemory_kill,
+	TP_PROTO(struct task_struct *killed_task, long cache_size,
+		 long cache_limit, long free),
+
+	TP_ARGS(killed_task, cache_size, cache_limit, free),
+
+	TP_STRUCT__entry(
+			__array(char, comm, TASK_COMM_LEN)
+			__field(pid_t, pid)
+			__field(long, pagecache_size)
+			__field(long, pagecache_limit)
+			__field(long, free)
+	),
+
+	TP_fast_assign(
+			memcpy(__entry->comm, killed_task->comm, TASK_COMM_LEN);
+			__entry->pid = killed_task->pid;
+			__entry->pagecache_size = cache_size;
+			__entry->pagecache_limit = cache_limit;
+			__entry->free = free;
+	),
+
+	TP_printk("%s (%d), page cache %ldkB (limit %ldkB), free %ldKb",
+		  __entry->comm, __entry->pid, __entry->pagecache_size,
+		  __entry->pagecache_limit, __entry->free)
+);
+
+#endif /* !defined(_TRACE_LOWMEMORYKILLER_H) || defined(TRACE_HEADER_MULTI_READ) */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
1.9.1
#8 lore raw

PATCH 6/9 staging: ion: Set minimum carveout heap allocation order to PAGE_SHIFT

In reply to John Stultz

From: Rajmal Menariya <[email protected]>

In carveout heap, change minimum allocation order from 12 to PAGE_SHIFT. After this change each bit in bitmap (genalloc - General purpose special memory pool) represents one page size memory.

Cc Colin Cross <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>
[jstultz: Reworked commit message]
---
 drivers/staging/android/ion/ion_carveout_heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/ion/ion_carveout_heap.c +1 -1
index 9156d82..e702ce6 100644
@@ -167,7 +167,7 @@ struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *heap_data)
 	if (!carveout_heap)
 		return ERR_PTR(-ENOMEM);
 
-	carveout_heap->pool = gen_pool_create(12, -1);
+	carveout_heap->pool = gen_pool_create(PAGE_SHIFT, -1);
 	if (!carveout_heap->pool) {
 		kfree(carveout_heap);
 		return ERR_PTR(-ENOMEM);
Signature · 1 line
1.9.1
Acked-by on v1 6/9
#9 lore raw

Re: [PATCH 6/9] staging: ion: Set minimum carveout heap allocation order to PAGE_SHIFT

Quoted 7 lines · John Stultz

From: Rajmal Menariya <[email protected]>

In carveout heap, change minimum allocation order from 12 to PAGE_SHIFT. After this change each bit in bitmap (genalloc - General purpose special memory pool) represents one page size memory.

Quoted 10 lines
Cc Colin Cross <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>
[jstultz: Reworked commit message]
Quoted 18 lines
---
  drivers/staging/android/ion/ion_carveout_heap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/ion/ion_carveout_heap.c +1 -1
index 9156d82..e702ce6 100644
@@ -167,7 +167,7 @@ struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *heap_data)
  	if (!carveout_heap)
  		return ERR_PTR(-ENOMEM);
 
-	carveout_heap->pool = gen_pool_create(12, -1);
+	carveout_heap->pool = gen_pool_create(PAGE_SHIFT, -1);
  	if (!carveout_heap->pool) {
  		kfree(carveout_heap);
  		return ERR_PTR(-ENOMEM);
#10 lore raw

PATCH 7/9 staging: ion: Handle the memory mapping correctly on x86

In reply to John Stultz

From: Vinil Cheeramvelil <[email protected]>

This patch modifies the ion page pool code to address limitation in x86 PAT. When one physical page is mapped to multiple virtual pages, the same cache policy should be used. Add set_memory_wc/uc call to avoid aliases. If not, all mappings will be cached(write back).

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>
---
 drivers/staging/android/ion/Kconfig           |  8 +++++++
 drivers/staging/android/ion/ion_page_pool.c   |  8 +++++++
 drivers/staging/android/ion/ion_priv.h        | 33 +++++++++++++++++++++++++++
 drivers/staging/android/ion/ion_system_heap.c |  6 +++--
 4 files changed, 53 insertions(+), 2 deletions(-)
drivers/staging/android/ion/Kconfig +8 -0
index 19c1572..a15ff29 100644
@@ -40,3 +40,11 @@ config ION_HISI
 	  Choose this option if you wish to use ion on Hisilicon Platform.
 
 source "drivers/staging/android/ion/hisilicon/Kconfig"
+
+config ION_POOL_CACHE_POLICY
+	bool "Ion set page pool cache policy"
+	depends on ION
+	default y if X86
+	help
+	  Choose this option if need to explicity set cache policy of the
+	  pages in the page pool.
drivers/staging/android/ion/ion_page_pool.c +8 -0
index fd7e23e..59ee2f8 100644
@@ -30,6 +30,8 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool)
 
 	if (!page)
 		return NULL;
+	ion_page_pool_alloc_set_cache_policy(pool, page);
+
 	ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order,
 						DMA_BIDIRECTIONAL);
 	return page;
@@ -38,6 +40,7 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool)
 static void ion_page_pool_free_pages(struct ion_page_pool *pool,
 				     struct page *page)
 {
+	ion_page_pool_free_set_cache_policy(pool, page);
 	__free_pages(page, pool->order);
 }
 
@@ -103,6 +106,11 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct page *page)
 		ion_page_pool_free_pages(pool, page);
 }
 
+void ion_page_pool_free_immediate(struct ion_page_pool *pool, struct page *page)
+{
+	ion_page_pool_free_pages(pool, page);
+}
+
 static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
 {
 	int count = pool->low_count;
drivers/staging/android/ion/ion_priv.h +33 -0
index 0239883..9a25ba6 100644
@@ -26,6 +26,9 @@
 #include <linux/sched.h>
 #include <linux/shrinker.h>
 #include <linux/types.h>
+#ifdef CONFIG_ION_POOL_CACHE_POLICY
+#include <asm/cacheflush.h>
+#endif
 
 #include "ion.h"
 
@@ -381,6 +384,36 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order);
 void ion_page_pool_destroy(struct ion_page_pool *);
 struct page *ion_page_pool_alloc(struct ion_page_pool *);
 void ion_page_pool_free(struct ion_page_pool *, struct page *);
+void ion_page_pool_free_immediate(struct ion_page_pool *, struct page *);
+
+#ifdef CONFIG_ION_POOL_CACHE_POLICY
+static inline void ion_page_pool_alloc_set_cache_policy
+				(struct ion_page_pool *pool,
+				struct page *page){
+	void *va = page_address(page);
+
+	if (va)
+		set_memory_wc((unsigned long)va, 1 << pool->order);
+}
+
+static inline void ion_page_pool_free_set_cache_policy
+				(struct ion_page_pool *pool,
+				struct page *page){
+	void *va = page_address(page);
+
+	if (va)
+		set_memory_wb((unsigned long)va, 1 << pool->order);
+}
+#else
+static inline void ion_page_pool_alloc_set_cache_policy
+				(struct ion_page_pool *pool,
+				struct page *page){ }
+
+static inline void ion_page_pool_free_set_cache_policy
+				(struct ion_page_pool *pool,
+				struct page *page){ }
+#endif
+
 
 /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool
  * @pool:		the pool
drivers/staging/android/ion/ion_system_heap.c +4 -2
index d4c3e55..fa62cc4 100644
@@ -85,8 +85,10 @@ static void free_buffer_page(struct ion_system_heap *heap,
 
 	if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) {
 		struct ion_page_pool *pool = heap->pools[order_to_index(order)];
-
-		ion_page_pool_free(pool, page);
+		if (buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)
+			ion_page_pool_free_immediate(pool, page);
+		else
+			ion_page_pool_free(pool, page);
 	} else {
 		__free_pages(page, order);
 	}
Signature · 1 line
1.9.1
#11 lore raw

PATCH 8/9 staging: ion: Add X86 dependency for ION_POOL_CACHE_POLICY

In reply to John Stultz

From: Daniel Rosenberg <[email protected]>

ION_POOL_CACHE_POLICY uses x86 specific commands. Only allow it to be used for x86.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>
---
 drivers/staging/android/ion/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/ion/Kconfig +1 -1
index a15ff29..e2ee3c3 100644
@@ -43,7 +43,7 @@ source "drivers/staging/android/ion/hisilicon/Kconfig"
 
 config ION_POOL_CACHE_POLICY
 	bool "Ion set page pool cache policy"
-	depends on ION
+	depends on ION && X86
 	default y if X86
 	help
 	  Choose this option if need to explicity set cache policy of the
Signature · 1 line
1.9.1
#12 lore raw

PATCH 9/9 staging: ion: Fix page pool cache policy

In reply to John Stultz

From: Amit Pundir <[email protected]>

Fix redundant "buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE" checks in if(!cached ...) condition block.

The previous patch, "ion: Handle the memory mapping correctly on x86", is broken on android-3.18+ kernels. It conflicts with upstream commit commit 53a91c68fa7b ("staging: ion: Add private buffer flag to skip page pooling on free"), and breaks the ION_PRIV_FLAG_SHRINKER_FREE private flag check logic.

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>
---
 drivers/staging/android/ion/ion_system_heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/ion/ion_system_heap.c +1 -1
index fa62cc4..57d115d 100644
@@ -83,7 +83,7 @@ static void free_buffer_page(struct ion_system_heap *heap,
 	unsigned int order = compound_order(page);
 	bool cached = ion_buffer_cached(buffer);
 
-	if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) {
+	if (!cached) {
 		struct ion_page_pool *pool = heap->pools[order_to_index(order)];
 		if (buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)
 			ion_page_pool_free_immediate(pool, page);
Signature · 1 line
1.9.1
#13 lore raw
In reply to John Stultz
Quoted 8 lines · John Stultz

In reviewing the experimental/android-4.4 tree from AOSP, I realized there were a handful of patches to code in the staging/android directory.

So I wanted to send these along for review, so if there were no objections they could be queued for 4.6.

Let me know if there is any comments or feedback

I'm not thrilled about the patches for the cache policy. It certainly fixes the problem for x86 but I'd rather see a more unified caching approach which would also abstract some of the cache flushing.

Thanks,
Laura

Quoted 50 lines

thanks
-john

Cc Android Kernel Team <[email protected]>
Cc Greg KH <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Sumit Semwal <[email protected]>

Amit Pundir (1):
staging: ion: Fix page pool cache policy

Colin Cross (1):
staging: lowmemorykiller: Make default lowmemorykiller debug message
useful

Daniel Rosenberg (1):
staging: ion: Add X86 dependency for ION_POOL_CACHE_POLICY

Laura Abbott (1):
staging: ashmem: Avoid deadlock with mmap/shrink

Martijn Coenen (1):
staging: lowmemorykiller: Trace kill events.

Rajmal Menariya (1):
staging: ion: Set minimum carveout heap allocation order to PAGE_SHIFT

Rom Lemarchand (1):
staging: ashmem: Add missing include

San Mehat (1):
staging: lowmemorykiller: Fix task_struct leak

Vinil Cheeramvelil (1):
staging: ion: Handle the memory mapping correctly on x86

  drivers/staging/android/ashmem.c                |  4 ++-
  drivers/staging/android/ion/Kconfig             |  8 +++++
  drivers/staging/android/ion/ion_carveout_heap.c |  2 +-
  drivers/staging/android/ion/ion_page_pool.c     |  8 +++++
  drivers/staging/android/ion/ion_priv.h          | 33 ++++++++++++++++++++
  drivers/staging/android/ion/ion_system_heap.c   |  8 +++--
  drivers/staging/android/lowmemorykiller.c       | 33 +++++++++++++++-----
  drivers/staging/android/trace/lowmemorykiller.h | 40 +++++++++++++++++++++++++
  drivers/staging/android/uapi/ashmem.h           |  1 +
  9 files changed, 124 insertions(+), 13 deletions(-)

create mode 100644 drivers/staging/android/trace/lowmemorykiller.h

#14 lore raw
Quoted 9 lines · Laura Abbott
Quoted 8 lines · John Stultz

In reviewing the experimental/android-4.4 tree from AOSP, I realized there were a handful of patches to code in the staging/android directory.

So I wanted to send these along for review, so if there were no objections they could be queued for 4.6.

Quoted 6 lines
Quoted 1 line

Let me know if there is any comments or feedback

I'm not thrilled about the patches for the cache policy. It certainly fixes the problem for x86 but I'd rather see a more unified caching approach which would also abstract some of the cache flushing.

Fair enough.

Though I worry that keeping them out of mainline's staging makes it more difficult to get a proper solution upstream, since it creates more out of tree variants, which users may have subtle dependencies on. But that's more of a general worry then a specific concern here.

thanks
-john

maintainer
#15 lore raw
In reply to John Stultz
Quoted 8 lines · John Stultz

In reviewing the experimental/android-4.4 tree from AOSP, I realized there were a handful of patches to code in the staging/android directory.

So I wanted to send these along for review, so if there were no objections they could be queued for 4.6.

Let me know if there is any comments or feedback

I've applied some of these, if I've missed any I should apply, please rebase and resend.

thanks,

greg k-h