From patchwork Thu Jan 24 11:56:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 10778807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFC101390 for ; Thu, 24 Jan 2019 11:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA9332EC18 for ; Thu, 24 Jan 2019 11:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCF2D2EB1E; Thu, 24 Jan 2019 11:57:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A7612EB1E for ; Thu, 24 Jan 2019 11:57:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AC358E0047; Thu, 24 Jan 2019 06:57:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 18BD78E0079; Thu, 24 Jan 2019 06:57:07 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F223A8E007A; Thu, 24 Jan 2019 06:57:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id 7D0C78E0047 for ; Thu, 24 Jan 2019 06:57:06 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id f22-v6so1594560lja.7 for ; Thu, 24 Jan 2019 03:57:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=Bmx4BpgKe71+rZZ26lOw3fLZEJYFgz55uetEcgrI96E=; b=gEevyryu85BRE3IWqZvwtDYjr1JfwJWzaqQ4CDoTh5TC00a3RgxLS18haRJJRT67D+ kg7zaadM1tw9/DDXZ4cb01NqlkZK072ZM24kVJpB3raTve2ZclFgZldSBeQtiuSSINNH Thwmzf+AMNK1+rDrSZjaYQAAZHkiZRXJwYqtYA3pA0bqJq2buRS3qnYiIcvBig+iFoqv Yn5e84C1L0Se5Ixh40RrgSQkGNqVZy+M8rc+XOHQ1WtsRumcoyaKF2trFQx79rrPce2r ZPHwfeAJm3ynuNqhkFhI8rQZ4agL5hHhkXYW/nsQf7CsFym1/xZdT2wwuIRXvqnofDE5 CF5w== X-Gm-Message-State: AJcUukcKFgKmdahKAoyN4WSDaxbJrIbakZpN7P9zMBupOmy5qVToXZaK zYGX3q1OuTY/iAq6mr3LWEq1UHnoQiiIqe+RPcCuXF6X4JtPniwvpYM+H/3ZovcwLQ0p37hxJUd wVHxRdLvqxXI119CXw+p82v1UVR/1RKoxh/VpeKG7eaqhzGH9Crf5yLJ4zo4kOj0/webhVYQTzx TVnRUXlxl/7fkAzDXFgJ+7TFKkhhpe/B5ZfMUc9WZBqdm2R95jRGbXVEFZvZhW/6w7oi+gPf984 VBqzUmWH/O1/4SMCec75bmWYYh7bV3Wl5DP07/rf8RH9fPe0MPKpFjQ7J4q2s35uqZyJ7mFzIej psynvTNLhV0UzjmQIawFWRCZLo5qAUDhSkpa2gvl7y9pEiSXuv2dcOM907uoScmIQTUwshJDBDO x X-Received: by 2002:a2e:7f04:: with SMTP id a4-v6mr5245682ljd.156.1548331025417; Thu, 24 Jan 2019 03:57:05 -0800 (PST) X-Received: by 2002:a2e:7f04:: with SMTP id a4-v6mr5245617ljd.156.1548331024283; Thu, 24 Jan 2019 03:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548331024; cv=none; d=google.com; s=arc-20160816; b=H95R3PY55UQCRPLif7WVI1YBREgcrnqBvzG/jd8qScqWAcf60W4TN696iOHaDNcLmS KstqKN0BYwQSPPBMUAS5nQIDy8CmO7F8pfIAXPlk1zme0vC4xxU9OTTO7hSzLjVnKBH2 KtHlxKVKs7bY0+FBac+MKljgeaE9Jta7vvBYSw1+mErgCV9bgLSNSdHaZMzMdjPOWmz9 uTFaUGbSERCyaSgZkYheRHKeK+xE5WNU8cmVgYKEM9o+3gWB1R7i2JnBpVCu/H8tc7w8 ky33E7T85actJsr9f9JowsqN6KScChrr80CRr7A0Z8KEquA6NVHyA9VRvZBDdGW2dNvA Ijuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bmx4BpgKe71+rZZ26lOw3fLZEJYFgz55uetEcgrI96E=; b=xeabm2Yy9ZRzkuKW/DCgttksf5GExv4WMBY9doh+o1Si+HMk6Le4FaYa4/NTQbRlHI 6ecOKk7NgMZ9tHcczmD1PftEQd9+XfciB3LGSioT70EWCBv7PlzR8ByRq+ZAlNZC1Twb C5hVIsgoWGcQbCXkSpLaesP1FWT51axtbiJmxvQh3E3HZCjvxOEejOFcYnUBTZXYB41O IVxj3trUGMePgETluYdsW8o0zAnhIdl4E/+7KiHDLmQ7/yGJQX/MX6fI7J8mpYRnvqdT 2e07osmbETDfo1nKxUxTj+mPPb3ILtPD6+Rw8tl6QZ3FVqjIvT0YTDZprig9281Luy3Z zFYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Gm/udZKd"; spf=pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g1-v6sor4406543ljg.10.2019.01.24.03.57.04 for (Google Transport Security); Thu, 24 Jan 2019 03:57:04 -0800 (PST) Received-SPF: pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Gm/udZKd"; spf=pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bmx4BpgKe71+rZZ26lOw3fLZEJYFgz55uetEcgrI96E=; b=Gm/udZKdWmDsapkf31oi+rV/xrSnCemE9Em+1d3nPz1T325PqUA8UYAq4tZbBsrndL QauifVztJj6FXXJ+kqfoCiP+BOIGeFgkA2ClQgXEYVjM+51aCj26rt6kI+qjmgEMj8mH 7kNRJu+XgTdpEjgsi8TquvDhssPTtjqI+6mkp0ryHr33B+38Ph7eiiuB0VoO7ilDBW6A dPxXAOlSwtMniFo02J4cswekKCffWYNCkEaE0j3gmJhRvfqBtZRVCZykn9U+oQXTT0d2 qwMJxoMY+UUyCDxldf+FQkFYc+nEGeUnLjSvGgfLbrl1nF9whzNr64O+Vo18f2Xz9MwS fH0g== X-Google-Smtp-Source: ALg8bN6UtOSdiZ6kpnXzV6MiFQ4RAnSAEkzBdbiMYt5qilFhIXuba1TyBeLy6M1MsF0orf+FsOvosA== X-Received: by 2002:a2e:b04f:: with SMTP id d15-v6mr5355706ljl.3.1548331023688; Thu, 24 Jan 2019 03:57:03 -0800 (PST) Received: from pc636.semobile.internal ([37.139.158.167]) by smtp.gmail.com with ESMTPSA id w202sm920226lff.31.2019.01.24.03.57.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 03:57:03 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: Andrew Morton , Michal Hocko , Matthew Wilcox , linux-mm@kvack.org Cc: LKML , Thomas Garnier , Oleksiy Avramchenko , Steven Rostedt , Joel Fernandes , Thomas Gleixner , Ingo Molnar , Tejun Heo , "Uladzislau Rezki (Sony)" Subject: [PATCH v1 1/2] mm/vmalloc: fix kernel BUG at mm/vmalloc.c:512! Date: Thu, 24 Jan 2019 12:56:47 +0100 Message-Id: <20190124115648.9433-2-urezki@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190124115648.9433-1-urezki@gmail.com> References: <20190124115648.9433-1-urezki@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP One of the vmalloc stress test case triggers the kernel BUG(): [60.562151] ------------[ cut here ]------------ [60.562154] kernel BUG at mm/vmalloc.c:512! [60.562206] invalid opcode: 0000 [#1] PREEMPT SMP PTI [60.562247] CPU: 0 PID: 430 Comm: vmalloc_test/0 Not tainted 4.20.0+ #161 [60.562293] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 [60.562351] RIP: 0010:alloc_vmap_area+0x36f/0x390 it can happen due to big align request resulting in overflowing of calculated address, i.e. it becomes 0 after ALIGN()'s fixup. Fix it by checking if calculated address is within vstart/vend range. Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 1c512fff8a56..fb4fb5fcee74 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -498,7 +498,11 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, } found: - if (addr + size > vend) + /* + * Check also calculated address against the vstart, + * because it can be 0 because of big align request. + */ + if (addr + size > vend || addr < vstart) goto overflow; va->va_start = addr; From patchwork Thu Jan 24 11:56:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 10778811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6C2C1390 for ; Thu, 24 Jan 2019 11:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756652EC36 for ; Thu, 24 Jan 2019 11:57:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 690902EC59; Thu, 24 Jan 2019 11:57:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEF6B2EC36 for ; Thu, 24 Jan 2019 11:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCB9C8E007C; Thu, 24 Jan 2019 06:57:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B296C8E007A; Thu, 24 Jan 2019 06:57:07 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CC298E007C; Thu, 24 Jan 2019 06:57:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by kanga.kvack.org (Postfix) with ESMTP id 29E0A8E007A for ; Thu, 24 Jan 2019 06:57:07 -0500 (EST) Received: by mail-lj1-f197.google.com with SMTP id v27-v6so1624420ljv.1 for ; Thu, 24 Jan 2019 03:57:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=LH2WfGm9JecgWZzx+vTKmh903j2Nkd/dyKUicbvBqL4=; b=TWvty3UBQe5odTeXt6almFHI8WfJCsPaKSkFHrnxg7DwH/E1f26siZ7jQvw4xK5pDQ Vd7149eZe7tVn60ezOfX8emqRAYuxqPWtTeVXG5ZYWNmzZLis1sZBIMTrTlhTODDpz5f OWCtBJ4fpI/zf67hiG+l/H8i11+STvwvsAdWlHTndz4I+Gs36NQB3aljz8Fu7DqDLOYF IbC5LEuAUWZbdUHhb3qaAX0xpqfXI1LipCa7BQi24uJKmPbZy4pDMXRUvx+JJUfXYw6g 7q8+3gqv8l2oTDCGIkMIBiZwW4Jngq74aJX5bKS5B4E8R3oAjHeyG870YFo4rCpc8012 cFPw== X-Gm-Message-State: AJcUukdtexMVhz2M33mHJV93/u9ZBc0i0kBfdt4ECszf1N+zMfiG1oto WOaRYNRifYQcTBdWoMtI8KsmIs+SmFdUeJ4Lr7zD06RxlqBI829Pk7lrO3voshoanhwFyWU/xRF F6XVdAVHxQkrb51SoV6ALJ24z8QRr3HyxnJTmhyqWjpFH83opfLOAqXX7rAm1TxBKWLZ+PYGUug ftc3fevDdna7kEw/mFIp2M4YYJItjZrgMNRIvz2xIZQOd+X9M7hMEhT9p0voyX6Gc8Y44TiqZ9Z nn2wUlMerVUkbwQtZlX09u2dzNB14esAfhykQye6+ubzCCTEr9rvmXB+8MRV0xXu9I0XGiMznuL ab3KstPJp89qJJA14/OcuJif+VjyT6YrL4Lsf3tiSpkDLxNz1qHTml86WsEYvOnC3FuB3/CP+NG 6 X-Received: by 2002:a2e:7f04:: with SMTP id a4-v6mr5245766ljd.156.1548331026542; Thu, 24 Jan 2019 03:57:06 -0800 (PST) X-Received: by 2002:a2e:7f04:: with SMTP id a4-v6mr5245679ljd.156.1548331025389; Thu, 24 Jan 2019 03:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548331025; cv=none; d=google.com; s=arc-20160816; b=YfqmHLCQ0IhnJ9eYQUy/ipsp+KjZFa/F9ACJdP3hRM7Kh7uhZecTOFmJcN57zaTVGt jCl11MzlghQFiY+rUUBlIzS96K5+uhM83xIfjRPllBICR2XhK2R2hiVo6MBb4Szqe9OR TucEMzFRPzK7gYcd7H6PyYvpuqT+guPyHA6x/bjaVW+3Ij/NhzyUhbNYt2anBPo2OxiO Kv73sD76IO7iijGHh/CV+USKwP8tQNa/iVzanBS+GV4ySl3JZjrwPg0tLsvSyInjbeZy Pg5KDq4htObFKwv1B4F5QXU8jEyAPpicCnurQRi5vcOuiEANIXXVD8lZmzzCoIfcIE7R vRUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LH2WfGm9JecgWZzx+vTKmh903j2Nkd/dyKUicbvBqL4=; b=0x4XQb/OFzDRWhctwzU79n9CpTAZGLjw34SuKBzmN9dNy/ESsMycUtUUAikwWW104j LT0yXg0VN8Dlxhim2WeFikCL1ifxtd31E/qQAiVqAPRJC1b73qMDlzJ44CizB9tEWiOd ZmAbQXUKSbKQNhkgRDR/FxvkawupLMc7PuFs2r0kjP0tj7lofehdy+JMtRH7FI8Ey+kF QaNCtv3auF+qJN7CFymBbnojJVxLeZU6l5IOQDqpF5FPnoyNHnjJwnj8oKS4WNZpaKyF 0UTRi9ooF0YrYciSXS+DOAZpub6pvIr9m8C3RPhi1a/uybuxrEGTMo31UtNuKC5jJ1PK rvWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=otCEUxy9; spf=pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c13sor1923695lfi.10.2019.01.24.03.57.05 for (Google Transport Security); Thu, 24 Jan 2019 03:57:05 -0800 (PST) Received-SPF: pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=otCEUxy9; spf=pass (google.com: domain of urezki@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LH2WfGm9JecgWZzx+vTKmh903j2Nkd/dyKUicbvBqL4=; b=otCEUxy9/8LsDspYMLhrFYV4Mt3MDXaRGgPVnH3raQohrhx3IENSURFXhFQYXzsedz F4TmLxi9rxVeDu/K5mpRe8tNOBqwW8/6DW+raTEvmAFy7JbwWK3yRgLNxgAoAOd0FHUm bcVS1WGX45Lcog/DowgR6A3GWH+Gwcaqv7DRM1arVX9Qx7UV6yAaHTWg8BwBLAqLTa4L v9WHSo3jdFFj5HAV+vhUWLeL1L0oKOYodltmV+WWkjeOYwX90wwLc5AxpiP/IzMuWLt/ okbN9C5tHA7QCOtBkHtA0+7N6IBrwXy+ImLXQDRTHirzyTzuG9ZtF/8/bfru/NNQ/O37 f7bw== X-Google-Smtp-Source: ALg8bN5XmuZZCNstoL7umSLMjPTwUb4qtjoHCuVnAOMRQy7Zp/qTmcBmfwsBuyULKrL8NZgyTKdbdg== X-Received: by 2002:a19:2106:: with SMTP id h6mr4947446lfh.29.1548331024917; Thu, 24 Jan 2019 03:57:04 -0800 (PST) Received: from pc636.semobile.internal ([37.139.158.167]) by smtp.gmail.com with ESMTPSA id w202sm920226lff.31.2019.01.24.03.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 03:57:04 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: Andrew Morton , Michal Hocko , Matthew Wilcox , linux-mm@kvack.org Cc: LKML , Thomas Garnier , Oleksiy Avramchenko , Steven Rostedt , Joel Fernandes , Thomas Gleixner , Ingo Molnar , Tejun Heo , "Uladzislau Rezki (Sony)" Subject: [PATCH v1 2/2] mm: add priority threshold to __purge_vmap_area_lazy() Date: Thu, 24 Jan 2019 12:56:48 +0100 Message-Id: <20190124115648.9433-3-urezki@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190124115648.9433-1-urezki@gmail.com> References: <20190124115648.9433-1-urezki@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP commit 763b218ddfaf ("mm: add preempt points into __purge_vmap_area_lazy()") introduced some preempt points, one of those is making an allocation more prioritized over lazy free of vmap areas. Prioritizing an allocation over freeing does not work well all the time, i.e. it should be rather a compromise. 1) Number of lazy pages directly influence on busy list length thus on operations like: allocation, lookup, unmap, remove, etc. 2) Under heavy stress of vmalloc subsystem i run into a situation when memory usage gets increased hitting out_of_memory -> panic state due to completely blocking of logic that frees vmap areas in the __purge_vmap_area_lazy() function. Establish a threshold passing which the freeing is prioritized back over allocation creating a balance between each other. Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fb4fb5fcee74..abe83f885069 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -661,23 +661,27 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end) struct llist_node *valist; struct vmap_area *va; struct vmap_area *n_va; - bool do_free = false; + int resched_threshold; lockdep_assert_held(&vmap_purge_lock); valist = llist_del_all(&vmap_purge_list); + if (unlikely(valist == NULL)) + return false; + + /* + * TODO: to calculate a flush range without looping. + * The list can be up to lazy_max_pages() elements. + */ llist_for_each_entry(va, valist, purge_list) { if (va->va_start < start) start = va->va_start; if (va->va_end > end) end = va->va_end; - do_free = true; } - if (!do_free) - return false; - flush_tlb_kernel_range(start, end); + resched_threshold = (int) lazy_max_pages() << 1; spin_lock(&vmap_area_lock); llist_for_each_entry_safe(va, n_va, valist, purge_list) { @@ -685,7 +689,9 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end) __free_vmap_area(va); atomic_sub(nr, &vmap_lazy_nr); - cond_resched_lock(&vmap_area_lock); + + if (atomic_read(&vmap_lazy_nr) < resched_threshold) + cond_resched_lock(&vmap_area_lock); } spin_unlock(&vmap_area_lock); return true;