Skip to contentSkip to conversation

minor clean-up and optimize highmem related code

PATCH Superseded Joonsoo Kim 3 participants 18 messages Oct 28, 2012 – Oct 31, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover minor clean-up and optimize highmem related code

This patchset clean-up and optimize highmem related code.

[1] is just clean-up and doesn't introduce any functional change. [2-3] are for clean-up and optimization.
These eliminate an useless lock opearation and list management. [4-5] is for optimization related to flush_all_zero_pkmaps().

Joonsoo Kim (5):
mm, highmem: use PKMAP_NR() to calculate an index of pkmap mm, highmem: remove useless pool_lock
mm, highmem: remove page_address_pool list
mm, highmem: makes flush_all_zero_pkmaps() return index of last
flushed entry
mm, highmem: get virtual address of the page using PKMAP_ADDR()

 include/linux/highmem.h |    1 +
 mm/highmem.c            |  102 ++++++++++++++++++++---------------------------
 2 files changed, 45 insertions(+), 58 deletions(-)
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/5 mm, highmem: use PKMAP_NR() to calculate an index of pkmap

To calculate an index of pkmap, using PKMAP_NR() is more understandable and maintainable, So change it.

mm/highmem.c +1 -1
index d517cd1..b3b3d68 100644
@@ -99,7 +99,7 @@ struct page *kmap_to_page(void *vaddr)
 	unsigned long addr = (unsigned long)vaddr;
 
 	if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
-		int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
+		int i = PKMAP_NR(addr);
 		return pte_page(pkmap_page_table[i]);
 	}
 
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] mm, highmem: use PKMAP_NR() to calculate an index of pkmap

Quoted 5 lines · Joonsoo Kim

To calculate an index of pkmap, using PKMAP_NR() is more understandable and maintainable, So change it.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH 2/5 mm, highmem: remove useless pool_lock

In reply to Joonsoo Kim

The pool_lock protects the page_address_pool from concurrent access. But, access to the page_address_pool is already protected by kmap_lock. So remove it.

mm/highmem.c +0 -6
index b3b3d68..017bad1 100644
@@ -328,7 +328,6 @@ struct page_address_map {
  * page_address_map freelist, allocated from page_address_maps.
  */
 static struct list_head page_address_pool;	/* freelist */
-static spinlock_t pool_lock;			/* protects page_address_pool */
 
 /*
  * Hash table bucket
@@ -395,11 +394,9 @@ void set_page_address(struct page *page, void *virtual)
 	if (virtual) {		/* Add */
 		BUG_ON(list_empty(&page_address_pool));
 
-		spin_lock_irqsave(&pool_lock, flags);
 		pam = list_entry(page_address_pool.next,
 				struct page_address_map, list);
 		list_del(&pam->list);
-		spin_unlock_irqrestore(&pool_lock, flags);
 
 		pam->page = page;
 		pam->virtual = virtual;
@@ -413,9 +410,7 @@ void set_page_address(struct page *page, void *virtual)
 			if (pam->page == page) {
 				list_del(&pam->list);
 				spin_unlock_irqrestore(&pas->lock, flags);
-				spin_lock_irqsave(&pool_lock, flags);
 				list_add_tail(&pam->list, &page_address_pool);
-				spin_unlock_irqrestore(&pool_lock, flags);
 				goto done;
 			}
 		}
@@ -438,7 +433,6 @@ void __init page_address_init(void)
 		INIT_LIST_HEAD(&page_address_htable[i].lh);
 		spin_lock_init(&page_address_htable[i].lock);
 	}
-	spin_lock_init(&pool_lock);
 }
 
 #endif	/* defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL) */
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] mm, highmem: remove useless pool_lock

Quoted 5 lines · Joonsoo Kim

The pool_lock protects the page_address_pool from concurrent access. But, access to the page_address_pool is already protected by kmap_lock. So remove it.

Looks good to me.
Just a nitpick.

Please write comment about locking rule like below.

