From patchwork Wed Mar 23 06:09:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: akash.goel@intel.com X-Patchwork-Id: 8647221 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E586D9F36E for ; Wed, 23 Mar 2016 05:57:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F00192038D for ; Wed, 23 Mar 2016 05:57:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E21702038A for ; Wed, 23 Mar 2016 05:57:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B83A6E7E0; Wed, 23 Mar 2016 05:57:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C0A46E3C7 for ; Wed, 23 Mar 2016 05:57:01 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 22 Mar 2016 22:57:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,381,1455004800"; d="scan'208";a="929940824" Received: from akashgoe-desktop.iind.intel.com ([10.223.82.36]) by fmsmga001.fm.intel.com with ESMTP; 22 Mar 2016 22:56:58 -0700 From: akash.goel@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Mar 2016 11:39:43 +0530 Message-Id: <1458713384-25688-1-git-send-email-akash.goel@intel.com> X-Mailer: git-send-email 1.9.2 Cc: linux-mm@kvack.org, Sourab Gupta , Hugh Dickins , Akash Goel Subject: [Intel-gfx] [PATCH 1/2] shmem: Support for registration of Driver/file owner specific ops X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Wilson This provides support for the Drivers or shmem file owners to register a set of callbacks, which can be invoked from the address space operations methods implemented by shmem. This allow the file owners to hook into the shmem address space operations to do some extra/custom operations in addition to the default ones. The private_data field of address_space struct is used to store the pointer to driver specific ops. Currently only one ops field is defined, which is migratepage, but can be extended on need basis. The need for driver specific operations arises since some of the operations (like migratepage) may not be handled completely within shmem, so as to be effective, and would need some driver specific handling also. Specifically, i915.ko would like to participate in migratepage(). i915.ko uses shmemfs to provide swappable backing storage for its user objects, but when those objects are in use by the GPU it must pin the entire object until the GPU is idle. As a result, large chunks of memory can be arbitrarily withdrawn from page migration, resulting in premature out-of-memory due to fragmentation. However, if i915.ko can receive the migratepage() request, it can then flush the object from the GPU, remove its pin and thus enable the migration. Since Gfx allocations are one of the major consumer of system memory, its imperative to have such a mechanism to effectively deal with fragmentation. And therefore the need for such a provision for initiating driver specific actions during address space operations. Cc: Hugh Dickins Cc: linux-mm@kvack.org Signed-off-by: Sourab Gupta Signed-off-by: Akash Goel --- include/linux/shmem_fs.h | 17 +++++++++++++++++ mm/shmem.c | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 4d4780c..6cfa76a 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -34,11 +34,28 @@ struct shmem_sb_info { struct mempolicy *mpol; /* default memory policy for mappings */ }; +struct shmem_dev_info { + void *dev_private_data; + int (*dev_migratepage)(struct address_space *mapping, + struct page *newpage, struct page *page, + enum migrate_mode mode, void *dev_priv_data); +}; + static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) { return container_of(inode, struct shmem_inode_info, vfs_inode); } +static inline int shmem_set_device_ops(struct address_space *mapping, + struct shmem_dev_info *info) +{ + if (mapping->private_data != NULL) + return -EEXIST; + + mapping->private_data = info; + return 0; +} + /* * Functions in mm/shmem.c called directly from elsewhere: */ diff --git a/mm/shmem.c b/mm/shmem.c index 440e2a7..f8625c4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -952,6 +952,21 @@ redirty: return 0; } +#ifdef CONFIG_MIGRATION +static int shmem_migratepage(struct address_space *mapping, + struct page *newpage, struct page *page, + enum migrate_mode mode) +{ + struct shmem_dev_info *dev_info = mapping->private_data; + + if (dev_info && dev_info->dev_migratepage) + return dev_info->dev_migratepage(mapping, newpage, page, + mode, dev_info->dev_private_data); + + return migrate_page(mapping, newpage, page, mode); +} +#endif + #ifdef CONFIG_NUMA #ifdef CONFIG_TMPFS static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) @@ -3168,7 +3183,7 @@ static const struct address_space_operations shmem_aops = { .write_end = shmem_write_end, #endif #ifdef CONFIG_MIGRATION - .migratepage = migrate_page, + .migratepage = shmem_migratepage, #endif .error_remove_page = generic_error_remove_page, };