From: Li Haifeng <omycle@gmail.com>
To: "open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
open list <linux-kernel@vger.kernel.org>,
linux-arm-kernel@lists.infradead.org,
Johannes Weiner <hannes@cmpxchg.org>
Subject: [PATCH] mm: Fixup the condition whether the page cache is free
Date: Mon, 4 Mar 2013 09:54:26 +0800 [thread overview]
Message-ID: <CAFNq8R7tq9kvD9LyhZJ-Cj0kexQfDsPhB4iQYyZ9s9+8Jo82QA@mail.gmail.com> (raw)
When a page cache is to reclaim, we should to decide whether the page
cache is free.
IMO, the condition whether a page cache is free should be 3 in page
frame reclaiming. The reason lists as below.
When page is allocated, the page->_count is 1(code fragment is code-1 ).
And when the page is allocated for reading files from extern disk, the
page->_count will increment 1 by page_cache_get() in
add_to_page_cache_locked()(code fragment is code-2). When the page is to
reclaim, the isolated LRU list also increase the page->_count(code
fragment is code-3).
According above reasons, when the file page is freeable, the
page->_count should be 3 instead of 2.
<code-1>
buffered_rmqueue ->prep_new_page->set_page_refcounted:
24 /*
25 * Turn a non-refcounted page (->_count == 0) into refcounted with
26 * a count of one.
27 */
28 static inline void set_page_refcounted(struct page *page)
29 {
30 VM_BUG_ON(PageTail(page));
31 VM_BUG_ON(atomic_read(&page->_count));
32 set_page_count(page, 1);
33 }
<code-2>
do_generic_file_read ->add_to_page_cache_lru-> add_to_page_cache->
add_to_page_cache_locked:
int add_to_page_cache_locked(struct page *page, struct address_space
*mapping,
pgoff_t offset, gfp_t gfp_mask)
{
…
page_cache_get(page);
page->mapping = mapping;
page->index = offset;
spin_lock_irq(&mapping->tree_lock);
error = radix_tree_insert(&mapping->page_tree, offset,
page);
if (likely(!error)) {
mapping->nrpages++;
__inc_zone_page_state(page, NR_FILE_PAGES);
spin_unlock_irq(&mapping->tree_lock);
…
}
<code-3>
static noinline_for_stack unsigned long
shrink_inactive_list(unsigned long nr_to_scan, struct mem_cgroup_zone
*mz,
struct scan_control *sc, int priority, int file)
{
…
nr_taken = isolate_lru_pages(nr_to_scan, mz, &page_list,
&nr_scanned,
sc, isolate_mode, 0, file);
…
nr_reclaimed = shrink_page_list(&page_list, mz, sc, priority,
&nr_dirty,
&nr_writeback);
}
Remarks for code-3:
isolate_lru_pages() will call get_page_unless_zero() ultimately to
increase the page->_count by 1.
And shrink_page_list() will call is_page_cache_freeable() finally to
check whether the page cache is free.
next reply other threads:[~2013-03-04 1:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-04 1:54 Li Haifeng [this message]
2013-03-04 15:09 ` Johannes Weiner
2013-03-05 1:51 ` Li Haifeng
2013-03-06 1:04 ` Simon Jeons
2013-03-06 19:47 ` Johannes Weiner
2013-03-07 1:05 ` Simon Jeons
2013-03-08 2:13 ` Simon Jeons
2013-03-08 2:37 ` Johannes Weiner
2013-03-08 2:48 ` Simon Jeons
2013-03-08 3:16 ` Johannes Weiner
2013-03-12 3:19 ` Simon Jeons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFNq8R7tq9kvD9LyhZJ-Cj0kexQfDsPhB4iQYyZ9s9+8Jo82QA@mail.gmail.com \
--to=omycle@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox