Skip to contentSkip to conversation

mm/page_owner: Record timestamp and pid

PATCH Superseded Georgi Djakov 4 participants 8 messages Nov 12, 2020 – Nov 30, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/page_owner: Record timestamp and pid

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

---
 mm/page_owner.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
mm/page_owner.c +10 -2
index b735a8eafcdb..e6dc52db5ba5 100644
@@ -10,6 +10,7 @@
 #include <linux/migrate.h>
 #include <linux/stackdepot.h>
 #include <linux/seq_file.h>
+#include <linux/sched/clock.h>
 
 #include "internal.h"
 
@@ -25,6 +26,8 @@ struct page_owner {
 	gfp_t gfp_mask;
 	depot_stack_handle_t handle;
 	depot_stack_handle_t free_handle;
+	u64 ts_nsec;
+	int pid;
 };
 
 static bool page_owner_enabled = false;
@@ -172,6 +175,8 @@ static inline void __set_page_owner_handle(struct page *page,
 		page_owner->order = order;
 		page_owner->gfp_mask = gfp_mask;
 		page_owner->last_migrate_reason = -1;
+		page_owner->pid = current->pid;
+		page_owner->ts_nsec = local_clock();
 		__set_bit(PAGE_EXT_OWNER, &page_ext->flags);
 		__set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
 
@@ -236,6 +241,8 @@ void __copy_page_owner(struct page *oldpage, struct page *newpage)
 	new_page_owner->last_migrate_reason =
 		old_page_owner->last_migrate_reason;
 	new_page_owner->handle = old_page_owner->handle;
+	new_page_owner->pid = old_page_owner->pid;
+	new_page_owner->ts_nsec = old_page_owner->ts_nsec;
 
 	/*
 	 * We don't clear the bit on the oldpage as it's going to be freed
@@ -349,9 +356,10 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
 		return -ENOMEM;
 
 	ret = snprintf(kbuf, count,
-			"Page allocated via order %u, mask %#x(%pGg)\n",
+			"Page allocated via order %u, mask %#x(%pGg), pid %d, ts %llu ns\n",
 			page_owner->order, page_owner->gfp_mask,
-			&page_owner->gfp_mask);
+			&page_owner->gfp_mask, page_owner->pid,
+			page_owner->ts_nsec);
 
 	if (ret >= count)
 		goto err;
maintainer
#1 lore raw
Quoted 7 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful. What has it been used for, what problems has it been used to solve?

Are there userspace tools which aid in the processing of this new information?

Can/should Documentation/vm/page_owner.rst be updated?

Quoted 11 lines
mm/page_owner.c +1 -0
@@ -10,6 +10,7 @@
 #include <linux/migrate.h>
 #include <linux/stackdepot.h>
 #include <linux/seq_file.h>
+#include <linux/sched/clock.h>
 
 #include "internal.h"
 

mm/page_owner.c struct page_owner { · line 30

Quoted 5 lines
mm/page_owner.c +2 -0
@@ -25,6 +26,8 @@ struct page_owner {
 	gfp_t gfp_mask;
 	depot_stack_handle_t handle;
 	depot_stack_handle_t free_handle;
+	u64 ts_nsec;
+	int pid;

pid_t would be nicer?

#2 lore raw
Quoted 4 lines · Andrew Morton
Quoted 2 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Quoted 8 lines
Quoted 5 lines

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful. What has it been used for, what problems has it been used to solve?

Thanks for the quick feedback. I'll add more details in the commit message when i post v2 next week.

Quoted 3 lines

Are there userspace tools which aid in the processing of this new information?

I'm not aware of any.

Quoted 2 lines

Can/should Documentation/vm/page_owner.rst be updated?

Yeah, probably i should update at least the size of the objects.

Quoted 10 lines
Quoted 10 lines
mm/page_owner.c +1 -0
@@ -10,6 +10,7 @@
 #include <linux/migrate.h>
 #include <linux/stackdepot.h>
 #include <linux/seq_file.h>
+#include <linux/sched/clock.h>
 
 #include "internal.h"
 
Quoted 8 lines

mm/page_owner.c struct page_owner { · line 30

Quoted 6 lines
mm/page_owner.c +2 -0
@@ -25,6 +26,8 @@ struct page_owner {
 	gfp_t gfp_mask;
 	depot_stack_handle_t handle;
 	depot_stack_handle_t free_handle;
+	u64 ts_nsec;
+	int pid;

pid_t would be nicer?

Yes, indeed! Thank you!

BR,
Georgi

#3 lore raw
In reply to Andrew Morton
Quoted 4 lines · Andrew Morton
Quoted 2 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Quoted 8 lines
Quoted 5 lines

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful. What has it been used for, what problems has it been used to solve?

Worth noting that on x86_64 it doubles the size of struct page_owner from 16 bytes to 32, so it better be justified:

struct page_owner {

        short unsigned int         order;                /*     0     2 */
        short int                  last_migrate_reason;  /*     2     2 */
        gfp_t                      gfp_mask;             /*     4     4 */
        depot_stack_handle_t       handle;               /*     8     4 */
        depot_stack_handle_t       free_handle;          /*    12     4 */
        u64                        ts_nsec;              /*    16     8 */
        int                        pid;                  /*    24     4 */
        /* size: 32, cachelines: 1, members: 7 */
        /* padding: 4 */
        /* last cacheline: 32 bytes */
};
Quoted 26 lines

Are there userspace tools which aid in the processing of this new information?

Can/should Documentation/vm/page_owner.rst be updated?

Quoted 11 lines
mm/page_owner.c +1 -0
@@ -10,6 +10,7 @@
 #include <linux/migrate.h>
 #include <linux/stackdepot.h>
 #include <linux/seq_file.h>
+#include <linux/sched/clock.h>
 
 #include "internal.h"
 

mm/page_owner.c struct page_owner { · line 30

Quoted 5 lines
mm/page_owner.c +2 -0
@@ -25,6 +26,8 @@ struct page_owner {
 	gfp_t gfp_mask;
 	depot_stack_handle_t handle;
 	depot_stack_handle_t free_handle;
+	u64 ts_nsec;
+	int pid;

pid_t would be nicer?

#4 lore raw

Hi Vlastimil,

Thanks for the comment!

Quoted 8 lines · Vlastimil Babka
Quoted 7 lines · Andrew Morton
Quoted 5 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful.  What has it been used for, what problems has it been used to solve?

Worth noting that on x86_64 it doubles the size of struct page_owner from 16 bytes to 32, so it better be justified:

Well, that's true. But for debug options there is almost always some penalty. The timestamp and pid information is very useful for me (and others, i believe) when doing memory analysis. On a crash for example, we can get this information from kdump (or RAM-dump) and look into it to catch memory allocation problems more easily.

If you find the above argument not strong enough, how about a separate config option for this? Maybe something like CONFIG_PAGE_OWNER_EXTENDED, which could be enabled in addition to CONFIG_PAGE_OWNER?

Thanks,
Georgi

Quoted 15 lines

struct page_owner {
        short unsigned int         order;                /*     0     2 */ short int                  last_migrate_reason;  /*     2     2 */ gfp_t                      gfp_mask;             /*     4     4 */ depot_stack_handle_t       handle;               /*     8     4 */ depot_stack_handle_t       free_handle;          /*    12     4 */ u64                        ts_nsec;              /*    16     8 */ int                        pid;                  /*    24     4 */

        /* size: 32, cachelines: 1, members: 7 */ /* padding: 4 */
        /* last cacheline: 32 bytes */
};

#5 lore raw
Quoted 19 lines · Georgi Djakov

Hi Vlastimil,

Thanks for the comment!

Quoted 14 lines · Vlastimil Babka
Quoted 12 lines · Andrew Morton
Quoted 7 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful.  What has it been used for, what problems has it been used to solve?

Quoted 8 lines
Quoted 2 lines

Worth noting that on x86_64 it doubles the size of struct page_owner from 16 bytes to 32, so it better be justified:

Well, that's true. But for debug options there is almost always some penalty. The timestamp and pid information is very useful for me (and others, i believe) when doing memory analysis. On a crash for example, we can get this information from kdump (or RAM-dump) and look into it to catch memory allocation problems more easily.

Right. Btw, you should add printing the info to __dump_page_owner().

Quoted 3 lines

If you find the above argument not strong enough, how about a separate config option for this? Maybe something like CONFIG_PAGE_OWNER_EXTENDED, which could be enabled in addition to CONFIG_PAGE_OWNER?

It might be strong enough if it's mentioned in changelog, and also what exactly the space tradeoff is :)

You can also mention that SLUB object tracking has also pid+timestamp.

Quoted 19 lines

Thanks,
Georgi

Quoted 15 lines

struct page_owner {
        short unsigned int         order;                /*     0     2 */ short int                  last_migrate_reason;  /*     2     2 */ gfp_t                      gfp_mask;             /*     4     4 */ depot_stack_handle_t       handle;               /*     8     4 */ depot_stack_handle_t       free_handle;          /*    12     4 */ u64                        ts_nsec;              /*    16     8 */ int                        pid;                  /*    24     4 */

        /* size: 32, cachelines: 1, members: 7 */ /* padding: 4 */
        /* last cacheline: 32 bytes */
};

#6 lore raw
Quoted 31 lines · Vlastimil Babka
Quoted 20 lines · Georgi Djakov

Hi Vlastimil,

Thanks for the comment!

Quoted 15 lines · Vlastimil Babka
Quoted 13 lines · Andrew Morton
Quoted 7 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful. What has it been used for, what problems has it been used to solve?

Quoted 8 lines
Quoted 2 lines

Worth noting that on x86_64 it doubles the size of struct page_owner from 16 bytes to 32, so it better be justified:

Well, that's true. But for debug options there is almost always some penalty. The timestamp and pid information is very useful for me (and others, i believe) when doing memory analysis. On a crash for example, we can get this information from kdump (or RAM-dump) and look into it to catch memory allocation problems more easily.

Quoted 8 lines

Right. Btw, you should add printing the info to __dump_page_owner().

Quoted 3 lines

If you find the above argument not strong enough, how about a separate config option for this? Maybe something like CONFIG_PAGE_OWNER_EXTENDED, which could be enabled in addition to CONFIG_PAGE_OWNER?

It might be strong enough if it's mentioned in changelog, and also what exactly the space tradeoff is :)

Just a thought ... putting it inside CONFIG_PAGE_OWNER_DEBUG might be better if it is used
purely for debugging purposes.

Quoted 24 lines

You can also mention that SLUB object tracking has also pid+timestamp.

Quoted 19 lines

Thanks,
Georgi

Quoted 15 lines

struct page_owner {

         short unsigned int         order;                /*     0     2 */
         short int                  last_migrate_reason;  /*     2     2 */
         gfp_t                      gfp_mask;             /*     4     4 */
         depot_stack_handle_t       handle;               /*     8     4 */
         depot_stack_handle_t       free_handle;          /*    12     4 */
         u64                        ts_nsec;              /*    16     8 */
         int                        pid;                  /*    24     4 */
         /* size: 32, cachelines: 1, members: 7 */
         /* padding: 4 */
         /* last cacheline: 32 bytes */
};
#7 lore raw
Quoted 38 lines · Souptick Joarder
Quoted 37 lines · Vlastimil Babka
Quoted 20 lines · Georgi Djakov

Hi Vlastimil,

Thanks for the comment!

Quoted 15 lines · Vlastimil Babka
Quoted 13 lines · Andrew Morton
Quoted 7 lines · On Thu, 12 Nov 2020 20:41:06 +0200 Georgi Djakov <[email protected]>…

From: Liam Mark <[email protected]>

Collect the time for each allocation recorded in page owner so that allocation "surges" can be measured.

Record the pid for each allocation recorded in page owner so that the source of allocation "surges" can be better identified.

Please provide a description of why this is considered useful. What has it been used for, what problems has it been used to solve?

Quoted 8 lines
Quoted 2 lines

Worth noting that on x86_64 it doubles the size of struct page_owner from 16 bytes to 32, so it better be justified:

Well, that's true. But for debug options there is almost always some penalty. The timestamp and pid information is very useful for me (and others, i believe) when doing memory analysis. On a crash for example, we can get this information from kdump (or RAM-dump) and look into it to catch memory allocation problems more easily.

Right. Btw, you should add printing the info to __dump_page_owner().

Quoted 3 lines

If you find the above argument not strong enough, how about a separate config option for this? Maybe something like CONFIG_PAGE_OWNER_EXTENDED, which could be enabled in addition to CONFIG_PAGE_OWNER?

Quoted 6 lines
Quoted 2 lines

It might be strong enough if it's mentioned in changelog, and also what exactly the space tradeoff is :)

Just a thought ... putting it inside CONFIG_PAGE_OWNER_DEBUG might be better if it is used
purely for debugging purposes.

I don't think we need to introduce new config just yet, until someone makes the case for it. Even then, it could be instead doable as an extension to "page_owner=on" boot option. I mean let's add those fields, but improve the changelog.

Quoted 25 lines
Quoted 24 lines

You can also mention that SLUB object tracking has also pid+timestamp.

Quoted 19 lines

Thanks,
Georgi

Quoted 15 lines

struct page_owner {

         short unsigned int         order;                /*     0     2 */
         short int                  last_migrate_reason;  /*     2     2 */
         gfp_t                      gfp_mask;             /*     4     4 */
         depot_stack_handle_t       handle;               /*     8     4 */
         depot_stack_handle_t       free_handle;          /*    12     4 */
         u64                        ts_nsec;              /*    16     8 */
         int                        pid;                  /*    24     4 */
         /* size: 32, cachelines: 1, members: 7 */
         /* padding: 4 */
         /* last cacheline: 32 bytes */
};