From patchwork Tue Oct 11 05:06:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel A Fernandes X-Patchwork-Id: 9370111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A72260487 for ; Tue, 11 Oct 2016 05:08:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B96729A51 for ; Tue, 11 Oct 2016 05:08:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DAB529A5A; Tue, 11 Oct 2016 05:08:19 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 170CB29A51 for ; Tue, 11 Oct 2016 05:08:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1btpHA-0002mu-Vp; Tue, 11 Oct 2016 05:06:53 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1btpH7-0002ln-9n for linux-arm-kernel@lists.infradead.org; Tue, 11 Oct 2016 05:06:50 +0000 Received: by mail-lf0-x243.google.com with SMTP id x79so1609849lff.2 for ; Mon, 10 Oct 2016 22:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vnNLLT5jDM+XEVx/6tD1xK9btPbfQk/unlZJOjnD2eM=; b=gXbvurjCqDIwG6KurKWYV2B0rz7tRdjfObw33y46+YMEWpVsebRIoEPC5bEdKiLVFi gdTjBbDG1E0PKbq4Mk0QY2NmNIT/9zYZDyhqUyKG6us4p+f6U551rdl8KCPnwTh0srog u4o7xf7Tk6mLIOE6OU8GZXWac7P7lHTV0yNaMBPbOukVg8rkmby5nl3hvDExfifhlPsC bQjd4+xbt0IydKj0MfsBo/URJ9JZndrI/OYfIi2CfyIqRmjT7iOuPLQ/R2zw3aK/FXJN SmYTE1E3q5iX9uqir1T+YL6m+j3qee1ALwCJb/Ue8F3Adzx+nehnfjXNNJ+yqtcMv/Up YwwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vnNLLT5jDM+XEVx/6tD1xK9btPbfQk/unlZJOjnD2eM=; b=A+pqcVL8XMTpWXqMb2nJ/zDG95fZrVUnnmV2aHoEsLd1IglTsPOkwg/824NSC1q8AZ X8vm7Bhld1+p1MiuM4UV/Krk6qaw0vZGYKrQnob0ClugxQM5hQDES1CWFOUQx9yGQX42 suevQBFif+h+9UEgDFcsNZdWuIzj+W1+rSAeIFdxxK7b8/JXKBE/L3rhk9MQ3DPiOmLN Vak3N8OAGfIpvIw/aiMlHkkdJqUjqyf6cuZafRts2IJxfBcwpyojsP4NHYo2lVG4GlPp 1N0zfTVVSmFeAxpQXFHkNo/2DQGJUzrp4L/hd1XilY8APKv+sgyv4DjpuCuKfbR216Dk GBmg== X-Gm-Message-State: AA6/9RmOz2a/dvF516uRt+mP+zZ9J72RbrBEljGmNXysk35n0OjbpXJ1nQMWAUmt3hzeQ99NKw8SBZ5qsvYLGw== X-Received: by 10.25.141.67 with SMTP id p64mr1168905lfd.86.1476162386625; Mon, 10 Oct 2016 22:06:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.39.6 with HTTP; Mon, 10 Oct 2016 22:06:25 -0700 (PDT) In-Reply-To: <20161009192610.GB2718@nuc-i3427.alporthouse.com> References: <20160929073411.3154-1-jszhang@marvell.com> <20160929081818.GE28107@nuc-i3427.alporthouse.com> <20161009124242.GA2718@nuc-i3427.alporthouse.com> <20161009192610.GB2718@nuc-i3427.alporthouse.com> From: Joel Fernandes Date: Mon, 10 Oct 2016 22:06:25 -0700 Message-ID: Subject: Re: [PATCH] mm/vmalloc: reduce the number of lazy_max_pages to reduce latency To: Chris Wilson X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161010_220649_625343_F5A4967E X-CRM114-Status: GOOD ( 18.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jisheng Zhang , Joel Fernandes , npiggin@kernel.dk, Linux Kernel Mailing List , linux-mm@kvack.org, rientjes@google.com, Andrew Morton , mgorman@techsingularity.net, iamjoonsoo.kim@lge.com, Linux ARM Kernel List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun, Oct 9, 2016 at 12:26 PM, Chris Wilson wrote: > On Sun, Oct 09, 2016 at 12:00:31PM -0700, Joel Fernandes wrote: >> Ok. So I'll submit a patch with mutex for purge_lock and use >> cond_resched_lock for the vmap_area_lock as you suggested. I'll also >> drop the lazy_max_pages to 8MB as Andi suggested to reduce the lock >> hold time. Let me know if you have any objections. > > The downside of using a mutex here though, is that we may be called > from contexts that cannot sleep (alloc_vmap_area), or reschedule for > that matter! If we change the notion of purged, we can forgo the mutex > in favour of spinning on the direct reclaim path. That just leaves the > complication of whether to use cond_resched_lock() or a lock around > the individual __free_vmap_area(). Good point. I agree with you. I think we still need to know if purging is in progress to preserve previous trylock behavior. How about something like the following diff? (diff is untested). This drops the purge lock and uses a ref count to indicate if purging is in progress, so that callers who don't want to purge if purging is already in progress can be kept happy. Also I am reducing vmap_lazy_nr as we go, and, not all at once, so that we don't reduce the counter too soon as we're not holding purge lock anymore. Lastly, I added the cond_resched as you suggested. purge_fragmented_blocks_allcpus(); @@ -655,9 +655,6 @@ static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end, nr += (va->va_end - va->va_start) >> PAGE_SHIFT; } - if (nr) - atomic_sub(nr, &vmap_lazy_nr); - if (nr || force_flush) flush_tlb_kernel_range(*start, *end); @@ -665,9 +662,11 @@ static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end, spin_lock(&vmap_area_lock); llist_for_each_entry_safe(va, n_va, valist, purge_list) __free_vmap_area(va); + atomic_sub(1, &vmap_lazy_nr); + cond_resched_lock(&vmap_area_lock); spin_unlock(&vmap_area_lock); } - spin_unlock(&purge_lock); + atomic_dec(&purging); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f2481cb..5616ca4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -626,7 +626,7 @@ void set_iounmap_nonlazy(void) static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end, int sync, int force_flush) { - static DEFINE_SPINLOCK(purge_lock); + static atomic_t purging; struct llist_node *valist; struct vmap_area *va; struct vmap_area *n_va; @@ -638,10 +638,10 @@ static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end, * the case that isn't actually used at the moment anyway. */ if (!sync && !force_flush) { - if (!spin_trylock(&purge_lock)) + if (atomic_cmpxchg(&purging, 0, 1)) return; } else - spin_lock(&purge_lock); + atomic_inc(&purging); if (sync)