From patchwork Mon Mar 4 01:54:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Haifeng X-Patchwork-Id: 2208911 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id E7B3EDF215 for ; Mon, 4 Mar 2013 02:02:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UCKeC-00016c-0M; Mon, 04 Mar 2013 01:57:00 +0000 Received: from mail-we0-f172.google.com ([74.125.82.172]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UCKe5-00015C-Hy for linux-arm-kernel@lists.infradead.org; Mon, 04 Mar 2013 01:56:57 +0000 Received: by mail-we0-f172.google.com with SMTP id x10so4140707wey.17 for ; Sun, 03 Mar 2013 17:54:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Zqr/o0wTYIJeo8dymuSjdnqqZN2CsNKSI2hcMm0b9do=; b=jtM2Jc7mSrG2RiJMu2H64XzrQx91hqVv6y/GO4XKBmzzvvdjXdn2kLaRBEjkH/iX3b wDpq374f7PNXq7+Ec79dKPU5NOffIrpohkByBQJd1AiktNcHR7jaVpislvZ1dvpVuDOz mmAo+qr2YEVPWXmBjbpGAwNMF5DoFYqt5bG45ux8dqKuOO8Rmn3lU3A03dbDgaegjAkP M8UO94Pc6PtgGc72xS7S75nC/5hK67EcZBjlzBbCFHujk7WIfU7ca1IP0NrHGGRKI76p E/WvMq2SQOmcugqz2Mz+ayvfKk5mCCNjtOBXcu5z1PxDWI6ndnEHCH8yGwORNm7YZzb+ vrCA== MIME-Version: 1.0 X-Received: by 10.180.81.164 with SMTP id b4mr8564383wiy.34.1362362066561; Sun, 03 Mar 2013 17:54:26 -0800 (PST) Received: by 10.194.174.164 with HTTP; Sun, 3 Mar 2013 17:54:26 -0800 (PST) Date: Mon, 4 Mar 2013 09:54:26 +0800 Message-ID: Subject: [PATCH] mm: Fixup the condition whether the page cache is free From: Li Haifeng To: "open list:MEMORY MANAGEMENT" , open list , linux-arm-kernel@lists.infradead.org, Johannes Weiner X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130303_205653_683572_F40804A7 X-CRM114-Status: GOOD ( 15.09 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (omycle[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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. 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 } 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); … } 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. From 59b25b5e0163dcb120d913b570c1b8b5b0c47c5d Mon Sep 17 00:00:00 2001 From: Haifeng Li Date: Mon, 4 Mar 2013 09:42:53 +0800 Subject: [PATCH] mm: Fixup the condition whether the page cache is free When a page is allocated, its reference is 1. If the page is inserted into page cache tree, the referenced also should be increased by 1. In reclaiming routine, it also referenced by isolated list. So here, the condition whether the page is free should be 3. Signed-off-by: Haifeng Li --- mm/vmscan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/mm/vmscan.c b/mm/vmscan.c index 6759993..b588378 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -400,11 +400,12 @@ static void reset_reclaim_mode(struct scan_control *sc) static inline int is_page_cache_freeable(struct page *page) { /* - * A freeable page cache page is referenced only by the caller - * that isolated the page, the page cache radix tree and - * optional buffer heads at page->private. + * A freeable page cache page, _count of which is + * initialized by 1. And it is also referenced only + * by the caller that isolated the page, the page cache + * radix tree and optional buffer heads at page->private. */ - return page_count(page) - page_has_private(page) == 2; + return page_count(page) - page_has_private(page) == 3; } static int may_write_to_queue(struct backing_dev_info *bdi,