linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <koct9i@gmail.com>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Joe Perches <joe@perches.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sam Varshavchik <mrsam@courier-mta.com>,
	Ingo Molnar <mingo@kernel.org>, Laura Abbott <labbott@redhat.com>,
	Brent <fix@bitrealm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [REGRESSION] RLIMIT_DATA crashes named
Date: Sun, 18 Sep 2016 00:40:37 +0300	[thread overview]
Message-ID: <CALYGNiN-ELbwSV0X2_FeKvGSOfRuHMsBnBDj86NHZxQKnZgVsQ@mail.gmail.com> (raw)
In-Reply-To: <20160917122021.GC26044@uranus.lan>

[-- Attachment #1: Type: text/plain, Size: 1163 bytes --]

On Sat, Sep 17, 2016 at 3:20 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> On Sat, Sep 17, 2016 at 03:09:09PM +0300, Konstantin Khlebnikov wrote:
>> >
>> > Seems I don't understand the bottom unlikely...
>>
>> This is gcc extrension:  https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
>> Here macro works as a function which returns bool
>
> no, no, I know for what unlikely extension stand for.
> it was just hard to obtain from without the context.
> this extension implies someone calls for
> if (printk_periodic()) right?

Yep.


Here is perfect macro for that jiffies check: time_in_range_open.

/*
 * Calculate whether a is in the range of [b, c).
 */
#define time_in_range_open(a,b,c) \
(time_after_eq(a,b) && \
time_before(a,c))

So... better version looks like

#define printk_periodic(period, fmt, ...)
({
        static unsigned long __prev __read_mostly = INITIAL_JIFFIES - (period);
        unsigned long __now = jiffies;
        bool __print = !time_in_range_open(__now, __prev, __prev + (period));

        if (__print) {
                __prev = __now;
                printk(fmt, ##__VA_ARGS__);
        }
        unlikely(__print);
})

[-- Attachment #2: printk-add-pr_warn_once_per_minute --]
[-- Type: application/octet-stream, Size: 2310 bytes --]

printk: add pr_warn_once_per_minute

From: Konstantin Khlebnikov <koct9i@gmail.com>

Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
---
 include/linux/printk.h |   17 +++++++++++++++++
 mm/mmap.c              |    2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 696a56be7d3e..372984b6645b 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -341,11 +341,25 @@ extern asmlinkage void dump_stack(void) __cold;
 	}							\
 	unlikely(__ret_print_once);				\
 })
+#define printk_periodic(period, fmt, ...)			\
+({								\
+	static unsigned long __prev __read_mostly = INITIAL_JIFFIES - (period); \
+	unsigned long __now = jiffies;				\
+	bool __print = !time_in_range_open(__now, __prev, __prev + (period)); \
+								\
+	if (__print) {						\
+		__prev = __now;					\
+		printk(fmt, ##__VA_ARGS__);			\
+	}							\
+	unlikely(__print);					\
+})
 #else
 #define printk_once(fmt, ...)					\
 	no_printk(fmt, ##__VA_ARGS__)
 #define printk_deferred_once(fmt, ...)				\
 	no_printk(fmt, ##__VA_ARGS__)
+#define printk_periodic(period, fmt, ...)			\
+	no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 #define pr_emerg_once(fmt, ...)					\
@@ -365,6 +379,9 @@ extern asmlinkage void dump_stack(void) __cold;
 #define pr_cont_once(fmt, ...)					\
 	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
 
+#define pr_warn_once_per_minute(fmt, ...)			\
+	printk_periodic(HZ * 60, KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+
 #if defined(DEBUG)
 #define pr_devel_once(fmt, ...)					\
 	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
diff --git a/mm/mmap.c b/mm/mmap.c
index ca9d91bca0d6..34f9fb2adcab 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2935,7 +2935,7 @@ bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages)
 		    mm->data_vm + npages <= rlimit_max(RLIMIT_DATA) >> PAGE_SHIFT)
 			return true;
 		if (!ignore_rlimit_data) {
-			pr_warn_once("%s (%d): VmData %lu exceed data ulimit %lu. Update limits or use boot option ignore_rlimit_data.\n",
+			pr_warn_once_per_minute("%s (%d): VmData %lu exceed data ulimit %lu. Update limits or use boot option ignore_rlimit_data.\n",
 				     current->comm, current->pid,
 				     (mm->data_vm + npages) << PAGE_SHIFT,
 				     rlimit(RLIMIT_DATA));

  reply	other threads:[~2016-09-17 21:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16 15:16 Laura Abbott
2016-09-16 17:46 ` Linus Torvalds
2016-09-16 20:10   ` Laura Abbott
2016-09-16 20:32     ` Linus Torvalds
2016-09-16 22:30       ` Sam Varshavchik
2016-09-16 23:58         ` Linus Torvalds
2016-09-17  0:04           ` Linus Torvalds
2016-09-17  4:08             ` Joe Perches
2016-09-17  8:33               ` Konstantin Khlebnikov
2016-09-17  9:09                 ` Cyrill Gorcunov
2016-09-17 12:09                   ` Konstantin Khlebnikov
2016-09-17 12:20                     ` Cyrill Gorcunov
2016-09-17 21:40                       ` Konstantin Khlebnikov [this message]
2016-09-17 21:52                         ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALYGNiN-ELbwSV0X2_FeKvGSOfRuHMsBnBDj86NHZxQKnZgVsQ@mail.gmail.com \
    --to=koct9i@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=borntraeger@de.ibm.com \
    --cc=fix@bitrealm.com \
    --cc=gorcunov@gmail.com \
    --cc=joe@perches.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=mrsam@courier-mta.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox