[Crash-utility] Re: [PATCH] remove struct zspage_5_17 and use union to resolve issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Tao, Lianbo

Patch v3 attached.

Thanks
Guanyou.Chen

Lianbo Jiang <lijiang@xxxxxxxxxx> 于2024年5月10日周五 11:21写道:
Hi, Chenguanyou

Thank you for the patch.

Can you post the v2 with plain text? Or did I miss anything?


Thanks

Lianbo

On 4/24/24 20:13, devel-request@xxxxxxxxxxxxxxxxxxxxxxxxxxx wrote:
> Date: Wed, 24 Apr 2024 17:23:55 +0800
> From: Guanyou Chen<chenguanyou9338@xxxxxxxxx>
> Subject: [PATCH] remove struct zspage_5_17 and use
>       union to resolve issue
> To: Lianbo<lijiang@xxxxxxxxxx>,devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx,
>       k-hagio-ab@xxxxxxx
> Message-ID:
>       <CAHS3RMVjQ7bBG4cnrdzswsAGrNeRW30AaPtVzXNJ3XHHyb+8+A@xxxxxxxxxxxxxx>
> Content-Type: multipart/mixed; boundary="00000000000072ca390616d43bfc"
>
> --00000000000072ca390616d43bfc
> Content-Type: multipart/alternative; boundary="00000000000072ca370616d43bfa"
>
> --00000000000072ca370616d43bfa
> Content-Type: text/plain; charset="UTF-8"
>
> Hi LianBo
>
> We don't need struct zspage_5_17.
>
> ---
>   defs.h     | 32 +++++++++++++++-----------------
>   diskdump.c | 15 ++++++---------
>   2 files changed, 21 insertions(+), 26 deletions(-)

From 873a736c36e3ec5902a58abb9924e54c348ce1a5 Mon Sep 17 00:00:00 2001
From: chenguanyou <chenguanyou@xxxxxxxxxx>
Date: Wed, 24 Apr 2024 17:00:20 +0800
Subject: [PATCH v3] remove struct zspage_5_17 and use union to resolve issue

This patch is a refactoring on commit [1], and has no functional
change. The reason is that the structure of zspage has not changed,
just new bits have been introduced. So a union is better to reduce
code replication.

[1] 0172e35083b5 ("Fix "rd" command to display data on zram on Linux 5.17 and later")

Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
---
 defs.h     | 32 +++++++++++++++-----------------
 diskdump.c | 15 ++++++---------
 2 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/defs.h b/defs.h
index 3cb8e63..01f316e 100644
--- a/defs.h
+++ b/defs.h
@@ -7407,28 +7407,26 @@ ulong try_zram_decompress(ulonglong pte_val, unsigned char *buf, ulong len, ulon
 #define SECTORS_PER_PAGE        (1 << SECTORS_PER_PAGE_SHIFT)
 
 struct zspage {
-    struct {
-        unsigned int fullness : 2;
-        unsigned int class : 9;
-        unsigned int isolated : 3;
-        unsigned int magic : 8;
+    union {
+        unsigned int flag_bits;
+        struct {
+            unsigned int fullness : 2;
+            unsigned int class : 9;
+            unsigned int isolated : 3;
+            unsigned int magic : 8;
+        } v0;
+        struct {
+            unsigned int huge : 1;
+            unsigned int fullness : 2;
+            unsigned int class : 9;
+            unsigned int isolated : 3;
+            unsigned int magic : 8;
+        } v5_17;
     };
     unsigned int inuse;
     unsigned int freeobj;
 };
 
-struct zspage_5_17 {
-	struct {
-		unsigned int huge : 1;
-		unsigned int fullness : 2;
-		unsigned int class : 9;
-		unsigned int isolated : 3;
-		unsigned int magic : 8;
-	};
-	unsigned int inuse;
-	unsigned int freeobj;
-};
-
 /*
  * makedumpfile.c
  */
diff --git a/diskdump.c b/diskdump.c
index 3ae7bf2..e87c40f 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2819,7 +2819,6 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
 {
 	ulong obj, off, class, page, zspage;
 	struct zspage zspage_s;
-	struct zspage_5_17 zspage_5_17_s;
 	physaddr_t paddr;
 	unsigned int obj_idx, class_idx, size;
 	ulong pages[2], sizes[2];
@@ -2833,15 +2832,13 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
 	readmem(page + OFFSET(page_private), KVADDR, &zspage,
 			sizeof(void *), "page_private", FAULT_ON_ERROR);
 
+	readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
 	if (VALID_MEMBER(zspage_huge)) {
-		readmem(zspage, KVADDR, &zspage_5_17_s,
-			sizeof(struct zspage_5_17), "zspage_5_17", FAULT_ON_ERROR);
-		class_idx = zspage_5_17_s.class;
-		zs_magic = zspage_5_17_s.magic;
+		class_idx = zspage_s.v5_17.class;
+		zs_magic = zspage_s.v5_17.magic;
 	} else {
-		readmem(zspage, KVADDR, &zspage_s, sizeof(struct zspage), "zspage", FAULT_ON_ERROR);
-		class_idx = zspage_s.class;
-		zs_magic = zspage_s.magic;
+		class_idx = zspage_s.v0.class;
+		zs_magic = zspage_s.v0.magic;
 	}
 
 	if (zs_magic != ZSPAGE_MAGIC)
@@ -2887,7 +2884,7 @@ zram_object_addr(ulong pool, ulong handle, unsigned char *zram_buf)
 
 out:
 	if (VALID_MEMBER(zspage_huge)) {
-		if (!zspage_5_17_s.huge)
+		if (!zspage_s.v5_17.huge)
 			return (zram_buf + ZS_HANDLE_SIZE);
 	} else {
 		readmem(page, KVADDR, &obj, sizeof(void *), "page flags", FAULT_ON_ERROR);
-- 
2.39.0

--
Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux