Received: by 10.213.65.68 with SMTP id h4csp238756imn; Fri, 30 Mar 2018 19:20:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+THVb4T0ZShTXeYkakSrnH2nmk4rf2E2wU+6LcEt08f7JYTyJSxeQtvnZoGG8oox2ytY6z X-Received: by 10.98.247.9 with SMTP id h9mr983760pfi.212.1522462823987; Fri, 30 Mar 2018 19:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522462823; cv=none; d=google.com; s=arc-20160816; b=mNnj3m8vYPqdL23YLWEMmOI625uPra5ERoecP8ViLipk6va7ET9nS7upKZofBu/zLG ED/tC9gQNPDXUylBosj2yoX9n4zWsZmOEn5uSj6Pd+zMf1mtxL2QYytWPFrsmt8qS4Og r5sfXza5QPOpGEY/Z8hoQ9G9WkofdP/B6OZpXwhryY6SmGNztHBK/16vF2EWTGNjBMXc 6crBPNvpjs4C5yojgpwKVnQBCdgxrWtwu7f4uLTG3oVzKMB6l2CJwsPmhMWFtrGFKJPs MNztBUvWpFpBpZ+2Dv0wc/ezjKygQYDK4YfBkZjms7hx2wU4mo5QGUYB/wbQxfcXxyEG SZ1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=4R1SM8ZlsomUocwfyjOTt8KdojMlm9UvPMj1HNWDHQw=; b=tp1xisvjNbUu+iq7H+DS2wLWf2M4XZ+Wjs7icFciqdg8lRwvz7EZniqdFq9nzXtF8H aJL0gTYnGu8ceZ5GbJ8z1peO73C3rtpCaQ3rj+ICv5m58YXZhmKVyX1TKCe9OEiDooD0 Yo3AG1a0HtayyzSXF9xklL9Cj5boZPe1NuojWEcwTz5IIjuXMRztbg8wwfX3PPFVAejQ awug7KdHikjkapjchD9YdIzu2vPQw6d7d9iV6tJ8HlRRBywFEUPxGOSc9n4QjbMVlQz8 eSByFgbRkHOpYdyx0OSg7rIWgcnV7lKhfqQMW/myHVSVIejt5kPIg9OUwgYbE83CKXll nG9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=SwXvASeA; 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 y11si5660534pgr.0.2018.03.30.19.20.09; Fri, 30 Mar 2018 19:20:23 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=SwXvASeA; 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 S1752837AbeCaCTC (ORCPT + 99 others); Fri, 30 Mar 2018 22:19:02 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46496 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752784AbeCaCTA (ORCPT ); Fri, 30 Mar 2018 22:19:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4R1SM8ZlsomUocwfyjOTt8KdojMlm9UvPMj1HNWDHQw=; b=SwXvASeAVwIA3QkIyoVoM1jr9 TS61U7dX8GCyGK5OPAzy1LQ68LACexu8jPmmUhAxVKJjWqvKzUzU2bjxOrA2Tt+DBWpae2KpBu6px f2rHCqK69XHx+akQ8ZVYrVSxTQ20BtiSrs6OJ3Jiz0CTyZt4o46WVBcUFlyCPIk6j9O+qypDfo0cx SI/Mx8oLRN9bIX8dnPzoO2XSsMv1nY6MhTv+p8OtmTqYKLry9xZ0vdKqDshFjeqB1CQpyp7DAxlUe qKQhr/aBB4gKOYWAQTJnsjCzgldZofh5XdmZM/1PiFmzCQIYMdJDhdaWmD7GiL9mKhwaxveev+mTG 0vA3PJEzw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f266c-0004fz-1E; Sat, 31 Mar 2018 02:18:58 +0000 Date: Fri, 30 Mar 2018 19:18:57 -0700 From: Matthew Wilcox To: Steven Rostedt Cc: Joel Fernandes , 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: <20180331021857.GD13332@bombadil.infradead.org> 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> <20180330214151.415e90ea@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180330214151.415e90ea@gandalf.local.home> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 30, 2018 at 09:41:51PM -0400, Steven Rostedt wrote: > 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. Again though, this is the same pattern as vmalloc. There are any number of places where userspace can cause an arbitrarily large vmalloc to be attempted (grep for kvmalloc_array for a list of promising candidates). I'm pretty sure that just changing your GFP flags to GFP_KERNEL | __GFP_NOWARN will give you the exact behaviour that you want with no need to grub around in the VM to find out if your huge allocation is likely to succeed.