mm/highmem.c struct page_address_map { · line 329

Quoted 8 lines
mm/highmem.c +0 -0
index b3b3d68..017bad1 100644
@@ -328,7 +328,6 @@ struct page_address_map {
  * page_address_map freelist, allocated from page_address_maps.
  */

/* page_address_pool is protected by kmap_lock */

Quoted 3 lines
mm/highmem.c +0 -1
 static struct list_head page_address_pool;	/* freelist */
-static spinlock_t pool_lock;			/* protects page_address_pool */
 
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#5 lore raw

Re: [PATCH 2/5] mm, highmem: remove useless pool_lock

In reply to Joonsoo Kim
Quoted 3 lines · On Mon, 29 Oct 2012 04:12:53 +0900 Joonsoo Kim <[email protected]> wrote:

The pool_lock protects the page_address_pool from concurrent access. But, access to the page_address_pool is already protected by kmap_lock. So remove it.

Well, there's a set_page_address() call in mm/page_alloc.c which doesn't have lock_kmap(). it doesn't *need* lock_kmap() because it's init-time code and we're running single-threaded there. I hope!

But this exception should be double-checked and mentioned in the changelog, please. And it's a reason why we can't add assert_spin_locked(&kmap_lock) to set_page_address(), which is unfortunate.

The irq-disabling in this code is odd. If ARCH_NEEDS_KMAP_HIGH_GET=n, we didn't need irq-safe locking in set_page_address(). I guess we'll need to retain it in page_address() - I expect some callers have IRQs disabled.

ARCH_NEEDS_KMAP_HIGH_GET is a nasty looking thing. It's ARM:

/*
* The reason for kmap_high_get() is to ensure that the currently kmap'd
* page usage count does not decrease to zero while we're using its
* existing virtual mapping in an atomic context. With a VIVT cache this
* is essential to do, but with a VIPT cache this is only an optimization
* so not to pay the price of establishing a second mapping if an existing
* one can be used. However, on platforms without hardware TLB maintenance
* broadcast, we simply cannot use ARCH_NEEDS_KMAP_HIGH_GET at all since
* the locking involved must also disable IRQs which is incompatible with
* the IPI mechanism used by global TLB operations.
*/
#define ARCH_NEEDS_KMAP_HIGH_GET
#if defined(CONFIG_SMP) && defined(CONFIG_CPU_TLB_V6)
#undef ARCH_NEEDS_KMAP_HIGH_GET
#if defined(CONFIG_HIGHMEM) && defined(CONFIG_CPU_CACHE_VIVT) #error "The sum of features in your kernel config cannot be supported together" #endif
#endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [PATCH 2/5] mm, highmem: remove useless pool_lock

Hi Andrew,

Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Mon, 29 Oct 2012 04:12:53 +0900 Joonsoo Kim <[email protected]> wrote:

The pool_lock protects the page_address_pool from concurrent access. But, access to the page_address_pool is already protected by kmap_lock. So remove it.

Quoted 9 lines

Well, there's a set_page_address() call in mm/page_alloc.c which doesn't have lock_kmap(). it doesn't *need* lock_kmap() because it's init-time code and we're running single-threaded there. I hope!

But this exception should be double-checked and mentioned in the changelog, please. And it's a reason why we can't add assert_spin_locked(&kmap_lock) to set_page_address(), which is unfortunate.

The exception is vaild only in m68k and sparc and they will use not set_page_address of highmem.c but page->virtual. So I think we can add such lock check in set_page_address in highmem.c.

But I'm not sure we really need it because set_page_address is used in few places so isn't it enough adding a just wording to avoid unnecessary overhead?

/* NOTE : Caller should hold kmap_lock by lock_kmap() */

Quoted 3 lines

The irq-disabling in this code is odd. If ARCH_NEEDS_KMAP_HIGH_GET=n, we didn't need irq-safe locking in set_page_address(). I guess we'll

What lock you mean in set_page_address?
We have two locks in there, pool_lock and pas->lock. By this patchset, we don't need pool_lock any more. Remained thing is pas->lock.

If we make the lock irq-unsafe, it would be deadlock with page_addresss if it is called in irq context. Currenntly, page_address is used lots of places and not sure it's called only process context. Was there any rule that we have to use page_addresss in only process context?

Quoted 30 lines

need to retain it in page_address() - I expect some callers have IRQs disabled.

ARCH_NEEDS_KMAP_HIGH_GET is a nasty looking thing. It's ARM:

/*
* The reason for kmap_high_get() is to ensure that the currently kmap'd
* page usage count does not decrease to zero while we're using its
* existing virtual mapping in an atomic context. With a VIVT cache this
* is essential to do, but with a VIPT cache this is only an optimization
* so not to pay the price of establishing a second mapping if an existing
* one can be used. However, on platforms without hardware TLB maintenance
* broadcast, we simply cannot use ARCH_NEEDS_KMAP_HIGH_GET at all since
* the locking involved must also disable IRQs which is incompatible with
* the IPI mechanism used by global TLB operations.
*/
#define ARCH_NEEDS_KMAP_HIGH_GET
#if defined(CONFIG_SMP) && defined(CONFIG_CPU_TLB_V6)
#undef ARCH_NEEDS_KMAP_HIGH_GET
#if defined(CONFIG_HIGHMEM) && defined(CONFIG_CPU_CACHE_VIVT) #error "The sum of features in your kernel config cannot be supported together" #endif
#endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Re: [PATCH 2/5] mm, highmem: remove useless pool_lock

In reply to Andrew Morton

Hello, Andrew.

2012/10/31 Andrew Morton <[email protected]>:

Quoted 7 lines
Quoted 3 lines · On Mon, 29 Oct 2012 04:12:53 +0900 Joonsoo Kim <[email protected]> wrote:

The pool_lock protects the page_address_pool from concurrent access. But, access to the page_address_pool is already protected by kmap_lock. So remove it.

Quoted 8 lines

Well, there's a set_page_address() call in mm/page_alloc.c which doesn't have lock_kmap(). it doesn't *need* lock_kmap() because it's init-time code and we're running single-threaded there. I hope!

But this exception should be double-checked and mentioned in the changelog, please. And it's a reason why we can't add assert_spin_locked(&kmap_lock) to set_page_address(), which is unfortunate.

set_page_address() in mm/page_alloc.c is invoked only when WANT_PAGE_VIRTUAL is defined.
And in this case, set_page_address()'s definition is not in highmem.c, but in include/linux/mm.h.
So, we don't need to worry about set_page_address() call in mm/page_alloc.c

Quoted 4 lines

The irq-disabling in this code is odd. If ARCH_NEEDS_KMAP_HIGH_GET=n, we didn't need irq-safe locking in set_page_address(). I guess we'll need to retain it in page_address() - I expect some callers have IRQs disabled.

As Minchan described, if we don't disable irq when we take a lock for pas->lock, it would be deadlock with page_address().

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

PATCH 3/5 mm, highmem: remove page_address_pool list

In reply to Joonsoo Kim

We can find free page_address_map instance without the page_address_pool. So remove it.

mm/highmem.c +2 -17
index 017bad1..731cf9a 100644
@@ -323,11 +323,7 @@ struct page_address_map {
 	void *virtual;
 	struct list_head list;
 };
-
-/*
- * page_address_map freelist, allocated from page_address_maps.
- */
-static struct list_head page_address_pool;	/* freelist */
+static struct page_address_map page_address_maps[LAST_PKMAP];
 
 /*
  * Hash table bucket
@@ -392,12 +388,7 @@ void set_page_address(struct page *page, void *virtual)
 
 	pas = page_slot(page);
 	if (virtual) {		/* Add */
-		BUG_ON(list_empty(&page_address_pool));
-
-		pam = list_entry(page_address_pool.next,
-				struct page_address_map, list);
-		list_del(&pam->list);
-
+		pam = &page_address_maps[PKMAP_NR((unsigned long)virtual)];
 		pam->page = page;
 		pam->virtual = virtual;
 
@@ -410,7 +401,6 @@ void set_page_address(struct page *page, void *virtual)
 			if (pam->page == page) {
 				list_del(&pam->list);
 				spin_unlock_irqrestore(&pas->lock, flags);
-				list_add_tail(&pam->list, &page_address_pool);
 				goto done;
 			}
 		}
@@ -420,15 +410,10 @@ done:
 	return;
 }
 
