Skip to contentSkip to conversation

improve read ahead in kernel

PATCH In review xtu4 5 participants 6 messages Dec 9, 2012 – Dec 20, 2012

Subsystems (5)
lore
Share & tools
lore

xtu4

author
#0 lore raw

PATCH 1/1 improve read ahead in kernel

Subject: [PATCH] when system in low memory scenario, imaging there is a mp3
play, or video play, we need to read mp3 or video file
from memory to page cache,but when system lack of memory,
page cache of mp3 or video file will be reclaimed.once read
in memory, then reclaimed, it will cause audio or video glitch,and it will increase the io operation at the same
time.

---
 include/linux/mm_types.h |    4 ++++
 mm/Kconfig               |    6 ++++++
 mm/filemap.c             |    4 ++++
 mm/readahead.c           |   20 +++++++++++++++++---
 mm/vmscan.c              |   10 ++++++++--
 5 files changed, 39 insertions(+), 5 deletions(-)
include/linux/mm_types.h +4 -0
index 5b42f1b..541864d 100644
@@ -149,6 +149,10 @@ struct page {
      */
     void *shadow;
 #endif
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    unsigned int ioprio;
+#endif
+
 }
 /*
  * If another subsystem starts using the double word pairing for atomic
mm/Kconfig +6 -0
index e338407..dade8d3 100644
@@ -140,6 +140,12 @@ config ARCH_DISCARD_MEMBLOCK
 config NO_BOOTMEM
     boolean
 
+# improve readahead in low memory scenario
+config LOWMEMORY_READAHEAD
+    bool "improve readahead in low memory scenario"
+    depends on (IA64 || X86)
+
+
 # eventually, we can have this option just 'select SPARSEMEM'
 config MEMORY_HOTPLUG
     bool "Allow for memory hot-add"
mm/filemap.c +4 -0
index a0701e6..e32efed8 100644
@@ -129,6 +129,10 @@ void __delete_from_page_cache(struct page *page)
     page->mapping = NULL;
     /* Leave page->index set: truncation lookup relies upon it */
     mapping->nrpages--;
+    #ifdef CONFIG_LOWMEMORY_READAHEAD
+    page->ioprio = 0;
+    #endif
+
     __dec_zone_page_state(page, NR_FILE_PAGES);
     if (PageSwapBacked(page))
         __dec_zone_page_state(page, NR_SHMEM);
mm/readahead.c +17 -3
index cbcbb02..dd07cfe 100644
@@ -159,6 +159,11 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
     int page_idx;
     int ret = 0;
     loff_t isize = i_size_read(inode);
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    int class = 0;
+    if (p->io_context)
+    class = IOPRIO_PRIO_CLASS(p->io_context->ioprio);
+#endif
 
     if (isize == 0)
         goto out;
@@ -177,12 +182,21 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
         rcu_read_lock();
         page = radix_tree_lookup(&mapping->page_tree, page_offset);
         rcu_read_unlock();
-        if (page)
-            continue;
-
+        if (page){
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+            if (class == IOPRIO_CLASS_RT) {
+                page->ioprio = 1;
+#endif
+                continue;
+            }
         page = page_cache_alloc_readahead(mapping);
         if (!page)
             break;
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (class == IOPRIO_CLASS_RT) {
+            page->ioprio = 1;
+#endif
+
         page->index = page_offset;
         list_add(&page->lru, &page_pool);
         if (page_idx == nr_to_read - lookahead_size)
mm/vmscan.c +8 -2
index 753a2dc..86e03aa 100644
@@ -728,8 +728,14 @@ static enum page_references page_check_references(struct page *page,
     }
 
     /* Reclaim if clean, defer dirty pages to writeback */
-    if (referenced_page && !PageSwapBacked(page))
-        return PAGEREF_RECLAIM_CLEAN;
+    if (referenced_page && !PageSwapBacked(page)) {
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (page->ioprio == 1) {
+            return PAGEREF_ACTIVATE;
+        } else
+#endif
+            return PAGEREF_RECLAIM_CLEAN;
+    }
 
     return PAGEREF_RECLAIM;
 }
Signature · 7 lines
1.7.6

--
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
Quoted 10 lines · On 12/09/12 07:57, xtu4 wrote:

Subject: [PATCH] when system in low memory scenario, imaging there is a mp3
play, or video play, we need to read mp3 or video file
from memory to page cache,but when system lack of memory,
page cache of mp3 or video file will be reclaimed.once read
in memory, then reclaimed, it will cause audio or video glitch,and it will increase the io operation at the same
time.

What tree does this patch apply to?

It looks like most (or all) of the tabs in the source files have been changed to spaces, which is Not Good.
Maybe some info in Documentation/email-clients.txt could help you.

Quoted 28 lines
---
 include/linux/mm_types.h |    4 ++++
 mm/Kconfig               |    6 ++++++
 mm/filemap.c             |    4 ++++
 mm/readahead.c           |   20 +++++++++++++++++---
 mm/vmscan.c              |   10 ++++++++--
 5 files changed, 39 insertions(+), 5 deletions(-)
include/linux/mm_types.h +4 -0
index 5b42f1b..541864d 100644
@@ -149,6 +149,10 @@ struct page {
      */
     void *shadow;
 #endif
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    unsigned int ioprio;
+#endif
+
 }
 /*
  * If another subsystem starts using the double word pairing for atomic
mm/Kconfig +0 -0
index e338407..dade8d3 100644

mm/Kconfig config ARCH_DISCARD_MEMBLOCK · line 146

Quoted 7 lines
mm/Kconfig +4 -0
@@ -140,6 +140,12 @@ config ARCH_DISCARD_MEMBLOCK
 config NO_BOOTMEM
     boolean
 
+# improve readahead in low memory scenario
+config LOWMEMORY_READAHEAD
+    bool "improve readahead in low memory scenario"
+    depends on (IA64 || X86)

Why this depends on?
I don't see anything that is arch-specific in the patch.

Quoted 82 lines
mm/Kconfig +2 -0
+
+
 # eventually, we can have this option just 'select SPARSEMEM'
 config MEMORY_HOTPLUG
     bool "Allow for memory hot-add"
mm/filemap.c +4 -0
index a0701e6..e32efed8 100644
@@ -129,6 +129,10 @@ void __delete_from_page_cache(struct page *page)
     page->mapping = NULL;
     /* Leave page->index set: truncation lookup relies upon it */
     mapping->nrpages--;
+    #ifdef CONFIG_LOWMEMORY_READAHEAD
+    page->ioprio = 0;
+    #endif
+
     __dec_zone_page_state(page, NR_FILE_PAGES);
     if (PageSwapBacked(page))
         __dec_zone_page_state(page, NR_SHMEM);
mm/readahead.c +17 -3
index cbcbb02..dd07cfe 100644
@@ -159,6 +159,11 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
     int page_idx;
     int ret = 0;
     loff_t isize = i_size_read(inode);
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    int class = 0;
+    if (p->io_context)
+    class = IOPRIO_PRIO_CLASS(p->io_context->ioprio);
+#endif
 
     if (isize == 0)
         goto out;
@@ -177,12 +182,21 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
         rcu_read_lock();
         page = radix_tree_lookup(&mapping->page_tree, page_offset);
         rcu_read_unlock();
-        if (page)
-            continue;
-
+        if (page){
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+            if (class == IOPRIO_CLASS_RT) {
+                page->ioprio = 1;
+#endif
+                continue;
+            }
         page = page_cache_alloc_readahead(mapping);
         if (!page)
             break;
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (class == IOPRIO_CLASS_RT) {
+            page->ioprio = 1;
+#endif
+
         page->index = page_offset;
         list_add(&page->lru, &page_pool);
         if (page_idx == nr_to_read - lookahead_size)
mm/vmscan.c +8 -2
index 753a2dc..86e03aa 100644
@@ -728,8 +728,14 @@ static enum page_references page_check_references(struct page *page,
     }
 
     /* Reclaim if clean, defer dirty pages to writeback */
-    if (referenced_page && !PageSwapBacked(page))
-        return PAGEREF_RECLAIM_CLEAN;
+    if (referenced_page && !PageSwapBacked(page)) {
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (page->ioprio == 1) {
+            return PAGEREF_ACTIVATE;
+        } else
+#endif
+            return PAGEREF_RECLAIM_CLEAN;
+    }
 
     return PAGEREF_RECLAIM;
 }
Signature · 7 lines
~Randy

--
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>
author
#2 lore raw

resend--[PATCH] improve read ahead in kernel

In reply to xtu4

resend it, due to format error

Subject: [PATCH] when system in low memory scenario, imaging there is a mp3
play, ora video play, we need to read mp3 or video file
from memory to page cache,but when system lack of memory,
page cache of mp3 or video file will be reclaimed.once read
in memory, then reclaimed, it will cause audio or video glitch,and it will increase the io operation at the same
time.

---
 include/linux/mm_types.h |    4 ++++
 mm/filemap.c             |    4 ++++
 mm/readahead.c           |   20 +++++++++++++++++---
 mm/vmscan.c              |   10 ++++++++--
 4 files changed, 33 insertions(+), 5 deletions(-)
include/linux/mm_types.h +4 -0
index 5b42f1b..2739995 100644
@@ -149,6 +149,10 @@ struct page {
      */
     void *shadow;
 #endif
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    unsigned int ioprio;
+#endif
+
 }
 /*
  * If another subsystem starts using the double word pairing for atomic
mm/filemap.c +4 -0
index a0701e6..ca3a3e8 100644
@@ -129,6 +129,10 @@ void __delete_from_page_cache(struct page *page)
     page->mapping = NULL;
     /* Leave page->index set: truncation lookup relies upon it */
     mapping->nrpages--;
+    #ifdef CONFIG_LOWMEMORY_READAHEAD
+    page->ioprio = 0;
+    #endif
+
     __dec_zone_page_state(page, NR_FILE_PAGES);
     if (PageSwapBacked(page))
         __dec_zone_page_state(page, NR_SHMEM);
mm/readahead.c +17 -3
index cbcbb02..5c2d2ff 100644
@@ -159,6 +159,11 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
     int page_idx;
     int ret = 0;
     loff_t isize = i_size_read(inode);
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+    int class = 0;
+    if (p->io_context)
+    class = IOPRIO_PRIO_CLASS(p->io_context->ioprio);
+#endif
 
     if (isize == 0)
         goto out;
@@ -177,12 +182,21 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
         rcu_read_lock();
         page = radix_tree_lookup(&mapping->page_tree, page_offset);
         rcu_read_unlock();
-        if (page)
-            continue;
-
+        if (page){
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+            if (class == IOPRIO_CLASS_RT) {
+                page->ioprio = 1;
+#endif
+                continue;
+            }
         page = page_cache_alloc_readahead(mapping);
         if (!page)
             break;
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (class == IOPRIO_CLASS_RT) {
+            page->ioprio = 1;
+#endif
+
         page->index = page_offset;
         list_add(&page->lru, &page_pool);
         if (page_idx == nr_to_read - lookahead_size)
mm/vmscan.c +8 -2
index 753a2dc..0a1cae8 100644
@@ -728,8 +728,14 @@ static enum page_references page_check_references(struct page *page,
     }
 
     /* Reclaim if clean, defer dirty pages to writeback */
-    if (referenced_page && !PageSwapBacked(page))
-        return PAGEREF_RECLAIM_CLEAN;
+    if (referenced_page && !PageSwapBacked(page)) {
+#ifdef CONFIG_LOWMEMORY_READAHEAD
+        if (page->ioprio == 1) {
+            return PAGEREF_ACTIVATE;
+        } else
+#endif
+            return PAGEREF_RECLAIM_CLEAN;
+    }
 
     return PAGEREF_RECLAIM;
 }
Signature · 7 lines
1.7.6

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

Re: resend--[PATCH] improve read ahead in kernel

Quoted 9 lines · xtu4 <[email protected]> wrote:

resend it, due to format error

Subject: [PATCH] when system in low memory scenario, imaging there is a mp3
play, ora video play, we need to read mp3 or video file
from memory to page cache,but when system lack of memory,
page cache of mp3 or video file will be reclaimed.once read
in memory, then reclaimed, it will cause audio or video glitch,and it will increase the io operation at the same
time.

To me, this basically describes how POSIX_FADV_NOREUSE should work. I would like to have this ability via fadvise (and not CONFIG_).

Also, I think your patch has too many #ifdefs to be accepted.

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

#4 lore raw

Re: resend--[PATCH] improve read ahead in kernel

Quoted 11 lines · Eric Wong
Quoted 9 lines · xtu4 <[email protected]> wrote:

resend it, due to format error

Subject: [PATCH] when system in low memory scenario, imaging there is a mp3
play, ora video play, we need to read mp3 or video file
from memory to page cache,but when system lack of memory,
page cache of mp3 or video file will be reclaimed.once read
in memory, then reclaimed, it will cause audio or video glitch,and it will increase the io operation at the same
time.

Quoted 1 line

To me, this basically describes how POSIX_FADV_NOREUSE should work.

Hi Eric,

But why fadvise POSIX_FADV_NOREUSE almost do nothing? Why not set some flag or other things for these use once data?

Quoted 9 lines

I would like to have this ability via fadvise (and not CONFIG_).

Also, I think your patch has too many #ifdefs to be accepted.

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

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

#5 lore raw

Re: resend--[PATCH] improve read ahead in kernel

Hi Simon,

20.12.2012, 10:21, "Simon Jeons" <[email protected]>:

Quoted 12 lines · Eric Wong
Quoted 11 lines
Quoted 9 lines · ?xtu4 <[email protected]> wrote:

?resend it, due to format error

?Subject: [PATCH] when system in low memory scenario, imaging there is a mp3 ??play, ora video play, we need to read mp3 or video file
??from memory to page cache,but when system lack of memory, ??page cache of mp3 or video file will be reclaimed.once read ??in memory, then reclaimed, it will cause audio or video ??glitch,and it will increase the io operation at the same ??time.

Quoted 6 lines
Quoted 1 line

?To me, this basically describes how POSIX_FADV_NOREUSE should work.

Hi Eric,

But why fadvise POSIX_FADV_NOREUSE almost do nothing? Why not set some flag or other things for these use once data?

Because, it's not clear how should it work in some cases.
Do we expect one access? Should we track a page as accessed after any access (even if only one byte was read)? What should we do with already-cached pages? etc.

IMHO, it will be better to introduce something like POSIX_FADV_DONTCACHE.
Corresponding pages can be added (ratated) to the tail of the inactive LRU after copying data in read() internals, or after minor/major pagefault.

Quoted 11 lines
Quoted 10 lines

?I would like to have this ability via fadvise (and not CONFIG_).

?Also, I think your patch has too many #ifdefs to be accepted.

?--
?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>

Quoted 5 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>

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