Received: by 10.213.65.68 with SMTP id h4csp3468932imn; Tue, 3 Apr 2018 05:36:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx49kewnuvl9Cx8ZEPwrRfMjuPiYcB+OemZsqEpSNmDHScJavo69zpWi653Dpwg40ZyU7zbXR X-Received: by 10.98.103.199 with SMTP id t68mr10401202pfj.24.1522759015692; Tue, 03 Apr 2018 05:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522759015; cv=none; d=google.com; s=arc-20160816; b=l3aIBDgFqknOdaF8VDK0US/+q6HNMD2DMyPmRcNPlU63xaOrLt/g+l03qyc4dLzCKA 2cfa3u4h7UtsCRiwhBUr5jib2hKgPFOSe8tTrFTU79hPJyacCjZaqVIyTtOZWlx76s0s U63UNn47UHF8TUXFlMMUIR03hhu0xjhOCWje4iq8DyP5GteHdaYUZRHE+KUzkDCtxBOs sOMfoCUNovwBdp6SSU2cqbCTRvEnghbBXloj6EoZlO4JkFadg0MT/qrgnPOYtLwdaa0r HYBpcneowHP9IMyol5LJGxyc/01QmUSXiZ25pUaG1mT36KAXPtolmgOk4aRWVe+tC+27 UsLw== 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=OlXnMlRjLf2epIh4TNmqBbOvAf0KLaCSs4wWgEv8zBE=; b=VdwMhpUJyJ7d49Kncc8AUK+47caW2yk+O0DOzUXNBxIKMHd1k66E1lJBOhe9qxfA7Q 2zCGYbshhz/wyClGJg4A5HCnbwYqX3xedYKV+V+8CEKUpdlbiY+8UMpC9wXYkvR6keZR aObxxfGDB5sA9oLPVH8M0fLjbtYCTtpM+JymYR8sENqK6/PNQBu2n4VIbHl4UvwMwgKk TCz1+01d/FJkJqMqqLJxcukgJ3YfrHHeVZlfT79HFLe9rDOf2J+tkQiB0leFBTCHZvT5 jSaMzrFc3u8GV4ghPC1Z06THr8wy+KcShlYOV4b7um0FuuKa5np10e2uZCS1TB/70u0T WYjg== 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 l18si1885808pgn.744.2018.04.03.05.36.41; Tue, 03 Apr 2018 05:36:55 -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 S932205AbeDCMfS (ORCPT + 99 others); Tue, 3 Apr 2018 08:35:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:37393 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932104AbeDCMfQ (ORCPT ); Tue, 3 Apr 2018 08:35:16 -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 E830AAC4E; Tue, 3 Apr 2018 12:35:14 +0000 (UTC) Date: Tue, 3 Apr 2018 14:35: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: <20180403123514.GX5501@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> <20180403121614.GV5501@dhcp22.suse.cz> <20180403082348.28cd3c1c@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180403082348.28cd3c1c@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 08:23:48, Steven Rostedt wrote: > On Tue, 3 Apr 2018 14:16:14 +0200 > Michal Hocko wrote: > > > > 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. > > OK, then what do you suggest? Because currently, it appears to work. A > rough estimate may be good enough. > > If we use NORETRY, then we have those that complain that we do not try > hard enough to reclaim memory. If we use RETRY_MAYFAIL we have this > issue of taking up all memory before we get what we want. Just try to do what admin asks for and trust it will not try to shoot his foot? I mean there are other ways admin can shoot the machine down. Being clever is OK if it doesn't add a tricky code. And relying on si_mem_available is definitely tricky and obscure. > Perhaps I should try to allocate a large group of pages with > RETRY_MAYFAIL, and if that fails go back to NORETRY, with the thinking > that the large allocation may reclaim some memory that would allow the > NORETRY to succeed with smaller allocations (one page at a time)? That again relies on a subtle dependencies of the current implementation. So I would rather ask whether this is something that really deserves special treatment. If admin asks for a buffer of a certain size then try to do so. If we get OOM then bad luck you cannot get large memory buffers for free... -- Michal Hocko SUSE Labs