Re: [PATCH] mm: Fix compile error when CONFIG_SHMEM is not set

From: Steven Rostedt
Date: Mon Jun 02 2025 - 17:13:57 EST


On Mon, 2 Jun 2025 17:05:00 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> From: Steven Rostedt <rostedt@xxxxxxxxxxx>
>
> When CONFIG_SHMEM is not set, the following compiler error occurs:
>
> ld: vmlinux.o: in function `ttm_backup_backup_page':

Actually, I was looking at the wrong location and not at ttm_backup_backup_page().

Which commit fe75adffac33e ("ttm: Call shmem_writeout() from
ttm_backup_backup_page()") updates as:

diff --git a/drivers/gpu/drm/ttm/ttm_backup.c b/drivers/gpu/drm/ttm/ttm_backup.c
index 93c007f18855..0d5718466ffc 100644
--- a/drivers/gpu/drm/ttm/ttm_backup.c
+++ b/drivers/gpu/drm/ttm/ttm_backup.c
@@ -136,13 +136,13 @@ ttm_backup_backup_page(struct ttm_backup *backup, struct page *page,
.for_reclaim = 1,
};
folio_set_reclaim(to_folio);
- ret = mapping->a_ops->writepage(folio_file_page(to_folio, idx), &wbc);
+ ret = shmem_writeout(to_folio, &wbc);
if (!folio_test_writeback(to_folio))
folio_clear_reclaim(to_folio);
/*
- * If writepage succeeds, it unlocks the folio.
- * writepage() errors are otherwise dropped, since writepage()
- * is only best effort here.
+ * If writeout succeeds, it unlocks the folio. errors
+ * are otherwise dropped, since writeout is only best
+ * effort here.
*/
if (ret)
folio_unlock(to_folio);

I'm not sure this is the right fix or not.


> (.text+0x10363bc): undefined reference to `shmem_writeout'
> make[3]: *** [/work/build/trace/nobackup/linux-test.git/scripts/Makefile.vmlinux:91: vmlinux.unstripped] Error 1
> make[2]: *** [/work/build/trace/nobackup/linux-test.git/Makefile:1241: vmlinux] Error 2
> make[1]: *** [/work/build/trace/nobackup/linux-test.git/Makefile:248: __sub-make] Error 2
> make[1]: Leaving directory '/work/build/nobackup/tracetest'
> make: *** [Makefile:248: __sub-make] Error 2
>
> This is due to the replacement of writepage and calling swap_writepage()
> and shmem_writepage() directly. The issue is that when CONFIG_SHMEM is not
> defined, shmem_writepage() is also not defined. Add it as a stub, and it
> should also never be called when CONFIG_SHMEM is undefined.
>
> Fixes: 84798514db50 ("mm: Remove swap_writepage() and shmem_writepage()")
> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
> ---
> mm/shmem.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 858cee02ca49..dec85388030a 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -5760,6 +5760,11 @@ void shmem_unlock_mapping(struct address_space *mapping)
> {
> }
>
> +int shmem_writeout(struct folio *folio, struct writeback_control *wbc)
> +{
> + return 0;

Perhaps this should return:

return swap_writeout(folio, wbc);

?

-- Steve

> +}
> +
> #ifdef CONFIG_MMU
> unsigned long shmem_get_unmapped_area(struct file *file,
> unsigned long addr, unsigned long len,