Received: by 10.223.164.202 with SMTP id h10csp2737831wrb; Tue, 28 Nov 2017 00:01:44 -0800 (PST) X-Google-Smtp-Source: AGs4zMbjHAKwSqp0VOrFDU4W14qXPlklKZU5RMKeb7tZMG9SCD9c2GKbBO7cPGVmrkvjJWcw87Ao X-Received: by 10.159.252.198 with SMTP id o6mr40793237pls.390.1511856104209; Tue, 28 Nov 2017 00:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511856104; cv=none; d=google.com; s=arc-20160816; b=FJxhhPvA+lGavGzcsFYNrVFnEVfwF51cfHhM57ad7uZHpD2/z79eH9v8wNCpbfK1KI Ma4Bask/DVH3soDLaxEiTrhGP/KSEc/pV9R1sqXAzybc5snNlKOrIiaFZLsOgEF1zSxC 7f9tjEq1R6wePV3oUVdg/ZGeQdOH+dvpi97KKlj8mj/NPX5JL9OnuIvxcL0d1R0a5G0B 5i43g7aCRJh6N4FTjrrdiNI1V2Y8PHiqr1hcl+22+GAlDK6wHRsySy14xdlz3dHO6mDn GIaKFDq0riUU0hxv7lPZouSDVx/mBh/HR6A68gGhuj+xTMCsWt5mikzsjFMfOHrI7gbX 3U6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=lz+9EeUrICbqnLO3dxTgiT8U9awB0bGOCJp9jfINEFw=; b=BPQSEY591y3UB5ZWhms3RC//tS3JjOec7n338qteemPGv5ww1o9FKqi8nysL8zQ1sx GFvdU/JhLBSisnc+mwCjYbP4BRha6uG6FX8ANLu6wbv703NdiF4QUr28wGVfZZ2usCQ1 FWhmiBGoQdiPjXJ17R4K174CqcD6/hmQRXZ8dzrnZIHEcIUI6IVYYLggAlw91IR3vjTL CzvguwSRjNF8dPNPOssC2i/Djvc3MgSfIRcojvYrKcXz4KjzIraIFXEZ2XMHU86GCq0E 07SygOGkQbfH1/vTk90fX+zF7Ef9rMM4BoQugz2yo15hD/oExZ6vJhOJX0ZhDB9g4h2K qjjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Eg36EYDy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l59si18207937plb.639.2017.11.28.00.01.32; Tue, 28 Nov 2017 00:01:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Eg36EYDy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751530AbdK1IAR (ORCPT + 78 others); Tue, 28 Nov 2017 03:00:17 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:33681 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750850AbdK1IAP (ORCPT ); Tue, 28 Nov 2017 03:00:15 -0500 Received: by mail-io0-f195.google.com with SMTP id i184so31951279ioa.0 for ; Tue, 28 Nov 2017 00:00:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=lz+9EeUrICbqnLO3dxTgiT8U9awB0bGOCJp9jfINEFw=; b=Eg36EYDypw8WXprXC9mj5PMA0RsSV5qfhnFeaqZ16hT5ylspG3rYOGVIwS638NoYhP Q3SeL1H7pFtZ9AOGqK+3VoKMdPZF1hUwl/Awz6z211MFbudZus5ioHUJWsiIIU61Kaj/ 4i2ruvgyyohLel0CVFeU0aPp6S8mrjK2X3YIjiBF4GrBBx76OJQRS4w7eqxWwBiOs0Nd 53SsuMFksuQHrW7CG/pHqGNIyN8GMlHvIQHs5WNxUGarGgEIj9EnDIYw71qc0QlZ1qCy +D3KfepcjSEAehk6xIqhtBPXV/MZCvMdLSsTzmTxkk8T+qYuGrFRLHzETZO0+oHPelai Wh1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=lz+9EeUrICbqnLO3dxTgiT8U9awB0bGOCJp9jfINEFw=; b=Um6GeoK7Hm7vbQhyc7y7zjX7XGjptJJZnRcF52uH3M+0P2hUv+NSTPtQ+bRbDUUj29 GfLrKOUN69lr5zX3txaTS0B7plH3sdxMEzLpvp1O4pN/MuO7XvpgFfQPFG2By9irLRR6 1nRRX800pMagHp9KX9KLofuaA1Vo90cLTt6LzGqzZa3U9N3qpK3Ur6RM9v/lmxNtMB5O gyJ8KDIllYOx0035T+tanIeuvKQDtmRfVml7DXnNw8pq8y95PVDqo2K/CbNWMqmzR/8l mRSwNigr0LSLngedvGVa7mJbPhA9VUP+p4jyJguavVjA6g6RY9571j1fiusp9atz00TK aBzA== X-Gm-Message-State: AJaThX4AS06z9gJaZs1u+p45dQMU04gpGizyBLp0p1xc8/w1tmENxq+n BU7YDktWuHZCl3N3eZVM4/ZS9ELDFdH6DXS+IaU= X-Received: by 10.107.163.147 with SMTP id m141mr30279594ioe.61.1511856015087; Tue, 28 Nov 2017 00:00:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.5.21 with HTTP; Tue, 28 Nov 2017 00:00:14 -0800 (PST) In-Reply-To: References: <1511841842-3786-1-git-send-email-zhouzhouyi@gmail.com> From: Zhouyi Zhou Date: Tue, 28 Nov 2017 16:00:14 +0800 Message-ID: Subject: Re: [PATCH 1/1] kasan: fix livelock in qlist_move_cache To: Dmitry Vyukov Cc: Andrey Ryabinin , Alexander Potapenko , kasan-dev , Linux-MM , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for reviewing My machine has 128G of RAM, and runs many KVM virtual machines. libvirtd always report "internal error: received hangup / error event on socket" under heavy memory load. Then I use perf top -g, qlist_move_cache consumes 100% cpu for several minutes. On Tue, Nov 28, 2017 at 3:45 PM, Dmitry Vyukov wrote: > On Tue, Nov 28, 2017 at 5:05 AM, Zhouyi Zhou wrote: >> When there are huge amount of quarantined cache allocates in system, >> number of entries in global_quarantine[i] will be great. Meanwhile, >> there is no relax in while loop in function qlist_move_cache which >> hold quarantine_lock. As a result, some userspace programs for example >> libvirt will complain. > > Hi, > > The QUARANTINE_BATCHES thing was supposed to fix this problem, see > quarantine_remove_cache() function. > What is the amount of RAM and number of CPUs in your system? > If system has 4GB of RAM, quarantine size is 128MB and that's split > into 1024 batches. Batch size is 128KB. Even if that's filled with the > smallest objects of size 32, that's only 4K objects. And there is a > cond_resched() between processing of every batch. > I don't understand why it causes problems in your setup. We use KASAN > extremely heavily on hundreds of machines 24x7 and we have not seen > any single report from this code... > > >> On Tue, Nov 28, 2017 at 12:04 PM, wrote: >>> From: Zhouyi Zhou >>> >>> This patch fix livelock by conditionally release cpu to let others >>> has a chance to run. >>> >>> Tested on x86_64. >>> Signed-off-by: Zhouyi Zhou >>> --- >>> mm/kasan/quarantine.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c >>> index 3a8ddf8..33eeff4 100644 >>> --- a/mm/kasan/quarantine.c >>> +++ b/mm/kasan/quarantine.c >>> @@ -265,10 +265,13 @@ static void qlist_move_cache(struct qlist_head *from, >>> struct kmem_cache *cache) >>> { >>> struct qlist_node *curr; >>> + struct qlist_head tmp_head; >>> + unsigned long flags; >>> >>> if (unlikely(qlist_empty(from))) >>> return; >>> >>> + qlist_init(&tmp_head); >>> curr = from->head; >>> qlist_init(from); >>> while (curr) { >>> @@ -278,10 +281,17 @@ static void qlist_move_cache(struct qlist_head *from, >>> if (obj_cache == cache) >>> qlist_put(to, curr, obj_cache->size); >>> else >>> - qlist_put(from, curr, obj_cache->size); >>> + qlist_put(&tmp_head, curr, obj_cache->size); >>> >>> curr = next; >>> + >>> + if (need_resched()) { >>> + spin_unlock_irqrestore(&quarantine_lock, flags); >>> + cond_resched(); >>> + spin_lock_irqsave(&quarantine_lock, flags); >>> + } >>> } >>> + qlist_move_all(&tmp_head, from); >>> } >>> >>> static void per_cpu_remove_cache(void *arg) >>> -- >>> 2.1.4 >>> >> >> -- >> You received this message because you are subscribed to the Google Groups "kasan-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. >> To post to this group, send email to kasan-dev@googlegroups.com. >> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/CAABZP2zEup53ZcNKOEUEMx_aRMLONZdYCLd7s5J4DLTccPxC-A%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. From 1585295111814116281@xxx Tue Nov 28 07:47:12 +0000 2017 X-GM-THRID: 1585281151451498932 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread