Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754266AbdDLMtv (ORCPT ); Wed, 12 Apr 2017 08:49:51 -0400 Received: from mail-eopbgr00101.outbound.protection.outlook.com ([40.107.0.101]:44640 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754194AbdDLMtn (ORCPT ); Wed, 12 Apr 2017 08:49:43 -0400 Authentication-Results: linux-foundation.org; dkim=none (message not signed) header.d=none;linux-foundation.org; dmarc=none action=none header.from=virtuozzo.com; From: Andrey Ryabinin To: Andrew Morton CC: , Andrey Ryabinin , , , , , , , , , , , , , Subject: [PATCH v2 5/5] mm/vmalloc: Don't spawn workers if somebody already purging Date: Wed, 12 Apr 2017 15:49:05 +0300 Message-ID: <20170412124905.25443-6-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170412124905.25443-1-aryabinin@virtuozzo.com> References: <20170330102719.13119-1-aryabinin@virtuozzo.com> <20170412124905.25443-1-aryabinin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0601CA0026.eurprd06.prod.outlook.com (10.166.117.36) To VI1PR0801MB2734.eurprd08.prod.outlook.com (10.166.198.27) X-MS-Office365-Filtering-Correlation-Id: 0a34a20c-451b-49c1-ff12-08d481a25cd1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:VI1PR0801MB2734; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2734;3:q/sUbgUTEWPvEhnk+Jktxe9NDMnmncZ2tsILU3aTXkIzP+61/LFxIvDvC08MN6Mguj2WI4jbPRSOzeSt3G+kRDzSOHVL3ApMWIuoIYClSuFGyH+eifM4jths0fMJinul0m77ni6wHmCXNyoaWLXcQNu6Isp7q27JX2bMynTRqVEounuS1294uB+eIj5/BPUNzk2HRn767Sr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Df5me3ZuZTPR2gSlSE3AluTgEt+jEpdInQy7N+Q3vdl6cF5kWQCH/bAUScWWLkyQ0m3BdSVwNow3YLysNX2ixqdwYiVlbyPAq4UjlB8fLqDKHoiUJKISKn7crja/UBPMR6AIWVo9yHg89OK98H7szgzs641zdolDdwunPObSorMm1Q07LAu6JTWns92MohNxr5V6qDd5LfKgODeqKdScXbV+30i8eMQJceNCrikSouWY3DrbKQi1gjxzsL0mvWNFY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(20161123562025)(20161123564025)(6072148);SRVR:VI1PR0801MB2734;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB2734; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2734;4:U9FkAvtfepn+9nAe41kkos1/HXr8cA7UAVgWUoL019TjzfuxD8Dd0CsBiJKhQSBmoaZkln4I09FRLnCEpyjFLnQSK+CkI0HTxk0IeTIt+Pdl37lQqwDTTLtL4bRqYtBe2dXiY1b6nfEVQEspApMTLYrTGQvbd75grw7bPdyuMTid6TEhmpY9pNeM9oOIv7TuDuda8YWiUeSY8lfyNM+aBng5JQ86U5P2mrJ99fu8mFV0BrZYBjV94b34AAZX8rVqRbELed/KGl0TtVth25G4d2lm2YWIjvpcGXAcTbWJ+V9PzZS1mRwumeHfMCttbLq5tip7w4rPw0UptY4xrPf0qdYY6+t+D/KXW3wV2aE98N1W6igAqsWVO83fOJFntLQEuFAcE3ApZTRSr/NvT9YEs+M59C8TFwnkTje4ft7D+W+dhE664PVQvlV7sbbOXLkEkNnEjdKGpSFN7/O77qapWRgX1HbJXSUuRuQYUooy8a8joh28hwl9/P87Rdt8qFbXtEBvZ6nyoRrXbQQy4f2ZQqmPdTe20PzMCbb9wVJmMNI/BV3RKr/X1pI0KZizrLM18AeZMpSSFt1pp6O7aVdJEZbS2mLvAZji4W1810tnCmvtijP4Yf56d+7eloiGBLZS8eyz1hX4Ie8ZgNa+GB76TszGW7Pgz+B4KBHFDsQsIVv6VZgVJWJsD0qx3aYAbyFuWK4ZYGkYmdq/4yh1uWjba1kADd1UQCafOu6zE/jRKN8+sGXCV6btd1/OE42WIeNhXGVFZylA4epfqCZyMiys9A== X-Forefront-PRVS: 027578BB13 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(39400400002)(39410400002)(39830400002)(39450400003)(51234002)(42186005)(25786009)(53416004)(3846002)(33646002)(6116002)(76506005)(305945005)(50466002)(53936002)(4326008)(575784001)(86362001)(8676002)(5003940100001)(38730400002)(2950100002)(1076002)(6916009)(2906002)(50226002)(189998001)(110136004)(48376002)(6666003)(6486002)(5660300001)(6512007)(36756003)(54906002)(6506006)(7416002)(81166006)(50986999)(76176999)(7736002)(47776003)(66066001);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB2734;H:localhost.sw.ru;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0801MB2734;23:uoTM5wTg7qixGsn08SS/ZSamF3va33zDhil9r/a?= =?us-ascii?Q?g1P4o4s8fNcMpyk8vCgbwnDobkPL+cTLO/EAHrc1DB7l/Dr/DjyqMx8VDO+X?= =?us-ascii?Q?BHFDi4mA1pXxzWNJUVNZDX3492twIEs5u6ij9qe9MKN5UA5iGeugY+YuogEg?= =?us-ascii?Q?HRhgEiU2X5YczK/b0wKwOYWZEx4wxDNCPedwYyNyuzLj/PN+oHoTNdj/sEyQ?= =?us-ascii?Q?Tkqsh1iUOo1R+JPBd6hYlGHWJBIrEcmp+C7ZxMSRlrV5CLvtfTXzkorjGuQR?= =?us-ascii?Q?xnWJFjucWigIYwrU34ji6LYIR2FmFobHIwr/MZ/62vR7V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s1crDoMyR0TsoRkJBflUYjNOV+EY1hdzMEkJTga/8jfIGcxdaXxg0/rlUR1dA==;20:q4CWSnYO9txVuSJbYeJZgUpCkKk3TtSosC/8A098W6mRg98G4BeGFEWb4Gf96fb6ReRfhVruSobsy03rT6BmhLwtW552PQ/Wc5pFzkKJvJ9K7PGGVYyg8Ky4E6Y1aFIDWU+rE5xhilK8Abz2SItsDFdYU3dfzeoR8urBhSPGZ5g= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2017 12:49:29.2251 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2734 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1964 Lines: 55 Don't schedule purge_vmap_work if mutex_is_locked(&vmap_purge_lock), as this means that purging is already running in another thread. There is no point to schedule extra purge_vmap_work if somebody is already purging for us, because that extra work will not do anything useful. To evaluate performance impact of this change test that calls fork() 100 000 times on the kernel with enabled CONFIG_VMAP_STACK=y and NR_CACHED_STACK changed to 0 (so that each fork()/exit() executes vmalloc()/vfree() call) was used. Commands: ~ # grep try_purge /proc/kallsyms ffffffff811d0dd0 t try_purge_vmap_area_lazy ~ # perf stat --repeat 10 -ae workqueue:workqueue_queue_work \ --filter 'function == 0xffffffff811d0dd0' ./fork gave me the following results: before: 30 workqueue:workqueue_queue_work ( +- 1.31% ) 1.613231060 seconds time elapsed ( +- 0.38% ) after: 15 workqueue:workqueue_queue_work ( +- 0.88% ) 1.615368474 seconds time elapsed ( +- 0.41% ) So there is no measurable difference on the performance of the test itself, but without the optimization we queue twice more jobs. This should save kworkers from doing some useless job. Signed-off-by: Andrey Ryabinin Suggested-by: Thomas Hellstrom Reviewed-by: Thomas Hellstrom --- mm/vmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ee62c0a..1079555 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -737,7 +737,8 @@ static void free_vmap_area_noflush(struct vmap_area *va) /* After this point, we may free va at any time */ llist_add(&va->purge_list, &vmap_purge_list); - if (unlikely(nr_lazy > lazy_max_pages())) + if (unlikely(nr_lazy > lazy_max_pages()) && + !mutex_is_locked(&vmap_purge_lock)) schedule_work(&purge_vmap_work); } -- 2.10.2