Re: [PATCH 10/10] mm/migrate.c: call detach_page_private to cleanup code
From: Guoqing Jiang
Date: Tue May 19 2020 - 16:44:46 EST
Hi Andrew,
On 5/19/20 9:35 AM, Guoqing Jiang wrote:
On 5/19/20 7:12 AM, Andrew Morton wrote:
On Sun, 17 May 2020 23:47:18 +0200 Guoqing Jiang
<guoqing.jiang@xxxxxxxxxxxxxxx> wrote:
We can cleanup code a little by call detach_page_private here.
...
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -804,10 +804,7 @@ static int __buffer_migrate_page(struct
address_space *mapping,
ÂÂÂÂÂ if (rc != MIGRATEPAGE_SUCCESS)
ÂÂÂÂÂÂÂÂÂ goto unlock_buffers;
 - ClearPagePrivate(page);
-ÂÂÂ set_page_private(newpage, page_private(page));
-ÂÂÂ set_page_private(page, 0);
-ÂÂÂ put_page(page);
+ÂÂÂ set_page_private(newpage, detach_page_private(page));
ÂÂÂÂÂ get_page(newpage);
 Â bh = head;
mm/migrate.c: In function '__buffer_migrate_page':
./include/linux/mm_types.h:243:52: warning: assignment makes integer
from pointer without a cast [-Wint-conversion]
 #define set_page_private(page, v) ((page)->private = (v))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
mm/migrate.c:800:2: note: in expansion of macro 'set_page_private'
ÂÂ set_page_private(newpage, detach_page_private(page));
ÂÂ ^~~~~~~~~~~~~~~~
The fact that set_page_private(detach_page_private()) generates a type
mismatch warning seems deeply wrong, surely.
Please let's get the types sorted out - either unsigned long or void *,
not half-one and half-the other. Whatever needs the least typecasting
at callsites, I suggest.
Sorry about that, I should notice the warning before. I will double
check if other
places need the typecast or not, then send a new version.
Only this patch missed the typecast. I guess I just need to send an
updated patch
to replace this one (I am fine to send a new patch set if you want),
sorry again for
the trouble.
And can we please implement set_page_private() and page_private() with
inlined C code? There is no need for these to be macros.
Just did a quick change.
-#define page_private(page)ÂÂÂÂÂÂÂÂÂÂÂÂ ((page)->private)
-#define set_page_private(page, v)ÂÂÂÂÂ ((page)->private = (v))
+static inline unsigned long page_private(struct page *page)
+{
+ÂÂÂÂÂÂ return page->private;
+}
+
+static inline void set_page_private(struct page *page, unsigned long
priv_data)
+{
+ÂÂÂÂÂÂ page->private = priv_data;
+}
Then I get error like.
fs/erofs/zdata.h: In function âz_erofs_onlinepage_indexâ:
fs/erofs/zdata.h:126:8: error: lvalue required as unary â&â operand
 u.v = &page_private(page);
ÂÂÂÂÂÂÂ ^
I guess it is better to keep page_private as macro, please correct me
in case I
missed something.
Lost of problems need to be fixed if change page_private to inline
function, so I
think it is better to keep it and only convert set_page_private.
mm/compaction.c: In function âisolate_migratepages_blockâ:
./include/linux/compiler.h:287:20: error: lvalue required as unary â&â
operand
ÂÂ __read_once_size(&(x), __u.__c, sizeof(x));Â \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
./include/linux/compiler.h:293:22: note: in expansion of macro â__READ_ONCEâ
Â#define READ_ONCE(x) __READ_ONCE(x, 1)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~~~~~
mm/internal.h:293:34: note: in expansion of macro âREAD_ONCEâ
Â#define page_order_unsafe(page)Â READ_ONCE(page_private(page))
Thanks,
Guoqing