From patchwork Mon Jun 13 09:47:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 9172499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D77456075D for ; Mon, 13 Jun 2016 09:54:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C76BC200F5 for ; Mon, 13 Jun 2016 09:54:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC13020855; Mon, 13 Jun 2016 09:54:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F03200F5 for ; Mon, 13 Jun 2016 09:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161222AbcFMJxg (ORCPT ); Mon, 13 Jun 2016 05:53:36 -0400 Received: from mga01.intel.com ([192.55.52.88]:31916 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161105AbcFMJxf (ORCPT ); Mon, 13 Jun 2016 05:53:35 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 13 Jun 2016 02:53:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,466,1459839600"; d="scan'208";a="826899001" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by orsmga003.jf.intel.com with ESMTP; 13 Jun 2016 02:53:32 -0700 From: Liang Li To: kvm@vger.kernel.org Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongun.org, linux-kernel@vger.kernel.org, mst@redhat.com, Liang Li , Paolo Bonzini , Cornelia Huck , Amit Shah , Alexander Viro Subject: [PATCH 3/6] mm:split the drop cache operation into a function Date: Mon, 13 Jun 2016 17:47:10 +0800 Message-Id: <1465811233-21136-4-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465811233-21136-1-git-send-email-liang.z.li@intel.com> References: <1465811233-21136-1-git-send-email-liang.z.li@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Put the drop caches operation in a new function and export it, then wen can reuse it later. Signed-off-by: Liang Li Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Cornelia Huck Cc: Amit Shah Cc: Alexander Viro --- fs/drop_caches.c | 22 ++++++++++++++-------- include/linux/mm.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/drop_caches.c b/fs/drop_caches.c index d72d52b..977dc71 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c @@ -50,14 +50,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write, if (write) { static int stfu; - if (sysctl_drop_caches & 1) { - iterate_supers(drop_pagecache_sb, NULL); - count_vm_event(DROP_PAGECACHE); - } - if (sysctl_drop_caches & 2) { - drop_slab(); - count_vm_event(DROP_SLAB); - } + drop_caches(sysctl_drop_caches); if (!stfu) { pr_info("%s (%d): drop_caches: %d\n", current->comm, task_pid_nr(current), @@ -67,3 +60,16 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write, } return 0; } + +void drop_caches(int drop_ctl) +{ + if (drop_ctl & 1) { + iterate_supers(drop_pagecache_sb, NULL); + count_vm_event(DROP_PAGECACHE); + } + if (drop_ctl & 2) { + drop_slab(); + count_vm_event(DROP_SLAB); + } +} +EXPORT_SYMBOL_GPL(drop_caches); diff --git a/include/linux/mm.h b/include/linux/mm.h index 5df5feb..e22e315 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2263,6 +2263,7 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr) extern int sysctl_drop_caches; int drop_caches_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); +void drop_caches(int drop_ctl); #endif void drop_slab(void);