minor clean-up and optimize highmem related code
Subsystems (2)
v2 cover minor clean-up and optimize highmem related code
This patchset clean-up and optimize highmem related code.
Change from v1
Rebase on v3.7-rc3
[4] Instead of returning index of last flushed entry, return first index. And update last_pkmap_nr to this index to optimize more.
Summary for v1
[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 first
flushed entry
mm, highmem: get virtual address of the page using PKMAP_ADDR()
include/linux/highmem.h | 1 + mm/highmem.c | 108 ++++++++++++++++++++++------------------------- 2 files changed, 51 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>
PATCH v2 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
@@ -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>
PATCH v2 2/5 mm, highmem: remove useless pool_lock
In reply to Joonsoo KimThe 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
@@ -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>
PATCH v2 3/5 mm, highmem: remove page_address_pool list
In reply to Joonsoo KimWe can find free page_address_map instance without the page_address_pool. So remove it.
mm/highmem.c +2 -16
@@ -324,10 +324,7 @@ struct page_address_map {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 +389,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 +402,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 +411,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>
PATCH v2 4/5 mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
In reply to Joonsoo KimIn 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 first 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 first flushed entry.
Additionally, update last_pkmap_nr to this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updating last_pkmap_nr to this index is reasonable optimization.
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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );
mm/highmem.c +46 -33
120 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>
PATCH v2 5/5 mm, highmem: get virtual address of the page using PKMAP_ADDR()
In reply to Joonsoo KimIn 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
@@ -137,8 +137,7 @@ static unsigned 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 );if (index ==PKMAP_INVALID_INDEX )
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
In reply to Joonsoo KimQuoted 62 lines · Joonsoo Kim
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/**
mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;
I don't know how kmap_flush_unused is really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index = flush_all_zero_pkmaps();
if (index != PKMAP_INVALID_INDEX)
last_pkmap_nr = index;
unlock();
Normally, last_pkmap_nr is increased with searching empty slot in map_new_virtual. So I expect return value of flush_all_zero_pkmaps in kmap_flush_unused normally become either less than last_pkmap_nr or last_pkmap_nr + 1.
Quoted 92 lines
mm/highmem.c +34
-28unlock_kmap (); }static inline unsigned long map_new_virtual (struct page *page) {unsigned long vaddr; +unsigned int index =PKMAP_INVALID_INDEX ;int count; start:@@ -168,40 +176,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 (); +break ; } -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_INVALID_INDEX ) { +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 ; + last_pkmap_nr = index;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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 81 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)
Quoted 7 lines
last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.
There is a case that return value of kmap_flush_unused() is larger than last_pkmap_nr.
Look at the following example.
Assume last_pkmap = 20 and index 1-9, 11-19 is kmapped. 10 is kunmapped.
do kmap_flush_unused() => flush index 10 => last_pkmap = 10; do kunmap() with index 17
do kmap_flush_unused() => flush index 17
So, little dirty implementation is needed.
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Hi Joonsoo,
Quoted 87 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 84 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();
Quoted 7 lines
Quoted 4 lines
Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.
I see but why it's problem? kmap_flush_unused returns larger value than last_pkmap_nr means that there is no free slot at below the value. So unconditional last_pkmap_nr update is vaild.
Quoted 11 lines
Look at the following example.
Assume
last_pkmap= 20 and index 1-9, 11-19 is kmapped. 10 is kunmapped.do
kmap_flush_unused()=> flush index 10 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17So, little dirty implementation is needed.
Thanks.
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.
Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.
I think that this is not true.
Look at the slightly different example.
Assume last_pkmap = 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.
do kmap_flush_unused() => flush index 10,11 => last_pkmap = 10; do kunmap() with index 17
do kmap_flush_unused() => flush index 17 => last_pkmap = 17?
In this case, unconditional last_pkmap_nr update skip one kunmapped index. So, conditional update is needed.
Quoted 8 lines
Quoted 8 lines
Look at the following example.
Assume
last_pkmap= 20 and index 1-9, 11-19 is kmapped. 10 is kunmapped.do
kmap_flush_unused()=> flush index 10 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17
Quoted 7 lines
Quoted 3 lines
So, little dirty implementation is needed.
Thanks.
--
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Quoted 106 lines · JoonSoo Kim
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.
Quoted 8 lines
Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.
Thanks for pouinting out, Joonsoo.
You're right. I misunderstood your flush_all_zero_pkmaps change.
As your change, flush_all_zero_pkmaps returns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index? I think flush_all_zero_pkmaps should return first free slot because customer of flush_all_zero_pkmaps doesn't care whether it's just flushed or not.
What he want is just free or not. In such case, we can remove above check and it makes flusha_all_zero_pkmaps more intuitive.
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
2012/11/13 Minchan Kim <[email protected]>:
Quoted 113 lines · JoonSoo Kim
Quoted 112 lines
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?
Quoted 7 lines
Quoted 2 lines
In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.Thanks for pouinting out, Joonsoo.
You're right. I misunderstood yourflush_all_zero_pkmapschange.
As your change,flush_all_zero_pkmapsreturns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index?
If flush_all_zero_pkmaps() return free slot index rather than first flushed free slot,
we need another comparison like as 'if pkmap_count[i] == 0' and need another local variable for determining whether flush is occurred or not. I want to minimize these overhead and churning of the code, although they are negligible.
Quoted 4 lines
I think
flush_all_zero_pkmapsshould return first free slot because customer offlush_all_zero_pkmapsdoesn't care whether it's just flushed or not. What he want is just free or not. In such case, we can remove above check and it makesflusha_all_zero_pkmapsmore intuitive.
Yes, it is more intuitive, but as I mentioned above, it need another comparison, so with that, a benefit which prevent to re-iterate when there is no free slot, may be disappeared.
--
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Quoted 129 lines · JoonSoo Kim
2012/11/13 Minchan Kim <[email protected]>:
Quoted 113 lines · JoonSoo Kim
Quoted 112 lines
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?Quoted 7 lines
Quoted 2 lines
In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.Thanks for pouinting out, Joonsoo.
You're right. I misunderstood yourflush_all_zero_pkmapschange.
As your change,flush_all_zero_pkmapsreturns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index?If
flush_all_zero_pkmaps()return free slot index rather than first flushed free slot,
we need another comparison like as 'if pkmap_count[i] == 0' and need another local variable for determining whether flush is occurred or not. I want to minimize these overhead and churning of the code, although they are negligible.
Quoted 8 lines
Quoted 4 lines
I think
flush_all_zero_pkmapsshould return first free slot because customer offlush_all_zero_pkmapsdoesn't care whether it's just flushed or not. What he want is just free or not. In such case, we can remove above check and it makesflusha_all_zero_pkmapsmore intuitive.Yes, it is more intuitive, but as I mentioned above, it need another comparison, so with that, a benefit which prevent to re-iterate when there is no free slot, may be disappeared.
If you're very keen on the performance, why do you have such code? You can remove below branch if you were keen on the performance.
mm/highmem.c +2 -3
@@ -114,7 +114,7 @@ static unsigned int flush_all_zero_pkmaps(void)flush_cache_kmaps (); -for (i =0 ; i <LAST_PKMAP ; i++) { +for (i =LAST_PKMAP -1 ; i >=0 ; i--) {struct page *page;/*
@@ -141,8 +141,7 @@ static unsigned int flush_all_zero_pkmaps(void)pte_clear (&init_mm,PKMAP_ADDR (i), &pkmap_page_table[i]);set_page_address (page,NULL ); -if (index ==PKMAP_INVALID_INDEX ) - index = i; + index = i; }if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP ));
Anyway, if you have the concern of performance, Okay let's give up making code clear although I didn't see any report about kmap perfomance. Instead, please consider above optimization because you have already broken what you mentioned.
If we can't make function clear, another method for it is to add function comment. Please.
Quoted 6 lines
--
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Hi, Minchan.
2012/11/14 Minchan Kim <[email protected]>:
Quoted 167 lines · JoonSoo Kim
Quoted 129 lines
2012/11/13 Minchan Kim <[email protected]>:
Quoted 113 lines · JoonSoo Kim
Quoted 112 lines
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?Quoted 7 lines
Quoted 2 lines
In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.Thanks for pouinting out, Joonsoo.
You're right. I misunderstood yourflush_all_zero_pkmapschange.
As your change,flush_all_zero_pkmapsreturns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index?If
flush_all_zero_pkmaps()return free slot index rather than first flushed free slot,
we need another comparison like as 'if pkmap_count[i] == 0' and need another local variable for determining whether flush is occurred or not. I want to minimize these overhead and churning of the code, although they are negligible.Quoted 8 lines
Quoted 4 lines
I think
flush_all_zero_pkmapsshould return first free slot because customer offlush_all_zero_pkmapsdoesn't care whether it's just flushed or not. What he want is just free or not. In such case, we can remove above check and it makesflusha_all_zero_pkmapsmore intuitive.Yes, it is more intuitive, but as I mentioned above, it need another comparison, so with that, a benefit which prevent to re-iterate when there is no free slot, may be disappeared.
If you're very keen on the performance, why do you have such code? You can remove below branch if you were keen on the performance.
mm/highmem.c +2
-3@@ -114,7 +114,7 @@ static unsigned int flush_all_zero_pkmaps(void)flush_cache_kmaps (); -for (i =0 ; i <LAST_PKMAP ; i++) { +for (i =LAST_PKMAP -1 ; i >=0 ; i--) {struct page *page;/* @@ -141,8 +141,7 @@ static unsigned int flush_all_zero_pkmaps(void)pte_clear (&init_mm,PKMAP_ADDR (i), &pkmap_page_table[i]);set_page_address (page,NULL ); -if (index ==PKMAP_INVALID_INDEX ) - index = i; + index = i; }if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP ));
Quoted 4 lines
Anyway, if you have the concern of performance, Okay let's give up making code clear although I didn't see any report about kmap perfomance. Instead, please consider above optimization because you have already broken what you mentioned.
If we can't make function clear, another method for it is to add function comment. Please.
Yes, I also didn't see any report about kmap performance. By your reviewing comment, I eventually reach that this patch will not give any benefit.
So how about to drop it?
Thanks for review.
--
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Hi Joonsoo,
Sorry for the delay.
Quoted 170 lines · JoonSoo Kim
Hi, Minchan.
2012/11/14 Minchan Kim <[email protected]>:
Quoted 167 lines · JoonSoo Kim
Quoted 129 lines
2012/11/13 Minchan Kim <[email protected]>:
Quoted 113 lines · JoonSoo Kim
Quoted 112 lines
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?Quoted 7 lines
Quoted 2 lines
In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.Thanks for pouinting out, Joonsoo.
You're right. I misunderstood yourflush_all_zero_pkmapschange.
As your change,flush_all_zero_pkmapsreturns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index?If
flush_all_zero_pkmaps()return free slot index rather than first flushed free slot,
we need another comparison like as 'if pkmap_count[i] == 0' and need another local variable for determining whether flush is occurred or not. I want to minimize these overhead and churning of the code, although they are negligible.Quoted 8 lines
Quoted 4 lines
I think
flush_all_zero_pkmapsshould return first free slot because customer offlush_all_zero_pkmapsdoesn't care whether it's just flushed or not. What he want is just free or not. In such case, we can remove above check and it makesflusha_all_zero_pkmapsmore intuitive.Yes, it is more intuitive, but as I mentioned above, it need another comparison, so with that, a benefit which prevent to re-iterate when there is no free slot, may be disappeared.
If you're very keen on the performance, why do you have such code? You can remove below branch if you were keen on the performance.
mm/highmem.c +2
-3@@ -114,7 +114,7 @@ static unsigned int flush_all_zero_pkmaps(void)flush_cache_kmaps (); -for (i =0 ; i <LAST_PKMAP ; i++) { +for (i =LAST_PKMAP -1 ; i >=0 ; i--) {struct page *page;/* @@ -141,8 +141,7 @@ static unsigned int flush_all_zero_pkmaps(void)pte_clear (&init_mm,PKMAP_ADDR (i), &pkmap_page_table[i]);set_page_address (page,NULL ); -if (index ==PKMAP_INVALID_INDEX ) - index = i; + index = i; }if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP ));
Quoted 9 lines
Quoted 4 lines
Anyway, if you have the concern of performance, Okay let's give up making code clear although I didn't see any report about kmap perfomance. Instead, please consider above optimization because you have already broken what you mentioned.
If we can't make function clear, another method for it is to add function comment. Please.Yes, I also didn't see any report about kmap performance. By your reviewing comment, I eventually reach that this patch will not give any benefit.
So how about to drop it?
Personally, I prefer to proceed but if you don't have a confidence about gain, No problem to drop it.
Thanks.
Quoted 8 lines
Thanks for review.
--
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>
Re: [PATCH v2 4/5] mm, highmem: makes flush_all_zero_pkmaps() return index of first flushed entry
Hello, Andrew.
2012/11/20 Minchan Kim <[email protected]>:
Quoted 184 lines
Hi Joonsoo,
Sorry for the delay.Quoted 170 lines · JoonSoo Kim
Hi, Minchan.
2012/11/14 Minchan Kim <[email protected]>:
Quoted 167 lines · JoonSoo Kim
Quoted 129 lines
2012/11/13 Minchan Kim <[email protected]>:
Quoted 113 lines · JoonSoo Kim
Quoted 112 lines
2012/11/3 Minchan Kim <[email protected]>:
Quoted 95 lines
Hi Joonsoo,
Quoted 92 lines · JoonSoo Kim
Hello, Minchan.
2012/11/1 Minchan Kim <[email protected]>:
Quoted 88 lines · Joonsoo Kim
Quoted 62 lines
In current code, after
flush_all_zero_pkmaps()is invoked,
then re-iterate all pkmaps. It can be optimized ifflush_all_zero_pkmaps()return index of first flushed entry. With this index,
we can immediately map highmem page to virtual address represented by index. So change return type offlush_all_zero_pkmaps()
and return index of first flushed entry.Additionally, update
last_pkmap_nrto this index.
It is certain that entry which is below this index is occupied by other mapping, therefore updatinglast_pkmap_nrto this index is reasonable optimization.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Minchan Kim <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>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_INVALID_INDEX (LAST_PKMAP)/* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages (void );mm/highmem.c +7
-4@@ -106,10 +106,10 @@ struct page *kmap_to_page(void *vaddr)return virt_to_page (addr); } -static void flush_all_zero_pkmaps (void ) +static unsigned int flush_all_zero_pkmaps (void ) {int i; -int need_flush =0 ; +unsigned int index =PKMAP_INVALID_INDEX ;flush_cache_kmaps ();@@ -141,10 +141,13 @@ static void flush_all_zero_pkmaps(void) &pkmap_page_table[i]);set_page_address (page,NULL ); - need_flush =1 ; +if (index ==PKMAP_INVALID_INDEX ) + index = i; } -if (need_flush) +if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); + +return index; }/** mm/highmem.c static void flush_all_zero_pkmaps(void) · line 163
Quoted 10 lines
mm/highmem.c +5
-1@@ -152,14 +155,19 @@ static void flush_all_zero_pkmaps(void)*/ void kmap_flush_unused (void ) { +unsigned int index; +lock_kmap (); -flush_all_zero_pkmaps (); + index =flush_all_zero_pkmaps (); +if (index !=PKMAP_INVALID_INDEX && (index < last_pkmap_nr)) + last_pkmap_nr = index;I don't know how
kmap_flush_unusedis really fast path so how my nitpick is effective. Anyway,
What problem happens if we do following as?
lock()
index =flush_all_zero_pkmaps();
if (index !=PKMAP_INVALID_INDEX)last_pkmap_nr = index;
unlock();Normally,
last_pkmap_nris increased with searching empty slot inmap_new_virtual. So I expect return value offlush_all_zero_pkmapsinkmap_flush_unusednormally become either less thanlast_pkmap_nrorlast_pkmap_nr+ 1.Quoted 6 lines
Quoted 2 lines
There is a case that return value of
kmap_flush_unused()is larger thanlast_pkmap_nr.I see but why it's problem?
kmap_flush_unusedreturns larger value thanlast_pkmap_nrmeans that there is no free slot at below the value. So unconditionallast_pkmap_nrupdate is vaild.I think that this is not true.
Look at the slightly different example.Assume
last_pkmap= 20 and index 1-9, 12-19 is kmapped. 10, 11 is kunmapped.do
kmap_flush_unused()=> flush index 10,11 =>last_pkmap= 10; dokunmap()with index 17
dokmap_flush_unused()=> flush index 17 =>last_pkmap= 17?Quoted 7 lines
Quoted 2 lines
In this case, unconditional
last_pkmap_nrupdate skip one kunmapped index. So, conditional update is needed.Thanks for pouinting out, Joonsoo.
You're right. I misunderstood yourflush_all_zero_pkmapschange.
As your change,flush_all_zero_pkmapsreturns first *flushed* free slot index. What's the benefit returning flushed flushed free slot index rather than free slot index?If
flush_all_zero_pkmaps()return free slot index rather than first flushed free slot,
we need another comparison like as 'if pkmap_count[i] == 0' and need another local variable for determining whether flush is occurred or not. I want to minimize these overhead and churning of the code, although they are negligible.Quoted 8 lines
Quoted 4 lines
I think
flush_all_zero_pkmapsshould return first free slot because customer offlush_all_zero_pkmapsdoesn't care whether it's just flushed or not. What he want is just free or not. In such case, we can remove above check and it makesflusha_all_zero_pkmapsmore intuitive.Yes, it is more intuitive, but as I mentioned above, it need another comparison, so with that, a benefit which prevent to re-iterate when there is no free slot, may be disappeared.
If you're very keen on the performance, why do you have such code? You can remove below branch if you were keen on the performance.
mm/highmem.c +2
-3@@ -114,7 +114,7 @@ static unsigned int flush_all_zero_pkmaps(void)flush_cache_kmaps (); -for (i =0 ; i <LAST_PKMAP ; i++) { +for (i =LAST_PKMAP -1 ; i >=0 ; i--) {struct page *page;/* @@ -141,8 +141,7 @@ static unsigned int flush_all_zero_pkmaps(void)pte_clear (&init_mm,PKMAP_ADDR (i), &pkmap_page_table[i]);set_page_address (page,NULL ); -if (index ==PKMAP_INVALID_INDEX ) - index = i; + index = i; }if (index !=PKMAP_INVALID_INDEX )flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP ));Quoted 9 lines
Quoted 4 lines
Anyway, if you have the concern of performance, Okay let's give up making code clear although I didn't see any report about kmap perfomance. Instead, please consider above optimization because you have already broken what you mentioned.
If we can't make function clear, another method for it is to add function comment. Please.Yes, I also didn't see any report about kmap performance. By your reviewing comment, I eventually reach that this patch will not give any benefit.
So how about to drop it?
Quoted 6 lines
Personally, I prefer to proceed but if you don't have a confidence about gain, No problem to drop it.
Thanks.Quoted 2 lines
Thanks for review.
During the review, I concluded that this patch have no gain. And this patch churn the code too much.
So I want to drop this patch for your tree.
Sorry for late notification.
--
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>