Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754316AbdLDQNP (ORCPT ); Mon, 4 Dec 2017 11:13:15 -0500 Received: from mail-eopbgr20098.outbound.protection.outlook.com ([40.107.2.98]:45698 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752166AbdLDQNH (ORCPT ); Mon, 4 Dec 2017 11:13:07 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Subject: [PATCH 1/5] aio: Move aio_nr increment to separate function From: Kirill Tkhai To: axboe@kernel.dk, bcrl@kvack.org, viro@zeniv.linux.org.uk, tj@kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-aio@kvack.org, oleg@redhat.com, ktkhai@virtuozzo.com Date: Mon, 04 Dec 2017 19:12:59 +0300 Message-ID: <151240397905.10164.6467631934054020994.stgit@localhost.localdomain> In-Reply-To: <151240305010.10164.15584502480037205018.stgit@localhost.localdomain> References: <151240305010.10164.15584502480037205018.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: HE1PR07CA0017.eurprd07.prod.outlook.com (2603:10a6:7:67::27) To VI1PR0801MB1341.eurprd08.prod.outlook.com (2603:10a6:800:3a::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 602512f5-6830-418d-ce89-08d53b31e5c9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603286);SRVR:VI1PR0801MB1341; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1341;3:UwBcOPa6N4tm9hmGFQnf4sNwZGXPc9WCKBHh2/xCWRTGZmpFjAotpEdowccHwtKbHBXqIkm0cfFBi+C8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zmcbW34yKnAYr/93M5e459oDKVsm6jvQtj39a4bUWn7ETvsQbbmqI/9TJ2f/7NXNDGwn53gGtOe0Ar7R1KzyOc/d0mI25mOeUOtppUK3Ln+x0k4hBoTSFX8dw1ulz3QYDyjwr/rDZEas3ofrm7nqSC7Sd+YmPmxOEbp/JoQ1BYK6O6Cyt0rU5pwIYeyEM8=;4:HEZVBc90LL2ZVUgd8hGA9FKuVsYl7MfJHhvy1YKg6k7SLem1PbiutZ87tUUwN3x1kPNMANw1nVnoyxJTf6xCfTw9VvXrfG1jX8t+LS4l02LW4fQ1SDuPeLx/oz5XySdLMyMYNInzALLTVcNQlT9ZBUEHCNd+WCFekR3TTyqElIkOs7ru/awlrSpsfCECsl+4+ZUHXWgIPaSaFxbuc6heWoAszB6Z0c6WRj42oVfkbORwfP9YwmtAX/XnqY9HoX22qxrn1pqcLhrWxtX5CTV1xg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231022)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123564025)(20161123562025)(20161123560025)(20161123555025)(6072148)(201708071742011);SRVR:VI1PR0801MB1341;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:VI1PR0801MB1341; X-Forefront-PRVS: 051158ECBB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(6009001)(366004)(346002)(376002)(199003)(189002)(230700001)(7696005)(2906002)(6116002)(3846002)(25786009)(68736007)(16526018)(478600001)(9686003)(316002)(55016002)(6506006)(50466002)(33646002)(61506002)(103116003)(8936002)(189998001)(58126008)(105586002)(53936002)(54356011)(81156014)(5660300001)(47776003)(81166006)(106356001)(8676002)(23676004)(97736004)(305945005)(66066001)(101416001)(83506002)(6666003)(7736002)(52116002)(86362001)(2950100002)(55236003)(76176011)(2486003);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1341;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA4MDFNQjEzNDE7MjM6QmFjTFZaRllFdzdJbFBDMDNySTRWaWFF?= =?utf-8?B?aDBmQWNvNWNvQkVIczdJMU5zY1VsaUwyZmhLaVMreGNmSURya1JkZHV2anpS?= =?utf-8?B?azNWMU5oazJYeHJEbXBWdEo3TlJFYWI4bWFaTmoweExBdUdTRElaUDVZMTVa?= =?utf-8?B?SmtvMDZOczdZWlhZWXJTVmRZWnhRNWRGcXppYkU1b2FSRU1kVXpLZDhBWHRp?= =?utf-8?B?YVlGZCtnN3BWNC82R0IxWXpHd2J1bU5MbHVBQlZwVkhtRkN6T0JRUk5BZG5O?= =?utf-8?B?dG5KWC90SS9pUktMSjRwYnhJRitDRHNNbUlqenJTTXVPUStzSWx0bUhFZTQw?= =?utf-8?B?bGdmSDlMaEVibnMwLzJmcnNSSk5EUzhhcjVhVnFqMm9KbDhYeDF4a2txbCtQ?= =?utf-8?B?Nmp3UXdZUk5JQXlEUTA1aGZUUkg0QTBlUFdEaXZKc2w5enhRcEJGdlJpZW00?= =?utf-8?B?SjlCMGVvY2RNZkxhV3Y4Y3V5SzRKRktNZC9YYXUrajlUaUFJSXhzeUNqTUpK?= =?utf-8?B?QkxUdVNWeFdQY01meEpJbXd6UXorVGhJdkg3VllZZndNK25ENzFPakFsQ3BN?= =?utf-8?B?RzE1U2FVVFpXYW52ZTVBdWxWd0pGL2VOb2lVOVAza1FkcDZrYUREVVNhQmNN?= =?utf-8?B?OFdUakZQcEdhdkRscVArTzIwN2FFTndMQ0RmME40aGN0cjBTMjZ2dmgzMzVl?= =?utf-8?B?Y1ZuZ2d2UkF2am83WUpmdUVJa0RVdWF5OUtqRm9jOE03bXBxNHc0WTlxaUVj?= =?utf-8?B?UXNQRlFHVWt4aDV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x1m0pIICJLypBCbBPD1dqVdUZqfCXaDaUUxo3NBlhI/OrkXrsfxNCKzNdYvCZf6A5MXck2sxIz6noisgk8JEIsUxlo85il+X6FGB23svicnIlvMWxn3w1EuOS6rTiMqoqmnQ52IV4WQRccQSXIhc90G56udGwnnftM/+KI4cPHgE7DgpcN+1hft8AimI7sZxWPUU6NygoTwfsp7YOvy4b1Ypgx//11i4tuPvcgXuYU2Wv5QyeQBO0EIZkVoCbac6vQfAfdteoJ2rCc4qQZpsN2pX7puFj5lCB+u4IBi4s93x8d9rU3jMLGCelmT5I0wKQzt3E=;5:jE7JW+jfGLOveiavxfLAhxC2992JKK/IqfULTBQ1/FogQ8HG9bMaBbd+m/71qzqrIBXIax7lpboiNsXBIWzEon2DQseyCtAeOTh7pL+/YFHx19CoQcrROdZXHG4rTxZScH6WQ/PMXg+6FsT6I/I1/WtE0de6nVVxWjm4usdmMGo=;24:nJ/3bLWjjS1Fm/0F+cnEyhnHBrwmYMXXPpCjgRGFN69j7tOXHArvE2/gTblCSn2RwXKlm6Gt/wAf/oQoxPuiFHl5+yJE6nvUXam/05wroko=;7:zdkbP91OCR2YCR6I0/7GX0d7y3f71lzLWAbnrxNvX9E//ihGP6l88MrMTSiWcWnyNJZJQw4GWTyhTaZHDTm1JHDJtnPKZFzgD6wfQqitXWAYqjRkjaN20eLBJMp58umP1lIkHnth0WwbjlBHLovyPChMGnTQIuZ4NH1RAspqi3NpLTH3fMLwRpqI1BJLRSddqPnMe7PyYY+65LAhbg+igYHC5uiSzXbRKEx+MZTvJJR6xh/uws7w/lh3BW9buFz/ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1341;20:BpycC6UXecoqqAOtHX+mnOTrjysQu401346rsYzQBs+OgKjvkeyU50md12eFwb5W4T6NCU+SEl1taXm16BFXve8QiqzeeLoUZUjRwvlTeTmXLtFntd/0lC3MchLfocUGV09UcYzYav+hM4wo4o00405XO6Bx7GjJ/LRQFn9JtR0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2017 16:13:02.9781 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 602512f5-6830-418d-ce89-08d53b31e5c9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1341 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2229 Lines: 90 There is no functional changes, only a preparation for next patches. Signed-off-by: Kirill Tkhai --- fs/aio.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index e6de7715228c..04209c0561b2 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -694,13 +694,39 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm) } } -static void aio_nr_sub(unsigned nr) +static bool __try_to_charge_aio_nr(unsigned nr) +{ + if (aio_nr + nr > aio_max_nr || + aio_nr + nr < aio_nr) + return false; + + aio_nr += nr; + return true; +} + +static void __uncharge_aio_nr(unsigned nr) { - spin_lock(&aio_nr_lock); if (WARN_ON(aio_nr - nr > aio_nr)) aio_nr = 0; else aio_nr -= nr; +} + +static bool try_to_charge_aio_nr(unsigned nr) +{ + bool ret; + + spin_lock(&aio_nr_lock); + ret = __try_to_charge_aio_nr(nr); + spin_unlock(&aio_nr_lock); + + return ret; +} + +static void uncharge_aio_nr(unsigned nr) +{ + spin_lock(&aio_nr_lock); + __uncharge_aio_nr(nr); spin_unlock(&aio_nr_lock); } @@ -776,15 +802,9 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) ctx->req_batch = 1; /* limit the number of system wide aios */ - spin_lock(&aio_nr_lock); - if (aio_nr + ctx->max_reqs > aio_max_nr || - aio_nr + ctx->max_reqs < aio_nr) { - spin_unlock(&aio_nr_lock); - err = -EAGAIN; + err = -EAGAIN; + if (!try_to_charge_aio_nr(ctx->max_reqs)) goto err_ctx; - } - aio_nr += ctx->max_reqs; - spin_unlock(&aio_nr_lock); percpu_ref_get(&ctx->users); /* io_setup() will drop this ref */ percpu_ref_get(&ctx->reqs); /* free_ioctx_users() will drop this */ @@ -801,7 +821,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) return ctx; err_cleanup: - aio_nr_sub(ctx->max_reqs); + uncharge_aio_nr(ctx->max_reqs); err_ctx: atomic_set(&ctx->dead, 1); if (ctx->mmap_size) @@ -848,7 +868,7 @@ static int kill_ioctx(struct mm_struct *mm, struct kioctx *ctx, * -EAGAIN with no ioctxs actually in use (as far as userspace * could tell). */ - aio_nr_sub(ctx->max_reqs); + uncharge_aio_nr(ctx->max_reqs); if (ctx->mmap_size) vm_munmap(ctx->mmap_base, ctx->mmap_size);