Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp15425pxb; Tue, 17 Nov 2020 18:48:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzv/K9I8Fbsq+nXAORfsVb4MV5pJcqmv+mZ7ai5fhePkDMUPF9vREvoa3SjLrZKzqN2FFyd X-Received: by 2002:a50:fc95:: with SMTP id f21mr23205234edq.383.1605667721260; Tue, 17 Nov 2020 18:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605667721; cv=none; d=google.com; s=arc-20160816; b=gkGbkGpzAfIkYOxsSOe7vdD9LzoqutfrCHt60gkneg6nteRcda0/AzD2A5lophd6bQ 3TdsQuxxvdtRBC6LgyCYvtPtwdsUE+zEXkgs9q0tGnAvx9coZA2jiFZiBi8ziMOy5eZh IK3saEheTKPgFrfqFESkszQBfMee0/pUdcz8c/ceQxM2UWd/wbvzdzBp+GQklaBxUGyg SjXDV9Y1tUB/+LWAP1gLQ72+XtJdiHePz9UZl+sd3XKrO4vZGOUOe/+eQf7RwxDXezeI oNRbere65E+T1dbermX+C+Hi514XLA429QKx343KzG4hZdSzGiggPtB8muPKfblO4uhc IRMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=i1baSlx7+AuP0I6rzkrgeQ8LBxCjB7SE8APgJzoq8Tk=; b=ThJrhaSpn2RF7gm08xJ4idKC7mqz7Ui5z454gJPYwF4dGZ+WiVZ2o82JU0OKFtVITn PPRHX2qz+8yn68SBZLViS24YpNVZzJZV7RjNzUqzCboNqlQaiq2v9AM6D9ntIk3Bkl7C mQ/ESVmvUF1SPS6fKNHlxsYJpkS8nPvNJd/Tdabvp3337YmXTFKKP0mYIIdHPzq8b/+b ZgwOR7kUmAhz/qWej4HEg1IaNP9ZrT0INZrTdK9T7cghAm07ZVhHWL45VNpB6MqtVErF cyeIyH6kABc7U/RKwuMDWcka5mdGf+HcPZfKF66DhSyYFsYbXFzD7H7xZBfsYkcxsA4S QKew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TTgZMsAB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o16si15211646edi.462.2020.11.17.18.48.18; Tue, 17 Nov 2020 18:48:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TTgZMsAB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726202AbgKRCo0 (ORCPT + 99 others); Tue, 17 Nov 2020 21:44:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbgKRCo0 (ORCPT ); Tue, 17 Nov 2020 21:44:26 -0500 Received: from mail-vs1-xe44.google.com (mail-vs1-xe44.google.com [IPv6:2607:f8b0:4864:20::e44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A575C0613D4 for ; Tue, 17 Nov 2020 18:44:25 -0800 (PST) Received: by mail-vs1-xe44.google.com with SMTP id v6so197402vsd.1 for ; Tue, 17 Nov 2020 18:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i1baSlx7+AuP0I6rzkrgeQ8LBxCjB7SE8APgJzoq8Tk=; b=TTgZMsABcbK/0tR56BhY5Kc3aVCHk2MgelMbWKx9Xwhkr5Frty7saHuiqmPAxqBqh4 tClJ4m2IgA5rVTAuQyHfe049KsBCpdpoUZ+z7seEZFoCiR/ysG8XYEfemf/IP92tv4RG jU2JG55ayurOrn831ogClu8q9WHNpZ6CZCteSQsxNvF4NSDu7mdR4XPgO1YPRfNKYZts gliQu/cX/r8+X1HHYae48a84LeUPpoj7e5BBoxeqtQ8SGuRDU8W/gp12c8fO1i3LcKVu PFPunEFubjhtDS2uuJeE3m45WK5kIyDYVjgpY7n/iOCCh7MLe8STHz8OEyujXi3Adsht fU1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i1baSlx7+AuP0I6rzkrgeQ8LBxCjB7SE8APgJzoq8Tk=; b=e4I81ekIyCSUEgAQtoJPvxggpsPlp4TdqJV9WDo/jwrDtRk6/9PXtMR6k4vXz0FzzY t2H86heMwgVHgmDJb3ArntYm4ZJ4sHbU0Hy9wROInSHGycGJZGC0ghsoeB5aCZ/nFnZT SICzzuWaWR22UBziCPAUfd/RAQVWyFAEEwO0gZmacuZjLDnSRQ9ODRJpZdNi9A+PHy41 af0dl0/bP3NX7W/DYdfYvMBWfmYTE8NLxQfpo37GM4NJcDajJnA7bhFvPSRJuZ+k2WP6 2L7HxTsNFJ1jMpykjxh4J9ksjdcnG11g2yKXDmz4WsmQY2FOW6u4q0WMDL0oCj9T5c+F 08Jg== X-Gm-Message-State: AOAM5324YzEo61XDAy4sQaDt6/MygxR4E1qGkhrsWt5jolDQSvPl6vpX M0YNGw9+aOnEk2WzQMoGl9+ojbPqaTApwKLOm62DsM83s28= X-Received: by 2002:a05:6102:3129:: with SMTP id f9mr2009802vsh.26.1605667464406; Tue, 17 Nov 2020 18:44:24 -0800 (PST) MIME-Version: 1.0 References: <20201116220033.1837-1-urezki@gmail.com> <20201116220033.1837-2-urezki@gmail.com> <20201117130434.GA10769@pc636> In-Reply-To: <20201117130434.GA10769@pc636> From: huang ying Date: Wed, 18 Nov 2020 10:44:13 +0800 Message-ID: Subject: Re: [PATCH 2/2] mm/vmalloc: rework the drain logic To: Uladzislau Rezki Cc: Andrew Morton , linux-mm@kvack.org, LKML , Hillf Danton , Michal Hocko , Matthew Wilcox , Oleksiy Avramchenko , Steven Rostedt , Huang Ying , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 17, 2020 at 9:04 PM Uladzislau Rezki wrote: > > On Tue, Nov 17, 2020 at 10:37:34AM +0800, huang ying wrote: > > On Tue, Nov 17, 2020 at 6:00 AM Uladzislau Rezki (Sony) > > wrote: > > > > > > A current "lazy drain" model suffers from at least two issues. > > > > > > First one is related to the unsorted list of vmap areas, thus > > > in order to identify the [min:max] range of areas to be drained, > > > it requires a full list scan. What is a time consuming if the > > > list is too long. > > > > > > Second one and as a next step is about merging all fragments > > > with a free space. What is also a time consuming because it > > > has to iterate over entire list which holds outstanding lazy > > > areas. > > > > > > See below the "preemptirqsoff" tracer that illustrates a high > > > latency. It is ~24 676us. Our workloads like audio and video > > > are effected by such long latency: > > > > This seems like a real problem. But I found there's long latency > > avoidance mechanism in the loop in __purge_vmap_area_lazy() as > > follows, > > > > if (atomic_long_read(&vmap_lazy_nr) < resched_threshold) > > cond_resched_lock(&free_vmap_area_lock); > > > I have added that "resched threshold" because of on my tests i could > simply hit out of memory, due to the fact that a drain work is not up > to speed to process such long outstanding list of vmap areas. OK. Now I think I understand the problem. For free area purging, there are multiple "producers" but one "consumer", and it lacks enough mechanism to slow down the "producers" if "consumer" can not catch up. And your patch tries to resolve the problem via accelerating the "consumer". That isn't perfect, but I think we may have quite some opportunities to merge the free areas, so it should just work. And I found the long latency avoidance logic in __purge_vmap_area_lazy() appears problematic, if (atomic_long_read(&vmap_lazy_nr) < resched_threshold) cond_resched_lock(&free_vmap_area_lock); Shouldn't it be something as follows? if (i >= BATCH && atomic_long_read(&vmap_lazy_nr) < resched_threshold) { cond_resched_lock(&free_vmap_area_lock); i = 0; } else i++; This will accelerate the purging via batching and slow down vmalloc() via holding free_vmap_area_lock. If it makes sense, can we try this? And, can we reduce lazy_max_pages() to control the length of the purging list? It could be > 8K if the vmalloc/vfree size is small. Best Regards, Huang, Ying