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;