-static struct page_address_map page_address_maps[LAST_PKMAP];
-
 void __init page_address_init(void)
 {
 	int i;
 
-	INIT_LIST_HEAD(&page_address_pool);
-	for (i = 0; i < ARRAY_SIZE(page_address_maps); i++)
-		list_add(&page_address_maps[i].list, &page_address_pool);
 	for (i = 0; i < ARRAY_SIZE(page_address_htable); i++) {
 		INIT_LIST_HEAD(&page_address_htable[i].lh);
 		spin_lock_init(&page_address_htable[i].lock);
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] mm, highmem: remove page_address_pool list

Quoted 4 lines · Joonsoo Kim

We can find free page_address_map instance without the page_address_pool. So remove it.

See below a nitpick. :)

mm/highmem.c struct page_address_map { · line 326

Quoted 10 lines
mm/highmem.c +0 -1
index 017bad1..731cf9a 100644
@@ -323,11 +323,7 @@ struct page_address_map {
 	void *virtual;
 	struct list_head list;
 };
-

Let's leave a blank line.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

PATCH 4/5 mm, highmem: makes flush_all_zero_pkmaps() return index of last flushed entry

In reply to Joonsoo Kim

In current code, after flush_all_zero_pkmaps() is invoked,
then re-iterate all pkmaps. It can be optimized if flush_all_zero_pkmaps() return index of flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type of flush_all_zero_pkmaps()
and return index of last flushed entry.

include/linux/highmem.h +1 -0
index ef788b5..0683869 100644
@@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
 
 #ifdef CONFIG_HIGHMEM
 #include <asm/highmem.h>
+#define PKMAP_INDEX_INVAL (-1)
 
 /* declarations for linux/mm/highmem.c */
 unsigned int nr_free_highpages(void);
mm/highmem.c +40 -32

106 lines not on this page · raw message

Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw

Re: [PATCH 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of last flushed entry

Quoted 14 lines · Joonsoo Kim

In current code, after flush_all_zero_pkmaps() is invoked,
then re-iterate all pkmaps. It can be optimized if flush_all_zero_pkmaps() return index of flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type of flush_all_zero_pkmaps()
and return index of last flushed entry.

include/linux/highmem.h +0 -0
index ef788b5..0683869 100644

include/linux/highmem.h static inline void invalidate_kernel_vmap_range(void *vaddr, int size) · line 35

Quoted 4 lines
include/linux/highmem.h +1 -0
@@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
 
 #ifdef CONFIG_HIGHMEM
 #include <asm/highmem.h>
+#define PKMAP_INDEX_INVAL (-1)

How about this?

#define PKMAP_INVALID_INDEX (-1)

Quoted 21 lines
include/linux/highmem.h +0 -0
 /* declarations for linux/mm/highmem.c */
 unsigned int nr_free_highpages(void);
mm/highmem.c +2 -2
index 731cf9a..65beb9a 100644
@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)
 	return virt_to_page(addr);
 }
 
