diff mbox series

[-V3,1/8] migrate: fix syscall move_pages() return value for failure

Message ID 20220817081408.513338-2-ying.huang@intel.com (mailing list archive)
State New
Headers show
Series [-V3,1/8] migrate: fix syscall move_pages() return value for failure | expand

Commit Message

Huang, Ying Aug. 17, 2022, 8:14 a.m. UTC
The return value of move_pages() syscall is incorrect when counting
the remaining pages to be migrated.  For example, for the following
test program,

"
 #define _GNU_SOURCE

 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>

 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <numaif.h>
 #include <numa.h>

 #ifndef MADV_FREE
 #define MADV_FREE	8		/* free pages only if memory pressure */
 #endif

 #define ONE_MB		(1024 * 1024)
 #define MAP_SIZE	(16 * ONE_MB)
 #define THP_SIZE	(2 * ONE_MB)
 #define THP_MASK	(THP_SIZE - 1)

 #define ERR_EXIT_ON(cond, msg)					\
	 do {							\
		 int __cond_in_macro = (cond);			\
		 if (__cond_in_macro)				\
			 error_exit(__cond_in_macro, (msg));	\
	 } while (0)

 void error_msg(int ret, int nr, int *status, const char *msg)
 {
	 int i;

	 fprintf(stderr, "Error: %s, ret : %d, error: %s\n",
		 msg, ret, strerror(errno));

	 if (!nr)
		 return;
	 fprintf(stderr, "status: ");
	 for (i = 0; i < nr; i++)
		 fprintf(stderr, "%d ", status[i]);
	 fprintf(stderr, "\n");
 }

 void error_exit(int ret, const char *msg)
 {
	 error_msg(ret, 0, NULL, msg);
	 exit(1);
 }

 int page_size;

 bool do_vmsplice;
 bool do_thp;

 static int pipe_fds[2];
 void *addr;
 char *pn;
 char *pn1;
 void *pages[2];
 int status[2];

 void prepare()
 {
	 int ret;
	 struct iovec iov;

	 if (addr) {
		 munmap(addr, MAP_SIZE);
		 close(pipe_fds[0]);
		 close(pipe_fds[1]);
	 }

	 ret = pipe(pipe_fds);
	 ERR_EXIT_ON(ret, "pipe");

	 addr = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE,
		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	 ERR_EXIT_ON(addr == MAP_FAILED, "mmap");
	 if (do_thp) {
		 ret = madvise(addr, MAP_SIZE, MADV_HUGEPAGE);
		 ERR_EXIT_ON(ret, "advise hugepage");
	 }

	 pn = (char *)(((unsigned long)addr + THP_SIZE) & ~THP_MASK);
	 pn1 = pn + THP_SIZE;
	 pages[0] = pn;
	 pages[1] = pn1;
	 *pn = 1;

	 if (do_vmsplice) {
		 iov.iov_base = pn;
		 iov.iov_len = page_size;
		 ret = vmsplice(pipe_fds[1], &iov, 1, 0);
		 ERR_EXIT_ON(ret < 0, "vmsplice");
	 }

	 status[0] = status[1] = 1024;
 }

 void test_migrate()
 {
	 int ret;
	 int nodes[2] = { 1, 1 };
	 pid_t pid = getpid();

	 prepare();
	 ret = move_pages(pid, 1, pages, nodes, status, MPOL_MF_MOVE_ALL);
	 error_msg(ret, 1, status, "move 1 page");

	 prepare();
	 ret = move_pages(pid, 2, pages, nodes, status, MPOL_MF_MOVE_ALL);
	 error_msg(ret, 2, status, "move 2 pages, page 1 not mapped");

	 prepare();
	 *pn1 = 1;
	 ret = move_pages(pid, 2, pages, nodes, status, MPOL_MF_MOVE_ALL);
	 error_msg(ret, 2, status, "move 2 pages");

	 prepare();
	 *pn1 = 1;
	 nodes[1] = 0;
	 ret = move_pages(pid, 2, pages, nodes, status, MPOL_MF_MOVE_ALL);
	 error_msg(ret, 2, status, "move 2 pages, page 1 to node 0");
 }

 int main(int argc, char *argv[])
 {
	 numa_run_on_node(0);
	 page_size = getpagesize();

	 test_migrate();

	 fprintf(stderr, "\nMake page 0 cannot be migrated:\n");
	 do_vmsplice = true;
	 test_migrate();

	 fprintf(stderr, "\nTest THP:\n");
	 do_thp = true;
	 do_vmsplice = false;
	 test_migrate();

	 fprintf(stderr, "\nTHP: make page 0 cannot be migrated:\n");
	 do_vmsplice = true;
	 test_migrate();

	 return 0;
 }
