Received: by 10.213.65.68 with SMTP id h4csp3449759imn; Tue, 3 Apr 2018 05:17:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx48T2xItz1pIt3WJ79m1vG+d5gkzZYJbzdA7JlvTtqpERMyFnFL1cXE3J2b0wjCO03/+gfG1 X-Received: by 10.98.87.7 with SMTP id l7mr10388756pfb.148.1522757874782; Tue, 03 Apr 2018 05:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522757874; cv=none; d=google.com; s=arc-20160816; b=j5pAESvxiS+3llRq5jBzdNzL2/G+ys5rKkQrl6krBhKvn8CYlVte6lUIQZSLQvigYW hMH8ap9W9VjSjaB/su0n3xOVT0GmyyGqeeDprPwzfW/92qleXWZoW2zTDA5wbIqE8zOl Hiyas3UIyD8lf2fQJk/dMKhmDN/WuZCNrJ8kgr/KnxnuRAy8r80u0sRBT+Za7hXkkn4+ iHnpNtQ2TaP/I9zI8hBHkbhRGLkYN2oH9TWy8a8P5ihcXThMrHlAMyLvsZa/3W/nT1AV KhJP9N41oVl3ivaYEkXxVftj3yK5QGprBsG80GJU8GAJWEIIv3Gz2ZiRfF3oJ68mHJ70 pm9Q== 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:arc-authentication-results; bh=tpulM/3XbS5LLmFDqS93I51Uw9YmCDTWU+FF4jO2lpo=; b=lMzd+V7kqZms3cw9JTZ89hTxbInVfdGifRxfQ39juOXq1PmoOQ+2PrBxL5ln6rHmXl 3gFE6/F+dZKEj9AFcIt7GBEguLBBP9KS00rD1/x3233Z+txXU8kBSorTGPJRn78KJzr3 kP+8vcVKppDZtk7iZAB19pGC3rwKhga/xXiakJp16CEOYoXo2P2CICJe2F1rFBJJ43GC XYxxC+6Gn+m1fwi7gobKPx7tuCodA3oAKbtSVX2C4lHUYfdO8Zndts9ejt/hVAry4F5z 6VRSlRg7EIq+8faJmfSIuIZEhkM+vEMy38hvUfDORLVLOyldRfFXqbVINOnRGetSMGUj 15Ng== 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 z20si2032027pfh.251.2018.04.03.05.17.40; Tue, 03 Apr 2018 05:17:54 -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 S1755536AbeDCMQU (ORCPT + 99 others); Tue, 3 Apr 2018 08:16:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:35418 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755300AbeDCMQR (ORCPT ); Tue, 3 Apr 2018 08:16:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 73EEFAE7E; Tue, 3 Apr 2018 12:16:15 +0000 (UTC) Date: Tue, 3 Apr 2018 14:16:14 +0200 From: Michal Hocko To: Steven Rostedt Cc: Zhaoyang Huang , Ingo Molnar , linux-kernel@vger.kernel.org, kernel-patch-test@lists.linaro.org, Andrew Morton , Joel Fernandes , linux-mm@kvack.org, Vlastimil Babka Subject: Re: [PATCH v1] kernel/trace:check the val against the available mem Message-ID: <20180403121614.GV5501@dhcp22.suse.cz> References: <1522320104-6573-1-git-send-email-zhaoyang.huang@spreadtrum.com> <20180330102038.2378925b@gandalf.local.home> <20180403110612.GM5501@dhcp22.suse.cz> <20180403075158.0c0a2795@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180403075158.0c0a2795@gandalf.local.home> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 03-04-18 07:51:58, Steven Rostedt wrote: > On Tue, 3 Apr 2018 13:06:12 +0200 > Michal Hocko wrote: > > > > I wonder if I should have the ring buffer allocate groups of pages, to > > > avoid this. Or try to allocate with NORETRY, one page at a time, and > > > when that fails, allocate groups of pages with RETRY_MAYFAIL, and that > > > may keep it from causing an OOM? > > > > I wonder why it really matters. The interface is root only and we expect > > some sanity from an admin, right? So allocating such a large ring buffer > > that it sends the system to the OOM is a sign that the admin should be > > more careful. Balancing on the OOM edge is always a risk and the result > > will highly depend on the workload running in parallel. > > This came up because there's scripts or programs that set the size of > the ring buffer. The complaint was that the application would just set > the size to something bigger than what was available and cause an OOM > killing other applications. The final solution is to simply check the > available memory before allocating the ring buffer: > > /* Check if the available memory is there first */ > i = si_mem_available(); > if (i < nr_pages) > return -ENOMEM; > > And it works well. Except that it doesn't work. si_mem_available is not really suitable for any allocation estimations. Its only purpose is to provide a very rough estimation for userspace. Any other use is basically abuse. The situation can change really quickly. Really it is really hard to be clever here with the volatility the memory allocations can cause. -- Michal Hocko SUSE Labs