-static void flush_all_zero_pkmaps(void)
+static int flush_all_zero_pkmaps(void)
 {
 	int i;
-	int need_flush = 0;
+	int index = PKMAP_INDEX_INVAL;
 
 	flush_cache_kmaps();
 

mm/highmem.c static void flush_all_zero_pkmaps(void) · line 144

Quoted 5 lines
mm/highmem.c +1 -1
@@ -141,10 +141,12 @@ static void flush_all_zero_pkmaps(void)
 			  &pkmap_page_table[i]);
 
 		set_page_address(page, NULL);
-		need_flush = 1;
+		index = i;

How about returning first free index instead of last one? and update last_pkmap_nr to it.

Quoted 99 lines
mm/highmem.c +37 -29
 	}
-	if (need_flush)
+	if (index != PKMAP_INDEX_INVAL)
 		flush_tlb_kernel_range(PKMAP_ADDR(0), PKMAP_ADDR(LAST_PKMAP));
+
+	return index;
 }
 
 /**
@@ -160,6 +162,7 @@ void kmap_flush_unused(void)
 static inline unsigned long map_new_virtual(struct page *page)
 {
 	unsigned long vaddr;
+	int index = PKMAP_INDEX_INVAL;
 	int count;
 
 start:
@@ -168,40 +171,45 @@ start:
 	for (;;) {
 		last_pkmap_nr = (last_pkmap_nr + 1) & LAST_PKMAP_MASK;
 		if (!last_pkmap_nr) {
-			flush_all_zero_pkmaps();
-			count = LAST_PKMAP;
+			index = flush_all_zero_pkmaps();
+			if (index != PKMAP_INDEX_INVAL)
+				break; /* Found a usable entry */
 		}
-		if (!pkmap_count[last_pkmap_nr])
+		if (!pkmap_count[last_pkmap_nr]) {
+			index = last_pkmap_nr;
 			break;	/* Found a usable entry */
-		if (--count)
-			continue;
-
-		/*
-		 * Sleep for somebody else to unmap their entries
-		 */
-		{
-			DECLARE_WAITQUEUE(wait, current);
-
-			__set_current_state(TASK_UNINTERRUPTIBLE);
-			add_wait_queue(&pkmap_map_wait, &wait);
-			unlock_kmap();
-			schedule();
-			remove_wait_queue(&pkmap_map_wait, &wait);
-			lock_kmap();
-
-			/* Somebody else might have mapped it while we slept */
-			if (page_address(page))
-				return (unsigned long)page_address(page);
-
-			/* Re-start */
-			goto start;
 		}
+		if (--count == 0)
+			break;
 	}
-	vaddr = PKMAP_ADDR(last_pkmap_nr);
+
+	/*
+	 * Sleep for somebody else to unmap their entries
+	 */
+	if (index == PKMAP_INDEX_INVAL) {
+		DECLARE_WAITQUEUE(wait, current);
+
+		__set_current_state(TASK_UNINTERRUPTIBLE);
+		add_wait_queue(&pkmap_map_wait, &wait);
+		unlock_kmap();
+		schedule();
+		remove_wait_queue(&pkmap_map_wait, &wait);
+		lock_kmap();
+
+		/* Somebody else might have mapped it while we slept */
+		vaddr = (unsigned long)page_address(page);
+		if (vaddr)
+			return vaddr;
+
+		/* Re-start */
+		goto start;
+	}
+
+	vaddr = PKMAP_ADDR(index);
 	set_pte_at(&init_mm, vaddr,
-		   &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
+		   &(pkmap_page_table[index]), mk_pte(page, kmap_prot));
 
-	pkmap_count[last_pkmap_nr] = 1;
+	pkmap_count[index] = 1;
 	set_page_address(page, (void *)vaddr);
 
 	return vaddr;
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw

Re: [PATCH 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of last flushed entry

2012/10/29 Minchan Kim <[email protected]>:

Quoted 16 lines · Joonsoo Kim
Quoted 15 lines

In current code, after flush_all_zero_pkmaps() is invoked,
then re-iterate all pkmaps. It can be optimized if flush_all_zero_pkmaps() return index of flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type of flush_all_zero_pkmaps()
and return index of last flushed entry.

include/linux/highmem.h +0 -0
index ef788b5..0683869 100644
@@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
 
Quoted 7 lines

include/linux/highmem.h static inline void invalidate_kernel_vmap_range(void *vaddr, int size) · line 35

Quoted 3 lines
include/linux/highmem.h +1 -0
 #ifdef CONFIG_HIGHMEM
 #include <asm/highmem.h>
+#define PKMAP_INDEX_INVAL (-1)

How about this?

#define PKMAP_INVALID_INDEX (-1)

Okay.

Quoted 23 lines
Quoted 23 lines
include/linux/highmem.h +0 -0
 /* declarations for linux/mm/highmem.c */
 unsigned int nr_free_highpages(void);
mm/highmem.c +2 -2
index 731cf9a..65beb9a 100644
@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)
      return virt_to_page(addr);
 }
 
-static void flush_all_zero_pkmaps(void)
+static int flush_all_zero_pkmaps(void)
 {
      int i;
-     int need_flush = 0;
+     int index = PKMAP_INDEX_INVAL;
 
      flush_cache_kmaps();
 
@@ -141,10 +141,12 @@ static void flush_all_zero_pkmaps(void)
                        &pkmap_page_table[i]);
 
Quoted 6 lines

mm/highmem.c static void flush_all_zero_pkmaps(void) · line 144

Quoted 3 lines
mm/highmem.c +1 -1
              set_page_address(page, NULL);
-             need_flush = 1;
+             index = i;

How about returning first free index instead of last one? and update last_pkmap_nr to it.

