Received: by 10.192.165.148 with SMTP id m20csp925651imm; Thu, 10 May 2018 02:57:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrJEmxkFU8t7ctdBIvxV/FLdOAPe8LqEHIEie+PTRlXWZ10ZXSWmzRpr/NumUtqcUYduSvf X-Received: by 2002:a17:902:a60d:: with SMTP id u13-v6mr755523plq.40.1525946223298; Thu, 10 May 2018 02:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525946223; cv=none; d=google.com; s=arc-20160816; b=WOOBlDPXJSffj/Rjr+sSTJ1GBhl9Mb47xEcWKjut1MkMefNPsD0XFsFTF/bw1xIK16 3xHjYIhkQLX6IgTZ86/CXPQbEyUKB5RBaT76qZmKKumsPjoqx3lch3oS4UUi88cXEsNl 4Lc+DKV1ENbIcp/YhY1+OtRzYek1daBaGdAAOi0uqY+oosz6DJZYdH3blf1iPT043qBd l5TO3u5kKlIyTlvn1wMMr1jiFvSgBEk3qnOE4ryWCpySSup08jQ1NhsrQDnEtcZU0ZKi 4ZcADNbyIi+OrC0NTGNUKcPsMwdyBf0tZx1Oy9Vx/vhtu3I6Guc/jJ69aM8R3DjIIP3w uKTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :dkim-signature:arc-authentication-results; bh=ZopJs9YZJ5AStz2kEP2x8LdjSK1V6Y3zwOESzDJ3U5w=; b=YjL4ilUABrV6+nzlaNVVokyzAKNiCxrwjJ7BKe+YCk1s/q7O4wpoWdK9IZ7jOIuhH0 jqV0Br2pikofKaTITBpwo3Dt5DGSfdszjDQTcWlEWl4bzvizLOhljO0k7s7PMHRYvNCK MUaR7n/9ITtYBl4k5nR83K2/yspNCZMrSqMAIt712qg3uve7pFGqt4HiFRRLNFAhd8pu KGSyevuWQjAJY7GjnPvGSzMSLaHychNKk41XL5Vd/eo7YqsZx010JviOP38TpVnwu4bN x1pd8xWqBZlBFrRWvIhvpgaOa8EhI9F6icqPltnIrToRL9SUZ8KefMVGqsdL/d2uVuKp lRdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=C0JTtU2y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3-v6si449742pld.45.2018.05.10.02.56.49; Thu, 10 May 2018 02:57:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=C0JTtU2y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934430AbeEJJwd (ORCPT + 99 others); Thu, 10 May 2018 05:52:33 -0400 Received: from mail-ve1eur01on0104.outbound.protection.outlook.com ([104.47.1.104]:58089 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934106AbeEJJw1 (ORCPT ); Thu, 10 May 2018 05:52:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ZopJs9YZJ5AStz2kEP2x8LdjSK1V6Y3zwOESzDJ3U5w=; b=C0JTtU2y4bAUVMo+q7lDV18plyFC8cS+29Ta+awDc55x0x29bT0sHqf2kHxGGLcOaXRtUDVOI3+BcZvlsLiUWO4oWOSiWar9cBJvJn84yzzOASutHAlFWMF+hN7TM5sE0LzANiG7Apk+0dg7ujf84KE+KkEruNtOGhBJjmn6Ybg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by VI1PR0801MB1342.eurprd08.prod.outlook.com (2603:10a6:800:3a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.17; Thu, 10 May 2018 09:52:20 +0000 Subject: [PATCH v5 01/13] mm: Assign id to every memcg-aware shrinker From: Kirill Tkhai To: akpm@linux-foundation.org, vdavydov.dev@gmail.com, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, ktkhai@virtuozzo.com, tglx@linutronix.de, pombredanne@nexb.com, stummala@codeaurora.org, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, guro@fb.com, mka@chromium.org, penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk, longman@redhat.com, minchan@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, lirongqing@baidu.com, aryabinin@virtuozzo.com Date: Thu, 10 May 2018 12:52:18 +0300 Message-ID: <152594593798.22949.6730606876057040426.stgit@localhost.localdomain> In-Reply-To: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> References: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR06CA0030.eurprd06.prod.outlook.com (2603:10a6:206:2::43) To VI1PR0801MB1342.eurprd08.prod.outlook.com (2603:10a6:800:3a::28) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020);SRVR:VI1PR0801MB1342; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1342;3:4ewwDEueiII8n9qLdcJYEci53/q9cj63g824EwxG/5ZyjVxVp25KQMYKqjy/PfKkYISnIgMu0Fsh/dL3vXfyyE+9txtSRO7C0meEwhV8mG0uoXq2DVQ7JL6h2kzAabRfbE4cZwARsS1ZZiEjtNMzbvlITzAhFQVVgppxZ6WnbxqjpZjPHO+2pl/OwEr6plK3pGztmTANmcV0uBeNd7Ten9XSwe7Lc6DgPqnDx08JwZSSJAsERQoznpOxu/r/TSz5;25:rbHRUTmKr9aNEF3jNoBlHfZZZHLMI+YkTF0GPcj8ZU829f4JrJu6k71hvPd/bCnlvmC80Vql7fhKexB5h16k9iUlLtf9wH+X/z/PPxx1Nxww0fJotdbeGkHeDEkeyKBn8/pLnUPxRg/wx29FkHiYuZqpEKaKN4LQVBCyR157q5Rbrj5rfZ+HPNIrygMpnJduCmBnFRVt0LDIm4anqoMsTQaYVknhNDiZLjeAUiZM17XQy2KEXuG7laANFRdLvOnb2gK7kT7euGiupfqrDKYkrLnfiCtmbyqgUuWMzJ+EIc0pBKQcKMw3rnoznE5S2RA9CzdEmVdS7ULV1WP52URPdg==;31:fwNmssnbyk7v9UR+JoWlQSasvfmiTq2tG+x/JEuwUinIqVWhA78i8Fad+MgC8fsuH50pKYm1OZjlQGCt3qiujjdAhM1GCLsxPLnUK7JJrNhAl9O9kXtkMXZcDUqF7W2hpyqTDIIc/8afRZ46KhwCvh4m03wjYTKBC8CTsojumBJMLG0n/3Sygx7Ge6xRvp1PTUheX7OejhttnbXo2yU8lZug3/s5YW1cTznw7lj4OVI= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1342: X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1342;20:49sD6X7HnD1htoTjaH0O9JW1N4JDPcfb7YMNFvAjDigSlcdP0ijT/boNfUtUaD1j2Bvb5OknTe9GVRwFbZ/MlQfzTWIB15c5B9xRiWweYSf5gwJMX6zehC4zcwXSUhc2oHxQG5ddGdCi5rhJMMKvFWZ7IGi9ZRJch/yxnASEY0WikJ/m9zgxzWs5lqECjxi35ugZNeLFVelWFUcaZ4wRFaF1JqVeQOgzjaiPXmkoT+kKrueuKUmaFIF7Pz6RHASOdRQL13yT7lQm1yRhEXeL1q+Ewq62zb9XuuxZMkt7Bm05frHSmID9rf1aKGJtNXz184dNN1Swn7VDUnlDai3Wd8SFTdQCvYB/4PdDqy5iCbt76okVnBbtHh/CA9feu8piubR2yRvSriiuxtDJKtGbz/yAFmoygNVLj7wDD8UXiun8Cm+1p/Ed4SY6za/JoEqgapS2BSzQu3vggkVJw080ByzOmzVJGQj2uXiLgZUotP3z77QIMkKtB8kfdZI58fWB;4:IQGPSMRk/MaiGT3SUlxWoFDhtbXbs22ZqmmwAjGGOfrP7l8W9OVsPET62+ZCZLhJ6jJFVFyLmkEPgwJ3tNOUg15ENn4ainveyWTiX+z5IAgOkBoSx8LBK8yhWsnlDKTbOxOknWm/wXr6Zzpbn0RB/+q84TbVWs8N5poAQ/y9VmTQRw2VC6UgJA1r7ox2KhHU6q5pxJXlRFP67H11avzZASmPlZ2PkPSoDbaoYXCEdb3XJxCA6anrX78P3vihT0/serPA7USrUqw9ziNZ58shXQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:VI1PR0801MB1342;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1342; X-Forefront-PRVS: 066898046A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(346002)(396003)(39850400004)(376002)(366004)(39380400002)(199004)(189003)(52116002)(23676004)(26005)(68736007)(186003)(2486003)(6116002)(97736004)(61506002)(86362001)(3846002)(105586002)(106356001)(16526019)(55016002)(66066001)(11346002)(446003)(25786009)(486006)(7416002)(76176011)(8936002)(305945005)(956004)(478600001)(7696005)(5660300001)(230700001)(47776003)(386003)(316002)(59450400001)(39060400002)(476003)(2906002)(55236004)(7736002)(6506007)(6636002)(58126008)(53936002)(81166006)(9686003)(8676002)(33896004)(81156014)(50466002)(103116003)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1342;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA4MDFNQjEzNDI7MjM6V0J2RVZtT0hSa2xldElKa1NYSUJudU9y?= =?utf-8?B?ai9hSGNyWXZXREp0a2dyTTBZM05aUzFLTjduaHBETjJYMXpaQ3lheFJvTWhq?= =?utf-8?B?ZW1oTE9TdEZjR2Jqb3hhaE9hc2x6aWRLMFZGZWVPSXpmbnpIWVNPeHhaKzBn?= =?utf-8?B?a0xyS2FENTNIMW5Ma3dRaERYRUNZOFhkM0xXa3A2V3ZXM05UbS9BRm4vbyt0?= =?utf-8?B?Y29lL3pVb1hQVzdjNVVRRUtCUllBMkYrL09vc0FWTlhvRDJRaWx4MnZXVEY1?= =?utf-8?B?M2lZYStsaHNOSWxHaVNQd1RXenI5UjZjd0Rxd1dDd3BFeDNwYU5iWnprMTR3?= =?utf-8?B?YjY3S2JiQ1U4TmpSdUlUSitCdEc5Q0dJYXM5TUc5a2lBWUdxd3dIR3E3ODF3?= =?utf-8?B?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RZmtTVmOXLjJw= X-MS-Office365-Filtering-Correlation-Id: fcee02ee-68a8-416a-3db4-08d5b65bb9fe X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2018 09:52:20.3706 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcee02ee-68a8-416a-3db4-08d5b65bb9fe X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1342 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch introduces shrinker::id number, which is used to enumerate memcg-aware shrinkers. The number start from 0, and the code tries to maintain it as small as possible. This will be used as to represent a memcg-aware shrinkers in memcg shrinkers map. Since all memcg-aware shrinkers are based on list_lru, which is per-memcg in case of !SLOB only, the new functionality will be under MEMCG && !SLOB ifdef (symlinked to CONFIG_MEMCG_SHRINKER). Signed-off-by: Kirill Tkhai --- fs/super.c | 3 ++ include/linux/shrinker.h | 4 +++ init/Kconfig | 5 ++++ mm/vmscan.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/fs/super.c b/fs/super.c index 122c402049a2..16c153d2f4f1 100644 --- a/fs/super.c +++ b/fs/super.c @@ -248,6 +248,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_gran = 1000000000; s->cleancache_poolid = CLEANCACHE_NO_POOL; +#ifdef CONFIG_MEMCG_SHRINKER + s->s_shrink.id = -1; +#endif s->s_shrink.seeks = DEFAULT_SEEKS; s->s_shrink.scan_objects = super_cache_scan; s->s_shrink.count_objects = super_cache_count; diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 6794490f25b2..d8f3fc833e6e 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -66,6 +66,10 @@ struct shrinker { /* These are for internal use */ struct list_head list; +#ifdef CONFIG_MEMCG_SHRINKER + /* ID in shrinker_idr */ + int id; +#endif /* objs pending delete, per node */ atomic_long_t *nr_deferred; }; diff --git a/init/Kconfig b/init/Kconfig index 1706d963766b..09e201c2ada9 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -680,6 +680,11 @@ config MEMCG_SWAP_ENABLED select this option (if, for some reason, they need to disable it then swapaccount=0 does the trick). +config MEMCG_SHRINKER + bool + depends on MEMCG && !SLOB + default y + config BLK_CGROUP bool "IO controller" depends on BLOCK diff --git a/mm/vmscan.c b/mm/vmscan.c index 10c8a38c5eef..d691beac1048 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -169,6 +169,47 @@ unsigned long vm_total_pages; static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); +#ifdef CONFIG_MEMCG_SHRINKER +static DEFINE_IDR(shrinker_idr); + +static int prealloc_memcg_shrinker(struct shrinker *shrinker) +{ + int id, ret; + + down_write(&shrinker_rwsem); + ret = id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); + if (ret < 0) + goto unlock; + shrinker->id = id; + ret = 0; +unlock: + up_write(&shrinker_rwsem); + return ret; +} + +static void del_memcg_shrinker(struct shrinker *shrinker) +{ + int id = shrinker->id; + + if (id < 0) + return; + + down_write(&shrinker_rwsem); + idr_remove(&shrinker_idr, id); + up_write(&shrinker_rwsem); + shrinker->id = -1; +} +#else /* CONFIG_MEMCG_SHRINKER */ +static int prealloc_memcg_shrinker(struct shrinker *shrinker) +{ + return 0; +} + +static void del_memcg_shrinker(struct shrinker *shrinker) +{ +} +#endif /* CONFIG_MEMCG_SHRINKER */ + #ifdef CONFIG_MEMCG static bool global_reclaim(struct scan_control *sc) { @@ -306,6 +347,7 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone int prealloc_shrinker(struct shrinker *shrinker) { size_t size = sizeof(*shrinker->nr_deferred); + int ret; if (shrinker->flags & SHRINKER_NUMA_AWARE) size *= nr_node_ids; @@ -313,11 +355,26 @@ int prealloc_shrinker(struct shrinker *shrinker) shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); if (!shrinker->nr_deferred) return -ENOMEM; + + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { + ret = prealloc_memcg_shrinker(shrinker); + if (ret) + goto free_deferred; + } + return 0; + +free_deferred: + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; + return -ENOMEM; } void free_prealloced_shrinker(struct shrinker *shrinker) { + if (shrinker->flags & SHRINKER_MEMCG_AWARE) + del_memcg_shrinker(shrinker); + kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL; } @@ -347,6 +404,8 @@ void unregister_shrinker(struct shrinker *shrinker) { if (!shrinker->nr_deferred) return; + if (shrinker->flags & SHRINKER_MEMCG_AWARE) + del_memcg_shrinker(shrinker); down_write(&shrinker_rwsem); list_del(&shrinker->list); up_write(&shrinker_rwsem);