"

The output of the current kernel is,

"
Error: move 1 page, ret : 0, error: Success
status: 1
Error: move 2 pages, page 1 not mapped, ret : 0, error: Success
status: 1 -14
Error: move 2 pages, ret : 0, error: Success
status: 1 1
Error: move 2 pages, page 1 to node 0, ret : 0, error: Success
status: 1 0

Make page 0 cannot be migrated:
Error: move 1 page, ret : 0, error: Success
status: 1024
Error: move 2 pages, page 1 not mapped, ret : 1, error: Success
status: 1024 -14
Error: move 2 pages, ret : 0, error: Success
status: 1024 1024
Error: move 2 pages, page 1 to node 0, ret : 1, error: Success
status: 1024 1024
"

While the expected output is,

"
Error: move 1 page, ret : 0, error: Success
status: 1
Error: move 2 pages, page 1 not mapped, ret : 0, error: Success
status: 1 -14
Error: move 2 pages, ret : 0, error: Success
status: 1 1
Error: move 2 pages, page 1 to node 0, ret : 0, error: Success
status: 1 0

Make page 0 cannot be migrated:
Error: move 1 page, ret : 1, error: Success
status: 1024
Error: move 2 pages, page 1 not mapped, ret : 1, error: Success
status: 1024 -14
Error: move 2 pages, ret : 1, error: Success
status: 1024 1024
Error: move 2 pages, page 1 to node 0, ret : 2, error: Success
status: 1024 1024
"

Fix this via correcting the remaining pages counting.  With the fix,
the output for the test program as above is expected.

Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Fixes: 5984fabb6e82 ("mm: move_pages: report the number of non-attempted pages")
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Yang Shi <shy828301@gmail.com>
---
 mm/migrate.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Ryan Roberts July 26, 2023, 10:15 a.m. UTC | #1
On 17/08/2022 09:14, Huang Ying wrote:
> The return value of move_pages() syscall is incorrect when counting
> the remaining pages to be migrated.

Hi Huang, Alistair,

I've noticed that this patch from Huang has caused the mm/migration selftest (authored by Alistair) to start failing (see bisection log below).

Of the 3 tests, migration.private_anon and migration.private_anon_thp continue to pass, but migration.shared_anon fails:


  #  RUN           migration.shared_anon ...
  Didn't migrate 1 pages
  # migration.c:167:shared_anon:Expected migrate(ptr, self->n1, self->n2) (-2) == 0 (0)
  # shared_anon: Test terminated by assertion
  #          FAIL  migration.shared_anon
  not ok 2 migration.shared_anon


The failure occurs due to the return code of move_pages() and this patch has changed the return code handling in the kernel, so it makes sense:


int migrate(uint64_t *ptr, int n1, int n2)
{
	int ret, tmp;
	int status = 0;
	struct timespec ts1, ts2;

	if (clock_gettime(CLOCK_MONOTONIC, &ts1))
		return -1;

	while (1) {
		if (clock_gettime(CLOCK_MONOTONIC, &ts2))
			return -1;

		if (ts2.tv_sec - ts1.tv_sec >= RUNTIME)
			return 0;

		ret = move_pages(0, 1, (void **) &ptr, &n2, &status,
				MPOL_MF_MOVE_ALL);
		if (ret) {
			if (ret > 0)
				printf("Didn't migrate %d pages\n", ret); <<<< HERE
			else
				perror("Couldn't migrate pages");
			return -2;
		}

		tmp = n2;
		n2 = n1;
		n1 = tmp;
	}

	return 0;
}


I haven't looked any further and am not sure what the correct fix is. I wondered if either you might be able to offer a solution?

Thanks,
Ryan


git bisect start
# bad: [6eaae198076080886b9e7d57f4ae06fa782f90ef] Linux 6.5-rc3
git bisect bad 6eaae198076080886b9e7d57f4ae06fa782f90ef
# good: [2c85ebc57b3e1817b6ce1a6b703928e113a90442] Linux 5.10
git bisect good 2c85ebc57b3e1817b6ce1a6b703928e113a90442
# good: [d710d370c4911e83da5d2bc43d4a2c3b56bd27e7] Merge tag 's390-5.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
git bisect good d710d370c4911e83da5d2bc43d4a2c3b56bd27e7
# bad: [8715c6d3100fc7c6edddf29af4a399a1c12d028c] Merge tag 'for-6.2/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
git bisect bad 8715c6d3100fc7c6edddf29af4a399a1c12d028c
# good: [12b68040a5e468068fd7f4af1150eab8f6e96235] Merge tag 'media/v5.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
git bisect good 12b68040a5e468068fd7f4af1150eab8f6e96235
# good: [7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf] Merge tag 'drm-next-2022-10-05' of git://anongit.freedesktop.org/drm/drm
git bisect good 7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf
# bad: [524d0c68826bc1adf9d1946e540eb4f7b16699a7] Merge tag 'ceph-for-6.1-rc1' of https://github.com/ceph/ceph-client
git bisect bad 524d0c68826bc1adf9d1946e540eb4f7b16699a7
# good: [29926f1cd3535f565f200430d5b6a794543fe130] fbdev: mb862xx: Fix check of return value from irq_of_parse_and_map()
git bisect good 29926f1cd3535f565f200430d5b6a794543fe130
# good: [d4013bc4d49f6da8178a340348369bb9920225c9] Merge tag 'bitmap-6.1-rc1' of https://github.com/norov/linux
git bisect good d4013bc4d49f6da8178a340348369bb9920225c9
# bad: [ac1e8c6c95bf805c699656046aef0a05205edfbd] Merge tag '6.1-rc-smb3-client-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6
git bisect bad ac1e8c6c95bf805c699656046aef0a05205edfbd
# bad: [f80be4571b19b9fd8dd1528cd2a2f123aff51f70] kmsan: add KMSAN runtime core
git bisect bad f80be4571b19b9fd8dd1528cd2a2f123aff51f70
# bad: [c4c84f06285e48f80e9843d0775ad92714ffc35a] fs/proc/task_mmu: stop using linked list and highest_vm_end
git bisect bad c4c84f06285e48f80e9843d0775ad92714ffc35a
# good: [8c004d1fc1497d9a6d92ea968bd58230af59a492] jbd2: replace ll_rw_block()
git bisect good 8c004d1fc1497d9a6d92ea968bd58230af59a492
# bad: [f76c83378851f8e70f032848c4e61203f39480e4] mm: multi-gen LRU: optimize multiple memcgs
git bisect bad f76c83378851f8e70f032848c4e61203f39480e4
# good: [36537a67d3561bfe2b3654161d6c9008fff84d43] mm, hwpoison: avoid unneeded page_mapped_in_vma() overhead in collect_procs_anon()
git bisect good 36537a67d3561bfe2b3654161d6c9008fff84d43
# bad: [5fc30916b5cda697a7eb8f1167c38c27100a793a] migrate_pages(): fix failure counting for THP subpages retrying
git bisect bad 5fc30916b5cda697a7eb8f1167c38c27100a793a
# good: [2e3468778dbe3ec389a10c21a703bb8e5be5cfbc] mm: remember young/dirty bit for page migrations
git bisect good 2e3468778dbe3ec389a10c21a703bb8e5be5cfbc
# good: [f347c9d2697fcbbb64e077f7113a3887a181b8c0] filemap: make the accounting of thrashing more consistent
git bisect good f347c9d2697fcbbb64e077f7113a3887a181b8c0
# bad: [9c62ff005fc774fb2ba14223b0d865a8aca48fb5] migrate_pages(): remove unnecessary list_safe_reset_next()
git bisect bad 9c62ff005fc774fb2ba14223b0d865a8aca48fb5
# bad: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
git bisect bad a7504ed14f9b5e873599b2487eb95062dd0b65f8
# first bad commit: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
Alistair Popple July 28, 2023, 12:57 a.m. UTC | #2
Thanks Ryan.

If I'm understanding Huang's patch correctly then kernel versions
without it would have returned a return code indicating that all pages
were migrated (ie. none failed to migrate) even if they hadn't.

Given I would have wrote and tested the test against the old buggy
version it's probable that this test was always failing but the failure
was undetected.

The failure to migrate could be valid (although I'd expect at least some
success). One improvement to the test would be to check that status code
for the page as well and make sure it matches the return code. We would
likely have caught the bug Huang fixed earlier then.

Will take a look and see if I can improve the test.

 - Alistair

Ryan Roberts <ryan.roberts@arm.com> writes:

> On 17/08/2022 09:14, Huang Ying wrote:
>> The return value of move_pages() syscall is incorrect when counting
>> the remaining pages to be migrated.
>
> Hi Huang, Alistair,
>
> I've noticed that this patch from Huang has caused the mm/migration selftest (authored by Alistair) to start failing (see bisection log below).
>
> Of the 3 tests, migration.private_anon and migration.private_anon_thp continue to pass, but migration.shared_anon fails:
>
>
>   #  RUN           migration.shared_anon ...
>   Didn't migrate 1 pages
>   # migration.c:167:shared_anon:Expected migrate(ptr, self->n1, self->n2) (-2) == 0 (0)
>   # shared_anon: Test terminated by assertion
>   #          FAIL  migration.shared_anon
>   not ok 2 migration.shared_anon
>
>
> The failure occurs due to the return code of move_pages() and this patch has changed the return code handling in the kernel, so it makes sense:
>
>
> int migrate(uint64_t *ptr, int n1, int n2)
> {
> 	int ret, tmp;
> 	int status = 0;
> 	struct timespec ts1, ts2;
>
> 	if (clock_gettime(CLOCK_MONOTONIC, &ts1))
> 		return -1;
>
> 	while (1) {
> 		if (clock_gettime(CLOCK_MONOTONIC, &ts2))
> 			return -1;
>
> 		if (ts2.tv_sec - ts1.tv_sec >= RUNTIME)
> 			return 0;
>
> 		ret = move_pages(0, 1, (void **) &ptr, &n2, &status,
> 				MPOL_MF_MOVE_ALL);
> 		if (ret) {
> 			if (ret > 0)
> 				printf("Didn't migrate %d pages\n", ret); <<<< HERE
> 			else
> 				perror("Couldn't migrate pages");
> 			return -2;
> 		}
>
> 		tmp = n2;
> 		n2 = n1;
> 		n1 = tmp;
> 	}
>
> 	return 0;
> }
>
>
> I haven't looked any further and am not sure what the correct fix is. I wondered if either you might be able to offer a solution?
>
> Thanks,
> Ryan
>
>
> git bisect start
> # bad: [6eaae198076080886b9e7d57f4ae06fa782f90ef] Linux 6.5-rc3
> git bisect bad 6eaae198076080886b9e7d57f4ae06fa782f90ef
> # good: [2c85ebc57b3e1817b6ce1a6b703928e113a90442] Linux 5.10
> git bisect good 2c85ebc57b3e1817b6ce1a6b703928e113a90442
> # good: [d710d370c4911e83da5d2bc43d4a2c3b56bd27e7] Merge tag 's390-5.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
> git bisect good d710d370c4911e83da5d2bc43d4a2c3b56bd27e7
> # bad: [8715c6d3100fc7c6edddf29af4a399a1c12d028c] Merge tag 'for-6.2/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
> git bisect bad 8715c6d3100fc7c6edddf29af4a399a1c12d028c
> # good: [12b68040a5e468068fd7f4af1150eab8f6e96235] Merge tag 'media/v5.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
> git bisect good 12b68040a5e468068fd7f4af1150eab8f6e96235
> # good: [7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf] Merge tag 'drm-next-2022-10-05' of git://anongit.freedesktop.org/drm/drm
> git bisect good 7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf
> # bad: [524d0c68826bc1adf9d1946e540eb4f7b16699a7] Merge tag 'ceph-for-6.1-rc1' of https://github.com/ceph/ceph-client
> git bisect bad 524d0c68826bc1adf9d1946e540eb4f7b16699a7
> # good: [29926f1cd3535f565f200430d5b6a794543fe130] fbdev: mb862xx: Fix check of return value from irq_of_parse_and_map()
> git bisect good 29926f1cd3535f565f200430d5b6a794543fe130
> # good: [d4013bc4d49f6da8178a340348369bb9920225c9] Merge tag 'bitmap-6.1-rc1' of https://github.com/norov/linux
> git bisect good d4013bc4d49f6da8178a340348369bb9920225c9
> # bad: [ac1e8c6c95bf805c699656046aef0a05205edfbd] Merge tag '6.1-rc-smb3-client-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6
> git bisect bad ac1e8c6c95bf805c699656046aef0a05205edfbd
> # bad: [f80be4571b19b9fd8dd1528cd2a2f123aff51f70] kmsan: add KMSAN runtime core
> git bisect bad f80be4571b19b9fd8dd1528cd2a2f123aff51f70
> # bad: [c4c84f06285e48f80e9843d0775ad92714ffc35a] fs/proc/task_mmu: stop using linked list and highest_vm_end
> git bisect bad c4c84f06285e48f80e9843d0775ad92714ffc35a
> # good: [8c004d1fc1497d9a6d92ea968bd58230af59a492] jbd2: replace ll_rw_block()
> git bisect good 8c004d1fc1497d9a6d92ea968bd58230af59a492
> # bad: [f76c83378851f8e70f032848c4e61203f39480e4] mm: multi-gen LRU: optimize multiple memcgs
> git bisect bad f76c83378851f8e70f032848c4e61203f39480e4
> # good: [36537a67d3561bfe2b3654161d6c9008fff84d43] mm, hwpoison: avoid unneeded page_mapped_in_vma() overhead in collect_procs_anon()
> git bisect good 36537a67d3561bfe2b3654161d6c9008fff84d43
> # bad: [5fc30916b5cda697a7eb8f1167c38c27100a793a] migrate_pages(): fix failure counting for THP subpages retrying
> git bisect bad 5fc30916b5cda697a7eb8f1167c38c27100a793a
> # good: [2e3468778dbe3ec389a10c21a703bb8e5be5cfbc] mm: remember young/dirty bit for page migrations
> git bisect good 2e3468778dbe3ec389a10c21a703bb8e5be5cfbc
> # good: [f347c9d2697fcbbb64e077f7113a3887a181b8c0] filemap: make the accounting of thrashing more consistent
> git bisect good f347c9d2697fcbbb64e077f7113a3887a181b8c0
> # bad: [9c62ff005fc774fb2ba14223b0d865a8aca48fb5] migrate_pages(): remove unnecessary list_safe_reset_next()
> git bisect bad 9c62ff005fc774fb2ba14223b0d865a8aca48fb5
> # bad: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
> git bisect bad a7504ed14f9b5e873599b2487eb95062dd0b65f8
> # first bad commit: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
Ryan Roberts July 28, 2023, 8:45 a.m. UTC | #3
On 28/07/2023 01:57, Alistair Popple wrote:
> 
> Thanks Ryan.
> 
> If I'm understanding Huang's patch correctly then kernel versions
> without it would have returned a return code indicating that all pages
> were migrated (ie. none failed to migrate) even if they hadn't.
> 
> Given I would have wrote and tested the test against the old buggy
> version it's probable that this test was always failing but the failure
> was undetected.
> 
> The failure to migrate could be valid (although I'd expect at least some
> success).

Yes, when I looked, I think an initial (variable) number of iterations succeed
before failure.

 One improvement to the test would be to check that status code
> for the page as well and make sure it matches the return code. We would
> likely have caught the bug Huang fixed earlier then.
> 
> Will take a look and see if I can improve the test.

Thanks. This is not urgent from my perspective - I just wanted to point it out.
So don't feel like you need to prioritize it on my account. Although it would be
good to get to the point where all the tests pass on mainline...

> 
>  - Alistair
> 
> Ryan Roberts <ryan.roberts@arm.com> writes:
> 
>> On 17/08/2022 09:14, Huang Ying wrote:
>>> The return value of move_pages() syscall is incorrect when counting
>>> the remaining pages to be migrated.
>>
>> Hi Huang, Alistair,
>>
>> I've noticed that this patch from Huang has caused the mm/migration selftest (authored by Alistair) to start failing (see bisection log below).
>>
>> Of the 3 tests, migration.private_anon and migration.private_anon_thp continue to pass, but migration.shared_anon fails:
>>
>>
>>   #  RUN           migration.shared_anon ...
>>   Didn't migrate 1 pages
>>   # migration.c:167:shared_anon:Expected migrate(ptr, self->n1, self->n2) (-2) == 0 (0)
>>   # shared_anon: Test terminated by assertion
>>   #          FAIL  migration.shared_anon
>>   not ok 2 migration.shared_anon
>>
>>
>> The failure occurs due to the return code of move_pages() and this patch has changed the return code handling in the kernel, so it makes sense:
>>
>>
>> int migrate(uint64_t *ptr, int n1, int n2)
>> {
>> 	int ret, tmp;
>> 	int status = 0;
>> 	struct timespec ts1, ts2;
>>
>> 	if (clock_gettime(CLOCK_MONOTONIC, &ts1))
>> 		return -1;
>>
>> 	while (1) {
>> 		if (clock_gettime(CLOCK_MONOTONIC, &ts2))
>> 			return -1;
>>
>> 		if (ts2.tv_sec - ts1.tv_sec >= RUNTIME)
>> 			return 0;
>>
>> 		ret = move_pages(0, 1, (void **) &ptr, &n2, &status,
>> 				MPOL_MF_MOVE_ALL);
>> 		if (ret) {
>> 			if (ret > 0)
>> 				printf("Didn't migrate %d pages\n", ret); <<<< HERE
>> 			else
>> 				perror("Couldn't migrate pages");
>> 			return -2;
>> 		}
>>
>> 		tmp = n2;
>> 		n2 = n1;
>> 		n1 = tmp;
>> 	}
>>
>> 	return 0;
>> }
>>
>>
>> I haven't looked any further and am not sure what the correct fix is. I wondered if either you might be able to offer a solution?
>>
>> Thanks,
>> Ryan
>>
>>
>> git bisect start
>> # bad: [6eaae198076080886b9e7d57f4ae06fa782f90ef] Linux 6.5-rc3
>> git bisect bad 6eaae198076080886b9e7d57f4ae06fa782f90ef
>> # good: [2c85ebc57b3e1817b6ce1a6b703928e113a90442] Linux 5.10
>> git bisect good 2c85ebc57b3e1817b6ce1a6b703928e113a90442
>> # good: [d710d370c4911e83da5d2bc43d4a2c3b56bd27e7] Merge tag 's390-5.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
>> git bisect good d710d370c4911e83da5d2bc43d4a2c3b56bd27e7
>> # bad: [8715c6d3100fc7c6edddf29af4a399a1c12d028c] Merge tag 'for-6.2/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
>> git bisect bad 8715c6d3100fc7c6edddf29af4a399a1c12d028c
>> # good: [12b68040a5e468068fd7f4af1150eab8f6e96235] Merge tag 'media/v5.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
>> git bisect good 12b68040a5e468068fd7f4af1150eab8f6e96235
>> # good: [7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf] Merge tag 'drm-next-2022-10-05' of git://anongit.freedesktop.org/drm/drm
>> git bisect good 7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf
>> # bad: [524d0c68826bc1adf9d1946e540eb4f7b16699a7] Merge tag 'ceph-for-6.1-rc1' of https://github.com/ceph/ceph-client
>> git bisect bad 524d0c68826bc1adf9d1946e540eb4f7b16699a7
>> # good: [29926f1cd3535f565f200430d5b6a794543fe130] fbdev: mb862xx: Fix check of return value from irq_of_parse_and_map()
>> git bisect good 29926f1cd3535f565f200430d5b6a794543fe130
>> # good: [d4013bc4d49f6da8178a340348369bb9920225c9] Merge tag 'bitmap-6.1-rc1' of https://github.com/norov/linux
>> git bisect good d4013bc4d49f6da8178a340348369bb9920225c9
>> # bad: [ac1e8c6c95bf805c699656046aef0a05205edfbd] Merge tag '6.1-rc-smb3-client-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6
>> git bisect bad ac1e8c6c95bf805c699656046aef0a05205edfbd
>> # bad: [f80be4571b19b9fd8dd1528cd2a2f123aff51f70] kmsan: add KMSAN runtime core
>> git bisect bad f80be4571b19b9fd8dd1528cd2a2f123aff51f70
>> # bad: [c4c84f06285e48f80e9843d0775ad92714ffc35a] fs/proc/task_mmu: stop using linked list and highest_vm_end
>> git bisect bad c4c84f06285e48f80e9843d0775ad92714ffc35a
>> # good: [8c004d1fc1497d9a6d92ea968bd58230af59a492] jbd2: replace ll_rw_block()
>> git bisect good 8c004d1fc1497d9a6d92ea968bd58230af59a492
>> # bad: [f76c83378851f8e70f032848c4e61203f39480e4] mm: multi-gen LRU: optimize multiple memcgs
>> git bisect bad f76c83378851f8e70f032848c4e61203f39480e4
>> # good: [36537a67d3561bfe2b3654161d6c9008fff84d43] mm, hwpoison: avoid unneeded page_mapped_in_vma() overhead in collect_procs_anon()
>> git bisect good 36537a67d3561bfe2b3654161d6c9008fff84d43
>> # bad: [5fc30916b5cda697a7eb8f1167c38c27100a793a] migrate_pages(): fix failure counting for THP subpages retrying
>> git bisect bad 5fc30916b5cda697a7eb8f1167c38c27100a793a
>> # good: [2e3468778dbe3ec389a10c21a703bb8e5be5cfbc] mm: remember young/dirty bit for page migrations
>> git bisect good 2e3468778dbe3ec389a10c21a703bb8e5be5cfbc
>> # good: [f347c9d2697fcbbb64e077f7113a3887a181b8c0] filemap: make the accounting of thrashing more consistent
>> git bisect good f347c9d2697fcbbb64e077f7113a3887a181b8c0
>> # bad: [9c62ff005fc774fb2ba14223b0d865a8aca48fb5] migrate_pages(): remove unnecessary list_safe_reset_next()
>> git bisect bad 9c62ff005fc774fb2ba14223b0d865a8aca48fb5
>> # bad: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
>> git bisect bad a7504ed14f9b5e873599b2487eb95062dd0b65f8
>> # first bad commit: [a7504ed14f9b5e873599b2487eb95062dd0b65f8] migrate: fix syscall move_pages() return value for failure
>
diff mbox series

Patch

diff --git a/mm/migrate.c b/mm/migrate.c
index a35eba462e61..1758fd215c0a 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1751,7 +1751,7 @@  static int move_pages_and_store_status(struct mm_struct *mm, int node,
 		 * well.
 		 */
 		if (err > 0)
-			err += nr_pages - i - 1;
+			err += nr_pages - i;
 		return err;
 	}
 	return store_status(status, start, node, i - start);
@@ -1837,8 +1837,12 @@  static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
 
 		err = move_pages_and_store_status(mm, current_node, &pagelist,
 				status, start, i, nr_pages);
-		if (err)
+		if (err) {
+			/* We have accounted for page i */
+			if (err > 0)
+				err--;
 			goto out;
+		}
 		current_node = NUMA_NO_NODE;
 	}
 out_flush: