Received: by 10.213.65.68 with SMTP id h4csp3457365imn; Tue, 3 Apr 2018 05:25:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+iHv6DPgQbfVh/T6yR7EkvwEvCl9XJNxXhc3qdTNe0lT1euIMSrybmJpK4CJS4cS2NTIuo X-Received: by 2002:a17:902:3225:: with SMTP id y34-v6mr14416603plb.180.1522758315146; Tue, 03 Apr 2018 05:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522758315; cv=none; d=google.com; s=arc-20160816; b=YUYOzZKOhX3a+USH49bUOys5A/c2Q79gneVlB2wW9Nlphc09HiSr/gHIdlRDoU3xFr C0BNDhivnQ2XlG+qusLLF5hQe9o1uWGrt0nfrWT/8vewZ5WbetAPlnWsQtMufZ4UpBvv 8bdrWQHgBRDYpVbMKT3HzovfeyKlzrT/hlXNcHgPYEk8GQ1NqKacyTXec1EnXJ5eoWl0 Ng9j/iQdd2dhVlZkSpsy2a46ZqzJYXSbfeYjwQor9I5F33liQNHDHdmKlk0JR3ojVeiK Ll0qMGp8s0v/JwxrmlebGalAJNyJmQgoIzi/yT+Xa7hkBRhtA7g5gMQgYNvjhe9EVzKb ECTA== 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=IuCc1qAABKlFFv/rBNHaN7T3i6qqjO01ZvXCQh5jQ+s=; b=rFQyTOQC7jC78UGIW+jU4dUKqWmAsdecw5nFegw31jLpP1QA6yZG/raMVw/Fn+GB+X xyA6Z5dBMs22I/kyEuwMMq9gACRqND13XKO7T6ZQ7Qo+joHRLopqxgnINyVf44xu1UoP 0IE209ZrQ13LApPgm5ZtCabO49Ou+OMQB+d13qkXJXh47tjnrnjsm5+w87wmnur/Y2ml jTwfeLoo4jvfKp6eFicLuorfc0c4zVNpWmFXD9vgc1KHLrzy6l61nW/9jsd2F7mYD2OA NA3GHsibZjhW9zTTJA03sSGObav81yuU2+d0ISuT5sR1x5cZZhdpHRfZgN872Wf6OVpa vtkQ== 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.25.01; Tue, 03 Apr 2018 05:25:15 -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 S1755504AbeDCMXw (ORCPT + 99 others); Tue, 3 Apr 2018 08:23:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:51352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755300AbeDCMXv (ORCPT ); Tue, 3 Apr 2018 08:23:51 -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 366342133F; Tue, 3 Apr 2018 12:23:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 366342133F 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: Tue, 3 Apr 2018 08:23:48 -0400 From: Steven Rostedt To: Michal Hocko 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: <20180403082348.28cd3c1c@gandalf.local.home> In-Reply-To: <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> <20180403121614.GV5501@dhcp22.suse.cz> 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 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. 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)? -- Steve