Received: by 10.213.65.68 with SMTP id h4csp217271imn; Fri, 30 Mar 2018 18:43:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Z3LoTrrE/LjVwIoemzRt/LtnNEsRS2k2/kTt8bgVeGIBnSZH5+rhAdSLs2lxBucfTHw+l X-Received: by 2002:a17:902:7894:: with SMTP id q20-v6mr1284589pll.86.1522460594845; Fri, 30 Mar 2018 18:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522460594; cv=none; d=google.com; s=arc-20160816; b=ATtjWcvQ3RrWtcBsb8l85sulh9iLXgY7Elu87dnApP0XzerjuSJxAuelnnEE2026W0 8L52OuwEYbZ334ItEFtxNlJ1X9GoV8TwEPbUkJXkX2481Qp6aq3ItPjrK/TEIA3I8dzK 7HLAQSa1LlbiebCKCff56xxSAPm+S/vr+orY4SXdZbT09O7pCuCxelcP2ziuNs4nfU0F QT/6M9u5kU486yyfHmCxhZIvj/64vM4mKPslz78GeIa1WVEDwGdryYjpmXfiM5tMrAkR L2t6ZoIh4TNZJ0YQOyzSE7jlfz/PWkaxSy+KlD/bQZCtEk1aF5mR33fUln11iNpZmq1q gjSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=Zot+1TEsy14j1inh7JapD7NY4dhKw1/oDPCzc/0f3VU=; b=C6FeTcV3NaNLq0z221Jmlg6wLUEhmKG2JAwIe21HZlV/gohoPHhmNtCoqFiTJNn7yU zQuVm7FgngL3GfWoAyhhoiH2Ki9CdjfWYQSJzJw+eaH9w6WIQZdLTKYCRS4+8UpZqMgX JSjhDZkllZdg3b9FO7ElUn22KXFqYFydfUvp68oZPX6p2FDSvVro7AWcV73cia+kQJTY b40GwbaolL+DfoE4SaBTZ1vlNiZSmeFCUOqGYQU9xCWFztyucxgyYrZ7zms3hzQq88SS rDH2LgEcrBa2LigpRY5tzJztlv2fJbG5fJ/YpNliWT3brt6dbUxh3AmQN9eoU6IEuSEV /9qQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc11-v6si9230798plb.43.2018.03.30.18.43.00; Fri, 30 Mar 2018 18:43:14 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752823AbeCaBlz (ORCPT + 99 others); Fri, 30 Mar 2018 21:41:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:51696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752603AbeCaBly (ORCPT ); Fri, 30 Mar 2018 21:41:54 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1321021773; Sat, 31 Mar 2018 01:41:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1321021773 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Fri, 30 Mar 2018 21:41:51 -0400 From: Steven Rostedt To: Joel Fernandes Cc: Matthew Wilcox , Zhaoyang Huang , Ingo Molnar , LKML , kernel-patch-test@lists.linaro.org, Andrew Morton , Michal Hocko , "open list:MEMORY MANAGEMENT" , Vlastimil Babka , Michal Hocko Subject: Re: [PATCH v1] kernel/trace:check the val against the available mem Message-ID: <20180330214151.415e90ea@gandalf.local.home> In-Reply-To: References: <1522320104-6573-1-git-send-email-zhaoyang.huang@spreadtrum.com> <20180330102038.2378925b@gandalf.local.home> <20180330205356.GA13332@bombadil.infradead.org> <20180330173031.257a491a@gandalf.local.home> <20180330174209.4cb77003@gandalf.local.home> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Mar 2018 16:38:52 -0700 Joel Fernandes wrote: > > --- a/kernel/trace/ring_buffer.c > > +++ b/kernel/trace/ring_buffer.c > > @@ -1164,6 +1164,11 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu) > > struct buffer_page *bpage, *tmp; > > long i; > > > > + /* Check if the available memory is there first */ > > + i = si_mem_available(); > > + if (i < nr_pages) > > Does it make sense to add a small margin here so that after ftrace > finishes allocating, we still have some memory left for the system? > But then then we have to define a magic number :-| I don't think so. The memory is allocated by user defined numbers. They can do "free" to see what is available. The original patch from Zhaoyang was due to a script that would just try a very large number and cause issues. If the memory is available, I just say let them have it. This is borderline user space issue and not a kernel one. > > + > > I tested in Qemu with 1GB memory, I am always able to get it to fail > allocation even without this patch without causing an OOM. Maybe I am > not running enough allocations in parallel or something :) Try just echoing in "1000000" into buffer_size_kb and see what happens. > > The patch you shared using si_mem_available is working since I'm able > to allocate till the end without a page allocation failure: > > bash-4.3# echo 237800 > /d/tracing/buffer_size_kb > bash: echo: write error: Cannot allocate memory > bash-4.3# echo 237700 > /d/tracing/buffer_size_kb > bash-4.3# free -m > total used free shared buffers > Mem: 985 977 7 10 0 > -/+ buffers: 977 7 > Swap: 0 0 0 > bash-4.3# > > I think this patch is still good to have, since IMO we should not go > and get page allocation failure (even if its a non-OOM) and subsequent > stack dump from mm's allocator, if we can avoid it. > > Tested-by: Joel Fernandes Great thanks! I'll make it into a formal patch. -- Steve