Okay. It will be more good.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

PATCH 5/5 mm, highmem: get virtual address of the page using PKMAP_ADDR()

In reply to Joonsoo Kim

In flush_all_zero_pkmaps(), we have an index of the pkmap associated the page. Using this index, we can simply get virtual address of the page. So change it.

mm/highmem.c +1 -2
index 65beb9a..1417f4f 100644
@@ -137,8 +137,7 @@ static int flush_all_zero_pkmaps(void)
 		 * So no dangers, even with speculative execution.
 		 */
 		page = pte_page(pkmap_page_table[i]);
-		pte_clear(&init_mm, (unsigned long)page_address(page),
-			  &pkmap_page_table[i]);
+		pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
 
 		set_page_address(page, NULL);
 		index = i;
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] mm, highmem: get virtual address of the page using PKMAP_ADDR()

Quoted 5 lines · Joonsoo Kim

In flush_all_zero_pkmaps(), we have an index of the pkmap associated the page. Using this index, we can simply get virtual address of the page. So change it.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw
In reply to Joonsoo Kim

Hi Joonsoo,

Quoted 7 lines · Joonsoo Kim

This patchset clean-up and optimize highmem related code.

[1] is just clean-up and doesn't introduce any functional change. [2-3] are for clean-up and optimization.
These eliminate an useless lock opearation and list management. [4-5] is for optimization related to flush_all_zero_pkmaps().

Quoted 7 lines

Joonsoo Kim (5):
mm, highmem: use PKMAP_NR() to calculate an index of pkmap mm, highmem: remove useless pool_lock
mm, highmem: remove page_address_pool list
mm, highmem: makes flush_all_zero_pkmaps() return index of last
flushed entry
mm, highmem: get virtual address of the page using PKMAP_ADDR()

This patchset looks awesome to me.
If you have a plan to respin, please CCed Peter.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw

Hi, Minchan.

2012/10/29 Minchan Kim <[email protected]>:

Quoted 18 lines

Hi Joonsoo,

Quoted 7 lines · Joonsoo Kim

This patchset clean-up and optimize highmem related code.

[1] is just clean-up and doesn't introduce any functional change. [2-3] are for clean-up and optimization.
These eliminate an useless lock opearation and list management. [4-5] is for optimization related to flush_all_zero_pkmaps().

Quoted 7 lines

Joonsoo Kim (5):
mm, highmem: use PKMAP_NR() to calculate an index of pkmap mm, highmem: remove useless pool_lock
mm, highmem: remove page_address_pool list
mm, highmem: makes flush_all_zero_pkmaps() return index of last
flushed entry
mm, highmem: get virtual address of the page using PKMAP_ADDR()

Quoted 2 lines

This patchset looks awesome to me.
If you have a plan to respin, please CCed Peter.

Thanks for review.
I will wait more review and respin, the day after tomorrow. Version 2 will include fix about your comment.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Hello, Andrew.

2012/10/29 JoonSoo Kim <[email protected]>:

Quoted 21 lines

Hi, Minchan.

2012/10/29 Minchan Kim <[email protected]>:

Quoted 18 lines

Hi Joonsoo,

Quoted 14 lines · Joonsoo Kim

This patchset clean-up and optimize highmem related code.

[1] is just clean-up and doesn't introduce any functional change. [2-3] are for clean-up and optimization.
These eliminate an useless lock opearation and list management. [4-5] is for optimization related to flush_all_zero_pkmaps().

Joonsoo Kim (5):
mm, highmem: use PKMAP_NR() to calculate an index of pkmap mm, highmem: remove useless pool_lock
mm, highmem: remove page_address_pool list
mm, highmem: makes flush_all_zero_pkmaps() return index of last
flushed entry
mm, highmem: get virtual address of the page using PKMAP_ADDR()

Quoted 6 lines
Quoted 2 lines

This patchset looks awesome to me.
If you have a plan to respin, please CCed Peter.

Thanks for review.
I will wait more review and respin, the day after tomorrow. Version 2 will include fix about your comment.

Could you pick up second version of this patchset?

[3] is changed to leave one blank line.
[4] is changed in order to further optimize according to Minchan's comment. It return first index of flushed entry, instead of last index. Others doesn't changed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>