Received: by 10.192.165.156 with SMTP id m28csp211287imm; Tue, 17 Apr 2018 08:55:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/E1CwFlO1gr1HhU7N6PEN0LjCx0razeyX42LHxx0ZWvyx0rfs/fIxDbjDjBtAr56YGQ2jE X-Received: by 10.99.0.200 with SMTP id 191mr2226711pga.33.1523980505289; Tue, 17 Apr 2018 08:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523980505; cv=none; d=google.com; s=arc-20160816; b=nVcf8/y64VwpD21WAISGNvSMOBajd6YRInX/yzsjS8KLx8uV7Q3wJlmMVhkWMSHz3F rp4XJylELlaYmaISC6Alm6yPiACdE5M7P4+2WcqVANyO3Uf5URcN6evC73PWtHi3xJK5 fVC3JKYjRWx7FbyVF/WBCza9GBISLXNTNJzgr1PSqOztG+9nF51EWVjSWGtok0NmmFSl k2YJkQS9Cp9hT9f+A0GI2Bsa5QFuQWOccR8oLFSWGH/0OloURzWxiOMxFDfv+utAgcp7 6iroXk9UFDGVSbKNegUUtci7xpiRjihA0ymxb4pb/pRWnvHXNf6GTAmkMlbAJ4S850S/ h9nQ== 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=F0s+zLtSSHKeHGq0lrl3Y8ms1sjMhHkEZNj3JtB8k8A=; b=f5En46pA4Hrq/HwnMcTkheJpq0QhcHQFrjxRc+ls/hoei9ywSOItG4P1eFRKbRqXnS efMS6R+2idOInJTNDTYix0X9VGSqH4M7B3vpEWtWmUH+W7tXgexXHK1gnZXm7iCSb/Xd bIF24tAttFPmoxewMeCddzJjlZlzKDu6nEyl0Vj1exzd21WuaNWKC2xr6jQrcxlVeAfn nRFIh3ohmOiC4K6y1V3EXNlCmCZYQF4ZZS8oSHqf60yMmRYD/uTlNt1KPTsEpIYp/3bg r2GaPUTAjQsbTIjqnu1FeLvDi2Kbf5Zglm6xtLlDv+2z1jKyYSTH4SDBoLAet0xXPHFV c8AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=flTp3kG9; 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 c1si11697090pgp.557.2018.04.17.08.54.51; Tue, 17 Apr 2018 08:55:05 -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=flTp3kG9; 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 S1753089AbeDQPxT (ORCPT + 99 others); Tue, 17 Apr 2018 11:53:19 -0400 Received: from mail-db5eur01on0103.outbound.protection.outlook.com ([104.47.2.103]:39072 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753046AbeDQPxP (ORCPT ); Tue, 17 Apr 2018 11:53:15 -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=F0s+zLtSSHKeHGq0lrl3Y8ms1sjMhHkEZNj3JtB8k8A=; b=flTp3kG9mzstH7ZOd8MbWdP+D28YE/WwoiPvFKF6WfdQVToTqjB6Tdm2K7iq2xREesh4Os9gCNUALq6OZD5RH0B3LCc3/UaW3JO4nTmYecz2uqpxs7HW68Wx5HeByFGoGjl2aAJKFDuKgWRK96u4YWVR7NRsUMXbFXejqehla4U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by HE1PR0801MB1338.eurprd08.prod.outlook.com (2603:10a6:3:39::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.14; Tue, 17 Apr 2018 15:53:11 +0000 Subject: [PATCH v2 01/12] 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, hillf.zj@alibaba-inc.com, 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: Tue, 17 Apr 2018 21:53:02 +0300 Message-ID: <152399118252.3456.17590357803686895373.stgit@localhost.localdomain> In-Reply-To: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> References: <152397794111.3456.1281420602140818725.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: HE1PR07CA0008.eurprd07.prod.outlook.com (2603:10a6:7:67::18) To HE1PR0801MB1338.eurprd08.prod.outlook.com (2603:10a6:3:39::28) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:HE1PR0801MB1338; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1338;3:DDXfIUNEY2IcfgeD6nu//v73O6GXcbcDy6lAPpdRPgYFytATEsaZxhGaJOt1GJtNfh6j5vwMLnvrsB+x8KeW/SbxxMTHxhaan/EpU7U1do6Yt2Hq5o/hEMXyovKfy6q1lKH4xd+RXvf4oOJa52N7ETAXuvZGO0IZjZmJhLmnwgHDQbmOmNsjTdaTegwumtXJxWjHsHMr/B4IR0ZRqiXVT1ACLc8i42vE7sl6EXbZeNzSdUSgBJP01acM0slx9B2o;25:F90IOyjhNeQQAk1yHOaOvG1evrZ1fMrL17vxXjRh7E196ouD4y3yWLeBe+jJdtN8KFuIfckd+Q1oOpxzkJU74x3omiXSFGCRUOvBlSv4lJGterABLE9XtpRy+N5I4dNYqxdlt2Fn8WH2vxPHy8NE57jpZ/NtzRczXCSGBzcugqZZEnifank8SxQpUbVEoOZb9YBaUvhMQX5biR7qnyhRUWbWuiMpCmKO8LOjdQHWamUAb4An6XAxtcSacROp1Onm5Fbn3ANLDQuwrVzlQiXbtW4K91+CY26X8pqu1BZK3R8EpwqVI9s+WYkzUJbRt+7wJ4i+NGsGqg+o4r49Rox0Ww==;31:FRRLKg2BoiznfbeGBA8QV15YfRYjiQlv2MLqw6tgbWy6CMRjb7jutBS0sDuMqKR8m2y//ohl7Tp8alqVpXHnagN0l9Mk5u+PmqFKcAIqVIZigkIFCuPCxJXDWDo1ydxXa1a3RHkhJUxAX+uzdz+mmSJlDHR4DRbSfjsUnnng7zhe6dEk9AnA11lScFp1xoyQz1qSbVBjtuGV+OwPNSVemizYBqGhY/JSFWorP2HkM84= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1338: X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1338;20:KzUCNKnDiBpWR+R/4j/tbB1bQxr2pjHAWMcXeFUFa1xDOAVwYwYe0s7qq58bS9Lsy9J5vxmfJqBTRm3xbwI0EgZIZIEWP2wpkFP4c0xNckpsGmmLIGJ06QBRx77SQywN45vXfJiOgXoUhD5fv9LzPK1jL3EfFKoPopslQIwRFh+wG49nEML5zrVMFFt9CoOLLDQg8g9SsewiuRiG5oYvllKEecgZYZqgiqnOL6sfP8aLjZ8YJpR5nvBKf8V0GuIlrbL5/VnnRYyxXLK47I0oVDwZ4RV35Fh4Jk9Quu489EmIs3wm2XhrJPgG/VHpJhT2mGYU695+ZvUHzaza+AVUAZtyhyQYxAYLsuA5Ttpj+aMA5l4Pu5tpVKZBQEGlwfmbki7mC9TdDV90siapePg6miwwuK+8Lk6u9zElkqS33IgwMR8giWipe8oO1w8X9MgZT1mTPhDb3iyQx9TMDCUs4R5q2ue5Ggrr84mEbn2PRMOahRuWkVA5iObfD3ewMjrq;4:ocq99RhlezZPN3jh6h2j3uC+H+65g0S209hep9Y5Ooiyp5Am8F7Jsof4ytNlzwaT8pICnx6DCgMtISLaHXtV6K+BzP6bUlk7U5ef00ptPQAHcjTF/v2n48d1pbCYHAEbg61FWJVcV8YeUg7+lm4JGZolKHjhAKxOoQj4G0p4CTiKT+HUJ2G/cPfqIJJgdBkYTM04LGCnJ032I7lxpPaP70l4x/AWBnUXcQkfU0E7xGQ7j+tgkFkISbZHxh7Wy3dHCEO3DHvzzoqP6np1xmP7eg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231232)(944501327)(52105095)(10201501046)(6041310)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:HE1PR0801MB1338;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1338; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(376002)(366004)(396003)(346002)(39380400002)(39850400004)(199004)(189003)(47776003)(6636002)(7696005)(52116002)(23676004)(55236004)(7736002)(68736007)(7416002)(53936002)(2486003)(33896004)(76176011)(386003)(6666003)(59450400001)(6506007)(316002)(66066001)(305945005)(3846002)(478600001)(230700001)(86362001)(6116002)(25786009)(5660300001)(8676002)(55016002)(61506002)(16526019)(26005)(186003)(103116003)(97736004)(106356001)(105586002)(39060400002)(476003)(11346002)(58126008)(8936002)(486006)(9686003)(81156014)(2906002)(446003)(956004)(81166006)(50466002)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB1338;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?MTtIRTFQUjA4MDFNQjEzMzg7MjM6ODNWYVF6OTlPN2xpVFBFMXY3UEtSQkVT?= =?utf-8?B?NUV5aHh4NE9ZeisvK2R3NGZyMnRmQlFQM1Ezc2xETklIOXo1Y2NyN29TRW9r?= =?utf-8?B?bWZ6dkV1SXdBNlBZNUFWdnljTFBsd1dHMnNob2ZpSG5kaFpNMVdjWEtVRnIz?= =?utf-8?B?UFhDb3poZE5PUk9HekNvM1ViYXJucVpPTy83bTIzY0Vzak9RRTEzV2hYTlZq?= =?utf-8?B?d1dmc2s4aHczazEvaUM0QzBoUEE1R1Nma3RKZ1dmMVB2aTZrVFoyR3lScEF0?= =?utf-8?B?SUFtL01ldy9jNFhnNFljOHBoUE1uMStBVDgrUFpIYUhmM1dvMlYvQUVoazlB?= =?utf-8?B?dnByaGEyUXhCaGlEd240cENRaFJHWHVvRW5ZWG9ObFRSZVQzUExwcmZ5TDYr?= =?utf-8?B?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cefiCCXM8Los8TmWGj6qxqp32a6I= X-MS-Office365-Filtering-Correlation-Id: 83adc6fb-d1c8-4b46-3eb3-08d5a47b52f0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 15:53:11.3139 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83adc6fb-d1c8-4b46-3eb3-08d5a47b52f0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1338 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. Signed-off-by: Kirill Tkhai --- include/linux/shrinker.h | 2 ++ mm/vmscan.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index a3894918a436..86b651fa2846 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -66,6 +66,8 @@ struct shrinker { /* These are for internal use */ struct list_head list; + /* ID in shrinkers_id_idr */ + int id; /* objs pending delete, per node */ atomic_long_t *nr_deferred; }; diff --git a/mm/vmscan.c b/mm/vmscan.c index 8b920ce3ae02..4f02fe83537e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -169,6 +169,43 @@ unsigned long vm_total_pages; static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); +#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) +static DEFINE_IDR(shrinkers_id_idr); + +static int add_memcg_shrinker(struct shrinker *shrinker) +{ + int id, ret; + + down_write(&shrinker_rwsem); + ret = id = idr_alloc(&shrinkers_id_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; + + down_write(&shrinker_rwsem); + idr_remove(&shrinkers_id_idr, id); + up_write(&shrinker_rwsem); +} +#else /* CONFIG_MEMCG && !CONFIG_SLOB */ +static int add_memcg_shrinker(struct shrinker *shrinker) +{ + return 0; +} + +static void del_memcg_shrinker(struct shrinker *shrinker) +{ +} +#endif /* CONFIG_MEMCG && !CONFIG_SLOB */ + #ifdef CONFIG_MEMCG static bool global_reclaim(struct scan_control *sc) { @@ -306,6 +343,7 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone int register_shrinker(struct shrinker *shrinker) { size_t size = sizeof(*shrinker->nr_deferred); + int ret; if (shrinker->flags & SHRINKER_NUMA_AWARE) size *= nr_node_ids; @@ -314,10 +352,21 @@ int register_shrinker(struct shrinker *shrinker) if (!shrinker->nr_deferred) return -ENOMEM; + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { + ret = add_memcg_shrinker(shrinker); + if (ret) + goto free_deferred; + } + down_write(&shrinker_rwsem); list_add_tail(&shrinker->list, &shrinker_list); up_write(&shrinker_rwsem); return 0; + +free_deferred: + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; + return -ENOMEM; } EXPORT_SYMBOL(register_shrinker); @@ -328,6 +377,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);