Commit de63c0e3 authored by Audra Mitchell's avatar Audra Mitchell Committed by Jinjiang Tu
Browse files

tools/mm: filter out timestamps for correct collation

mainline inclusion
from mainline-v6.7-rc1
commit 63a150623a2bf94c9ed503719a3423675a3aa0d3
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8XGY0
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=63a150623a2bf94c9ed503719a3423675a3aa0d3

-------------------------------------------

With the introduction of allocation timestamps being included in
page_owner output, each record becomes unique due to the timestamp
nanosecond granularity.  Remove the check in add_list that tries to
collate each record during processing as the memcmp() is just additional
overhead at this point.

Also keep the allocation timestamps, but allow collation to occur without
consideration of the allocation timestamp except in the case were
allocation timestamps are requested by the user (the -a option).

Link: https://lkml.kernel.org/r/20231013190350.579407-4-audra@redhat.com


Signed-off-by: default avatarAudra Mitchell <audra@redhat.com>
Acked-by: default avatarRafael Aquini <aquini@redhat.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Georgi Djakov <djakov@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJinjiang Tu <tujinjiang@huawei.com>
parent 5dc8025d
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -203,6 +203,21 @@ static int compare_sort_condition(const void *p1, const void *p2)
	return cmp;
}

static int remove_pattern(regex_t *pattern, char *buf, int len)
{
	regmatch_t pmatch[2];
	int err;

	err = regexec(pattern, buf, 2, pmatch, REG_NOTBOL);
	if (err != 0 || pmatch[1].rm_so == -1)
		return len;

	memcpy(buf + pmatch[1].rm_so,
		buf + pmatch[1].rm_eo, len - pmatch[1].rm_eo);

	return len - (pmatch[1].rm_eo - pmatch[1].rm_so);
}

static int search_pattern(regex_t *pattern, char *pattern_str, char *buf)
{
	int err, val_len;
@@ -443,13 +458,6 @@ static bool is_need(char *buf)

static bool add_list(char *buf, int len, char *ext_buf)
{
	if (list_size != 0 &&
		len == list[list_size-1].len &&
		memcmp(buf, list[list_size-1].txt, len) == 0) {
		list[list_size-1].num++;
		list[list_size-1].page_num += get_page_num(buf);
		return true;
	}
	if (list_size == max_size) {
		fprintf(stderr, "max_size too small??\n");
		return false;
@@ -465,6 +473,9 @@ static bool add_list(char *buf, int len, char *ext_buf)
		return false;
	}
	memcpy(list[list_size].txt, buf, len);
	if (sc.cmps[0] != compare_ts) {
		len = remove_pattern(&ts_nsec_pattern, list[list_size].txt, len);
	}
	list[list_size].txt[len] = 0;
	list[list_size].len = len;
	list[list_size].num = 1;