Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932786AbdHVM3L (ORCPT ); Tue, 22 Aug 2017 08:29:11 -0400 Received: from mail-he1eur01on0117.outbound.protection.outlook.com ([104.47.0.117]:38592 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932427AbdHVM3J (ORCPT ); Tue, 22 Aug 2017 08:29:09 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Subject: [PATCH 0/3] Make count list_lru_one::nr_items lockless From: Kirill Tkhai To: apolyakov@beget.ru, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ktkhai@virtuozzo.com, vdavydov.dev@gmail.com, aryabinin@virtuozzo.com, akpm@linux-foundation.org Date: Tue, 22 Aug 2017 15:29:08 +0300 Message-ID: <150340381428.3845.6099251634440472539.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR0601CA0039.eurprd06.prod.outlook.com (2603:10a6:203:68::25) To DB6PR0801MB1336.eurprd08.prod.outlook.com (2603:10a6:4:b::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76e73a9f-5d56-4803-1faa-08d4e9596007 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DB6PR0801MB1336; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1336;3:Lp22h3+1CyOfxgOySs6QIJ1ix0b1l7VQL/OPaOTF+IoFru1DLbB12ZlITBDUaTozQ0Ziwu0yUwIwndFyxcSJ1T+1NPYd28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AItaa9TbJ28W1HrXTkn3552bJQSkvSZ5oxY5ONEQDkBJMYjeSCMAZA1quXp/tV2pYLal5cZoh0O885xfsDv/gKCPXPri3+16kuSqUnGL6KK3hoMnasehJ1t1kMtC2Hk7nbl8WORhV40V4rdyX5w3GRSwcxoaOP7zUr+xWMQ=;4:Ry3ww8aBG04fPyJmt2bNX94REp8HaJH7BWfJ2szebVhEbtp5zN8wGm1gT3uelyeDpmyfHTorbMaYOnw7Y2S6Vghd9DLuw75qRj0FeLdiEver0muF5wAIVBoeSizQfTLQlXVelITswPDyilWrDWncrCgZSdN+59p1jPHfKZ+pTS3nMbmro61lr0shV14i9j4ijlDrnBUflhrDrRdYbQYKYP1AuBvw6llnLUtczeH6QPQs02bS4Rq2thirraXO2lSbjQ68hf0SrBUdS+yj7GhtwP9bEOVpxmEmovFn9cJYd1M= X-Exchange-Antispam-Report-Test: UriScan:(190756311086443); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR0801MB1336;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR0801MB1336; X-Forefront-PRVS: 04073E895A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(7370300001)(4630300001)(6069001)(6009001)(189002)(199003)(4001350100001)(42186005)(105586002)(106356001)(68736007)(6116002)(305945005)(66066001)(86362001)(97736004)(33646002)(3846002)(47776003)(50466002)(25786009)(103116003)(230700001)(83506001)(23676002)(478600001)(110136004)(9686003)(53936002)(61506002)(81166006)(189998001)(55016002)(8676002)(81156014)(5660300001)(54356999)(101416001)(50986999)(7350300001)(6506006)(2906002)(7736002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0801MB1336;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDFNQjEzMzY7MjM6TzJwdGovajQvd0NmOHNyYTNBQXA3bFdo?= =?utf-8?B?S001dVdsbnVmODcyWXlmZkcwelNxNlJxSVJSRG9IM3lweGwra0JwWmY5b0RG?= =?utf-8?B?M1lIQVlYSmR5ZTlnbW9xcTJPVEVGemhKbkY0QnViTUdKZU16MjRDNStkKzkx?= =?utf-8?B?bUdMZFZ0RldLaFdiYmJxT3BJNzU4cHpQcWZiSmFOWDlBOG1TZlNWdWlxaVFP?= =?utf-8?B?SGNyQmZsMm13N2RVWVlieFZncWN5cjUxalB1UEdydzFwNnMrTTZJTUIxK01p?= =?utf-8?B?U1V5a2M4ekhYRElYRkJRQUtpTFVqbGdGT25UTkk1ZHZBSUtvZWNKdlVqVEY4?= =?utf-8?B?Q2U5K29yeXlJQUwzV2RTNWQ5dGVXRUtzL2l2NDRZQ1IvVVU0R3lobGVrdytu?= =?utf-8?B?ejk5YVhZMjlHN1Z1Yi9RZ1RyUUlKRW9pa2VUbHlRUkF0THc0dGQ4NWV1akxE?= =?utf-8?B?b2wwbFNWOVUwamJ5dDFlL083MzBGODBWckZJVFFrTUlWYnZVNXhXUVFMZzJG?= =?utf-8?B?RmFoZzROOC9YZHJYNEhNL21kem1iQ3FieStLVmhBcmlQZlFaemFWTTFWYkYz?= =?utf-8?B?a3lWZllPSGtKWmlTWjRnMG8wZVpvV0dNSTk5RjJZZk5RSlRMWUU3eWJRZlZX?= =?utf-8?B?WGtDd214N01OQk1xWWdxZGVNRFc4NzdZVXBLQXIzZW56WFhZdjR4ZnVYNmRa?= =?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/BLQTBvIszzSst8lTFjVVtCTaDJkO5q11DnRYoiP7rjWvt7Z5dbxwEgQt0liLDUpzkgGZpOqXP9mjvva5qEIVszJZFq6bV73rdUeSuZ4hDOm6MvbPu61dSF0ejo/eLpx28MBqtMzNcJJL8oGuSo7jj/8JETDea4W5erm6iorRGw80a1ovXcMjk7weBX/k35pGDpowsK+eUzMHjg==;5:luShGir9BXE+cqXBP3TvFgO1yBhWuF43pgI59idsxecUuiyZLUHXEjy2nqb1mwk1CZs8Pz/Q1qjYCmCbJoXmPoPV9UquvRwmSqzo7cAVHcapjTTXXhl3NXEtnsCnLRTdwi0hjqiucNIwAd8RD6VPHQ==;24:UcNo6wJplQSEa6x+rYTlawYw4j5wdnUZImITgq5sx1EbOZOY68BsHe9ljO4trY5V8DIzgI1a7GbGxtRe/baBLvJuk5ms1m9jtJD156YnxFg=;7:kHe2SYsf9+8JiP1yE4hTF8uscYaFsuy7+HC7d+++/mGYbnPZNumIOO7hvfYqTOrvnb3QEyxteRdUqxYiTwdCMsRVooToWu/HHRqzGU6+s5BofD3gO6XTXBcJc2v4Xb2FNHnHNIxyiDyZyl0OKjc8DaIhIdSL5IGq3/0zDaQ9gozB5XKshEbB5oVVTR57PUo0wOBAH/hP0a7RImd2J+zXtoeJuYBLTcGSoqCwzZshV4s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1336;20:uDH4RiD1kD7KlU5yFulbVCZuS5BJXrey+peS4wTn7CeXIndFUtznQw+zE9D+oOWZYvFWmSRCXDrEJ1JbYjmsdBiSjSNk4h2CZtUDMqDNvK5e3graqw29Eec9Xx75RWaCNUszzKjNBWQXTSTqvH6dnqC3w3dXcNlxnav7Dc/iT4o= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2017 12:29:03.2138 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1336 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1930 Lines: 41 This series aims to improve scalability of list_lru shrinking and to make list_lru_count_one() working more effective. On RHEL7 3.10 kernel I observe high system time usage and time spent in super_cache_count() during slab shrinking: 0,94% mysqld [kernel.vmlinux] [k] _raw_spin_lock [k] _raw_spin_lock 0,57% mysqld [kernel.vmlinux] [k] shrink_slab [k] shrink_slab 0,51% mysqld [kernel.vmlinux] [k] super_cache_count [k] super_cache_count 0,32% mysqld [kernel.vmlinux] [k] __list_lru_count_one.isra.2 [k] _raw_spin_lock 0,32% mysqld [kernel.vmlinux] [k] list_lru_count_one [k] __list_lru_count_one.isra.2 (percentage of all node time; collected via $perf record --call-graph fp -j k -a). It's an example, how the processes traces look like. And many processes spend time in the above. There is a node with many containers (more, than 200), and (as it's usually happen) containers have no free memory (cache is actively used). Since shrink_slab() iterates all superblocks, and it happens frequently, the shrink scales badly, and node spends in sys more than 90% of time. The patchset makes list_lru_count_one() lockless via RCU technics. Patch [1/3] adds a new rcu field to struct list_lru_memcg and makes functions account its size during allocations. Patch [2/3] makes list_lru_node::memcg_lrus RCU-protected and RCU-accessible. Patch [3/3] removes the lock and adds rcu read protection into __list_lru_count_one(). --- Kirill Tkhai (3): mm: Add rcu field to struct list_lru_memcg mm: Make list_lru_node::memcg_lrus RCU protected mm: Count list_lru_one::nr_items lockless include/linux/list_lru.h | 3 +- mm/list_lru.c | 77 ++++++++++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 27 deletions(-) -- Signed-off-by: Kirill Tkhai