Received: by 10.223.164.202 with SMTP id h10csp2800184wrb; Tue, 28 Nov 2017 01:18:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMa1gvrp0C9kF3jPZIt2lA+UXf6lWWo+anTIMFILpYqvD4JSZ1IqDzEJIXBBgD6MoMU7/xnR X-Received: by 10.84.218.143 with SMTP id r15mr41212556pli.53.1511860698099; Tue, 28 Nov 2017 01:18:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511860698; cv=none; d=google.com; s=arc-20160816; b=Gf+v/4m6UHICkV4rG2UYFXR2IiP6W3vO//fxz4NCDgxcskcXF0fgBKda1IK2J7bm3L KIvrhV/o2dTk6i6KBg4T2WgR6FjRhKAQLZ6boG94G42CUjqSKg6LF2LFbT+PBufbxb/s FnV/mDoto2b8rPLECScCVsxdsMmxOmiNmICQuFMWNWYlSFEvyMlRL/vNO+dngLSm3VXh PFKoPbleSE7uE6g6zIDR3ymI3aDvtoBhk4lpBZ1CuMy+VoT1dogA//J7RwuZ90TRwI4X t+va3TT1ndEXsYYgnfaiMZOGbKJHNdYRu4gjed8WFbr8VI8z1Nhsykmdpj2v+O1gD/dQ wD2g== 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=/HS30kgxX4p8VJJ2g85EnVH3G3AcOmxqv5CNy8609nU=; b=n16Zp3u1UrFj0csXdufNBeEFoVgheRXKxqKjBq5OPWddf+v7e3GtBbZRK+DT9r8eKG dYxuHZ/b2zeF2Kzoli/Ur/KfLDF0K3TpF1z0/lGjb2B9VYyIKjMHc0TQgSz21YMQm+6c fVreghOkbiDkk4Q4SjOzI38vfHb7uES4xgYenelJm/M3NQTq6l0skgoGp6oN6NqSXiVu AczcoYHNywPoiJVeNPj+B/3r/o/5OTyhIuwsfEL9LmxJCFe/Pak74QdIyzrcux5KTwLZ BE+tDeztFY6WWt0dZZAP5hPYyNNkrNMeNnKYLhjhtxRpOzx7TLFwRpHkb8gJdqiMmhTg VUxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G/HV8NkC; 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 be1si2927973plb.48.2017.11.28.01.18.06; Tue, 28 Nov 2017 01:18:18 -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=G/HV8NkC; 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 S1751942AbdK1JRS (ORCPT + 78 others); Tue, 28 Nov 2017 04:17:18 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:38283 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751668AbdK1JRP (ORCPT ); Tue, 28 Nov 2017 04:17:15 -0500 Received: by mail-io0-f196.google.com with SMTP id h205so132597iof.5 for ; Tue, 28 Nov 2017 01:17: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=/HS30kgxX4p8VJJ2g85EnVH3G3AcOmxqv5CNy8609nU=; b=G/HV8NkC38XV+5wm3senhXBdiSWKZajUcjWV+nf2p2pkErrtB2Cr5C+HlQqSQXy0fd eD9qc9E0twX7tPCiQSpL7Lhfxlq2PIwpg/QhKe9VJJMx3ObmDJnwp+PC7dAyougivQJd A36vwDo4yO7vRkZ10VKT9H8HVLRB54BgoZtToGWfNzh+2XZSchQ8VTpNMWf1UDgT0skT uMG2XD5Y1BsgfUGoRRVC7RUfo7cIIgWX6MJifsCZeQgMXFLeSTXzoFDQXqrgXdLzz6pp oBWCRUJBDoSKYer/VgJtXVmdEjFC02kEZgGfGo4TjP5SdK9fU7vNji8jJLPDpWdW3V6/ 0djQ== 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=/HS30kgxX4p8VJJ2g85EnVH3G3AcOmxqv5CNy8609nU=; b=ZMX299WoTrqoZeFX9nd6uN0lLiodwN5mgGXsiGHJDRSOSp42RJp7qNByfiboD5OliR E7woN6ZiwEL97PZgUrqbr0juhfLVDvn9pY363cOX5Qh+yPddTsB7K8vP4CM7ziwrx0Bz D2uK1yoHfojkcnjvgrGBuiXR3fy1KDLaykVkkGU5LkaBPk1hvpkqY3pI8dfR1ztrkkkJ oikfZBM2d4ajXlJ7ZmJ0iobwecEflDkFOPUQWPItke+qiPHOxIHaqUw9ztnlRqqe+z/2 +ef2NoPaEhZh7a8+/e0slVkpcvk3fFc2i9WqRJY8hLRHYnFUSoISogpNGvzMmQQ38MDX UIpQ== X-Gm-Message-State: AJaThX4nnDDhnbYYFMEQTLBgQ64hHDUfikC78ZKratvw00FYLIZSaAsv IyQ9TQYCtqw2Fvr5NzaWkURb+itCxi4/8BUfKEI= X-Received: by 10.107.5.142 with SMTP id 136mr18154564iof.121.1511860634979; Tue, 28 Nov 2017 01:17:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.5.21 with HTTP; Tue, 28 Nov 2017 01:17:14 -0800 (PST) In-Reply-To: References: <1511841842-3786-1-git-send-email-zhouzhouyi@gmail.com> From: Zhouyi Zhou Date: Tue, 28 Nov 2017 17:17: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 Hi, Imagine all of the QUARANTINE_BATCHES elements of global_quarantine array is of size 4MB + 1MB, now a new call to quarantine_put is invoked, one of the element will be of size 4MB + 1MB + 1MB, so on and on. On Tue, Nov 28, 2017 at 4:58 PM, Dmitry Vyukov wrote: > On Tue, Nov 28, 2017 at 9:33 AM, Zhouyi Zhou wrote: >> Hi, >> Please take a look at function quarantine_put, I don't think following >> code will limit the batch size below quarantine_batch_size. It only advance >> quarantine_tail after qlist_move_all. >> >> qlist_move_all(q, &temp); >> >> spin_lock(&quarantine_lock); >> WRITE_ONCE(quarantine_size, quarantine_size + temp.bytes); >> qlist_move_all(&temp, &global_quarantine[quarantine_tail]); >> if (global_quarantine[quarantine_tail].bytes >= >> READ_ONCE(quarantine_batch_size)) { >> int new_tail; >> >> new_tail = quarantine_tail + 1; >> if (new_tail == QUARANTINE_BATCHES) >> new_tail = 0; >> if (new_tail != quarantine_head) >> quarantine_tail = new_tail; > > > As far as I see this code can exceed global quarantine batch size by > at most 1 per-cpu batch. Per-cpu batch is caped at 1MB. So max global > batch size will be 4MB+1MB. Which does not radically change situation. > > >> On Tue, Nov 28, 2017 at 4:12 PM, Dmitry Vyukov wrote: >>> On Tue, Nov 28, 2017 at 9:00 AM, Zhouyi Zhou wrote: >>>> 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. >>> >>> For 128GB of RAM, batch size is 4MB. Processing such batch should not >>> take more than few ms. So I am still struggling to understand how/why >>> your change helps and why there are issues in the first place... >>> >>> >>> >>>> 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 1585299694835864432@xxx Tue Nov 28 09:00:02 +0000 2017 X-GM-THRID: 1585281151451498932 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread