Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755416Ab2BLAXl (ORCPT ); Sat, 11 Feb 2012 19:23:41 -0500 Received: from mail.betterlinux.com ([199.58.199.50]:56629 "EHLO mail.betterlinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755387Ab2BLAXg (ORCPT ); Sat, 11 Feb 2012 19:23:36 -0500 X-DKIM: OpenDKIM Filter v2.4.1 mail.betterlinux.com 75F5D82A54 From: Andrea Righi To: Andrew Morton Cc: Minchan Kim , Peter Zijlstra , Johannes Weiner , KAMEZAWA Hiroyuki , KOSAKI Motohiro , Rik van Riel , Hugh Dickins , Alexander Viro , Shaohua Li , =?UTF-8?q?P=C3=A1draig=20Brady?= , John Stultz , Jerry James , Julius Plenz , linux-mm , linux-fsdevel@vger.kernel.org, LKML Subject: [PATCH v5 2/3] mm: filemap: introduce mark_page_usedonce Date: Sun, 12 Feb 2012 01:21:37 +0100 Message-Id: <1329006098-5454-3-git-send-email-andrea@betterlinux.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1329006098-5454-1-git-send-email-andrea@betterlinux.com> References: <1329006098-5454-1-git-send-email-andrea@betterlinux.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1946 Lines: 67 Introduce a helper function to drop a page from the page cache if it is evictable, inactive and unreferenced. This can be used to drop used-once pages from the file cache with POSIX_FADV_NOREUSE. Signed-off-by: Andrea Righi --- include/linux/swap.h | 1 + mm/swap.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 3e60228..2e5d1b8 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -222,6 +222,7 @@ extern void lru_add_page_tail(struct zone* zone, struct page *page, struct page *page_tail); extern void activate_page(struct page *); extern void mark_page_accessed(struct page *); +extern void mark_page_usedonce(struct page *page); extern void lru_add_drain(void); extern int lru_add_drain_all(void); extern void rotate_reclaimable_page(struct page *page); diff --git a/mm/swap.c b/mm/swap.c index fff1ff7..2c19c92 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -352,6 +352,30 @@ void activate_page(struct page *page) } #endif +/** + * mark_page_usedonce - handle used-once pages + * @page: the page set as used-once + * + * Drop a page from the page cache if it is evictable, inactive and + * unreferenced. + */ +void mark_page_usedonce(struct page *page) +{ + int ret; + + if (!PageLRU(page)) + return; + if (PageActive(page) || PageUnevictable(page) || PageReferenced(page)) + return; + if (lock_page_killable(page)) + return; + ret = invalidate_inode_page(page); + unlock_page(page); + if (!ret) + deactivate_page(page); +} +EXPORT_SYMBOL(mark_page_usedonce); + /* * Mark a page as having seen activity. * -- 1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/