* [PATCH -mm] mm, swap: Fix THP swap out
@ 2019-06-24 2:23 Huang, Ying
2019-06-24 3:34 ` Ming Lei
0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2019-06-24 2:23 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Huang Ying, Ming Lei, Michal Hocko,
Johannes Weiner, Hugh Dickins, Minchan Kim, Rik van Riel,
Daniel Jordan
From: Huang Ying <ying.huang@intel.com>
0-Day test system reported some OOM regressions for several
THP (Transparent Huge Page) swap test cases. These regressions are
bisected to 6861428921b5 ("block: always define BIO_MAX_PAGES as
256"). In the commit, BIO_MAX_PAGES is set to 256 even when THP swap
is enabled. So the bio_alloc(gfp_flags, 512) in get_swap_bio() may
fail when swapping out THP. That causes the OOM.
As in the patch description of 6861428921b5 ("block: always define
BIO_MAX_PAGES as 256"), THP swap should use multi-page bvec to write
THP to swap space. So the issue is fixed via doing that in
get_swap_bio().
BTW: I remember I have checked the THP swap code when
6861428921b5 ("block: always define BIO_MAX_PAGES as 256") was merged,
and thought the THP swap code needn't to be changed. But apparently,
I was wrong. I should have done this at that time.
Fixes: 6861428921b5 ("block: always define BIO_MAX_PAGES as 256")
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
---
mm/page_io.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index 2e8019d0e048..4ab997f84061 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -29,10 +29,9 @@
static struct bio *get_swap_bio(gfp_t gfp_flags,
struct page *page, bio_end_io_t end_io)
{
- int i, nr = hpage_nr_pages(page);
struct bio *bio;
- bio = bio_alloc(gfp_flags, nr);
+ bio = bio_alloc(gfp_flags, 1);
if (bio) {
struct block_device *bdev;
@@ -41,9 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
bio->bi_end_io = end_io;
- for (i = 0; i < nr; i++)
- bio_add_page(bio, page + i, PAGE_SIZE, 0);
- VM_BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE * nr);
+ __bio_add_page(bio, page, PAGE_SIZE * hpage_nr_pages(page), 0);
}
return bio;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -mm] mm, swap: Fix THP swap out
2019-06-24 2:23 [PATCH -mm] mm, swap: Fix THP swap out Huang, Ying
@ 2019-06-24 3:34 ` Ming Lei
2019-06-24 4:44 ` Huang, Ying
0 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2019-06-24 3:34 UTC (permalink / raw)
To: Huang, Ying
Cc: Andrew Morton, linux-mm, linux-kernel, Michal Hocko,
Johannes Weiner, Hugh Dickins, Minchan Kim, Rik van Riel,
Daniel Jordan
Hi Huang Ying,
On Mon, Jun 24, 2019 at 10:23:36AM +0800, Huang, Ying wrote:
> From: Huang Ying <ying.huang@intel.com>
>
> 0-Day test system reported some OOM regressions for several
> THP (Transparent Huge Page) swap test cases. These regressions are
> bisected to 6861428921b5 ("block: always define BIO_MAX_PAGES as
> 256"). In the commit, BIO_MAX_PAGES is set to 256 even when THP swap
> is enabled. So the bio_alloc(gfp_flags, 512) in get_swap_bio() may
> fail when swapping out THP. That causes the OOM.
>
> As in the patch description of 6861428921b5 ("block: always define
> BIO_MAX_PAGES as 256"), THP swap should use multi-page bvec to write
> THP to swap space. So the issue is fixed via doing that in
> get_swap_bio().
>
> BTW: I remember I have checked the THP swap code when
> 6861428921b5 ("block: always define BIO_MAX_PAGES as 256") was merged,
> and thought the THP swap code needn't to be changed. But apparently,
> I was wrong. I should have done this at that time.
>
> Fixes: 6861428921b5 ("block: always define BIO_MAX_PAGES as 256")
> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Rik van Riel <riel@redhat.com>
> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
> ---
> mm/page_io.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 2e8019d0e048..4ab997f84061 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -29,10 +29,9 @@
> static struct bio *get_swap_bio(gfp_t gfp_flags,
> struct page *page, bio_end_io_t end_io)
> {
> - int i, nr = hpage_nr_pages(page);
> struct bio *bio;
>
> - bio = bio_alloc(gfp_flags, nr);
> + bio = bio_alloc(gfp_flags, 1);
> if (bio) {
> struct block_device *bdev;
>
> @@ -41,9 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
> bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
> bio->bi_end_io = end_io;
>
> - for (i = 0; i < nr; i++)
> - bio_add_page(bio, page + i, PAGE_SIZE, 0);
bio_add_page() supposes to work, just wondering why it doesn't recently.
Could you share me one test case for reproducing it?
> - VM_BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE * nr);
> + __bio_add_page(bio, page, PAGE_SIZE * hpage_nr_pages(page), 0);
> }
> return bio;
Actually the above code can be simplified as:
diff --git a/mm/page_io.c b/mm/page_io.c
index 2e8019d0e048..c20b4189d0a1 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -29,7 +29,7 @@
static struct bio *get_swap_bio(gfp_t gfp_flags,
struct page *page, bio_end_io_t end_io)
{
- int i, nr = hpage_nr_pages(page);
+ int nr = hpage_nr_pages(page);
struct bio *bio;
bio = bio_alloc(gfp_flags, nr);
@@ -41,8 +41,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
bio->bi_end_io = end_io;
- for (i = 0; i < nr; i++)
- bio_add_page(bio, page + i, PAGE_SIZE, 0);
+ bio_add_page(bio, page, PAGE_SIZE * nr, 0);
VM_BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE * nr);
}
return bio;
Thanks,
Ming
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -mm] mm, swap: Fix THP swap out
2019-06-24 3:34 ` Ming Lei
@ 2019-06-24 4:44 ` Huang, Ying
2019-06-24 7:28 ` Ming Lei
0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2019-06-24 4:44 UTC (permalink / raw)
To: Ming Lei
Cc: Andrew Morton, linux-mm, linux-kernel, Michal Hocko,
Johannes Weiner, Hugh Dickins, Minchan Kim, Rik van Riel,
Daniel Jordan
Ming Lei <ming.lei@redhat.com> writes:
> Hi Huang Ying,
>
> On Mon, Jun 24, 2019 at 10:23:36AM +0800, Huang, Ying wrote:
>> From: Huang Ying <ying.huang@intel.com>
>>
>> 0-Day test system reported some OOM regressions for several
>> THP (Transparent Huge Page) swap test cases. These regressions are
>> bisected to 6861428921b5 ("block: always define BIO_MAX_PAGES as
>> 256"). In the commit, BIO_MAX_PAGES is set to 256 even when THP swap
>> is enabled. So the bio_alloc(gfp_flags, 512) in get_swap_bio() may
>> fail when swapping out THP. That causes the OOM.
>>
>> As in the patch description of 6861428921b5 ("block: always define
>> BIO_MAX_PAGES as 256"), THP swap should use multi-page bvec to write
>> THP to swap space. So the issue is fixed via doing that in
>> get_swap_bio().
>>
>> BTW: I remember I have checked the THP swap code when
>> 6861428921b5 ("block: always define BIO_MAX_PAGES as 256") was merged,
>> and thought the THP swap code needn't to be changed. But apparently,
>> I was wrong. I should have done this at that time.
>>
>> Fixes: 6861428921b5 ("block: always define BIO_MAX_PAGES as 256")
>> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
>> Cc: Ming Lei <ming.lei@redhat.com>
>> Cc: Michal Hocko <mhocko@kernel.org>
>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> Cc: Hugh Dickins <hughd@google.com>
>> Cc: Minchan Kim <minchan@kernel.org>
>> Cc: Rik van Riel <riel@redhat.com>
>> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
>> ---
>> mm/page_io.c | 7 ++-----
>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/mm/page_io.c b/mm/page_io.c
>> index 2e8019d0e048..4ab997f84061 100644
>> --- a/mm/page_io.c
>> +++ b/mm/page_io.c
>> @@ -29,10 +29,9 @@
>> static struct bio *get_swap_bio(gfp_t gfp_flags,
>> struct page *page, bio_end_io_t end_io)
>> {
>> - int i, nr = hpage_nr_pages(page);
>> struct bio *bio;
>>
>> - bio = bio_alloc(gfp_flags, nr);
>> + bio = bio_alloc(gfp_flags, 1);
>> if (bio) {
>> struct block_device *bdev;
>>
>> @@ -41,9 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
>> bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
>> bio->bi_end_io = end_io;
>>
>> - for (i = 0; i < nr; i++)
>> - bio_add_page(bio, page + i, PAGE_SIZE, 0);
>
> bio_add_page() supposes to work, just wondering why it doesn't recently.
Yes. Just checked and bio_add_page() works too. I should have used
that. The problem isn't bio_add_page(), but bio_alloc(), because nr ==
512 > 256, mempool cannot be used during swapout, so swapout will fail.
Best Regards,
Huang, Ying
> Could you share me one test case for reproducing it?
>
>> - VM_BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE * nr);
>> + __bio_add_page(bio, page, PAGE_SIZE * hpage_nr_pages(page), 0);
>> }
>> return bio;
>
> Actually the above code can be simplified as:
>
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 2e8019d0e048..c20b4189d0a1 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -29,7 +29,7 @@
> static struct bio *get_swap_bio(gfp_t gfp_flags,
> struct page *page, bio_end_io_t end_io)
> {
> - int i, nr = hpage_nr_pages(page);
> + int nr = hpage_nr_pages(page);
> struct bio *bio;
>
> bio = bio_alloc(gfp_flags, nr);
> @@ -41,8 +41,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
> bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
> bio->bi_end_io = end_io;
>
> - for (i = 0; i < nr; i++)
> - bio_add_page(bio, page + i, PAGE_SIZE, 0);
> + bio_add_page(bio, page, PAGE_SIZE * nr, 0);
> VM_BUG_ON(bio->bi_iter.bi_size != PAGE_SIZE * nr);
> }
> return bio;
>
>
> Thanks,
> Ming
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -mm] mm, swap: Fix THP swap out
2019-06-24 4:44 ` Huang, Ying
@ 2019-06-24 7:28 ` Ming Lei
2019-06-24 7:31 ` Huang, Ying
0 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2019-06-24 7:28 UTC (permalink / raw)
To: Huang, Ying
Cc: Andrew Morton, linux-mm, linux-kernel, Michal Hocko,
Johannes Weiner, Hugh Dickins, Minchan Kim, Rik van Riel,
Daniel Jordan
On Mon, Jun 24, 2019 at 12:44:41PM +0800, Huang, Ying wrote:
> Ming Lei <ming.lei@redhat.com> writes:
>
> > Hi Huang Ying,
> >
> > On Mon, Jun 24, 2019 at 10:23:36AM +0800, Huang, Ying wrote:
> >> From: Huang Ying <ying.huang@intel.com>
> >>
> >> 0-Day test system reported some OOM regressions for several
> >> THP (Transparent Huge Page) swap test cases. These regressions are
> >> bisected to 6861428921b5 ("block: always define BIO_MAX_PAGES as
> >> 256"). In the commit, BIO_MAX_PAGES is set to 256 even when THP swap
> >> is enabled. So the bio_alloc(gfp_flags, 512) in get_swap_bio() may
> >> fail when swapping out THP. That causes the OOM.
> >>
> >> As in the patch description of 6861428921b5 ("block: always define
> >> BIO_MAX_PAGES as 256"), THP swap should use multi-page bvec to write
> >> THP to swap space. So the issue is fixed via doing that in
> >> get_swap_bio().
> >>
> >> BTW: I remember I have checked the THP swap code when
> >> 6861428921b5 ("block: always define BIO_MAX_PAGES as 256") was merged,
> >> and thought the THP swap code needn't to be changed. But apparently,
> >> I was wrong. I should have done this at that time.
> >>
> >> Fixes: 6861428921b5 ("block: always define BIO_MAX_PAGES as 256")
> >> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
> >> Cc: Ming Lei <ming.lei@redhat.com>
> >> Cc: Michal Hocko <mhocko@kernel.org>
> >> Cc: Johannes Weiner <hannes@cmpxchg.org>
> >> Cc: Hugh Dickins <hughd@google.com>
> >> Cc: Minchan Kim <minchan@kernel.org>
> >> Cc: Rik van Riel <riel@redhat.com>
> >> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
> >> ---
> >> mm/page_io.c | 7 ++-----
> >> 1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/mm/page_io.c b/mm/page_io.c
> >> index 2e8019d0e048..4ab997f84061 100644
> >> --- a/mm/page_io.c
> >> +++ b/mm/page_io.c
> >> @@ -29,10 +29,9 @@
> >> static struct bio *get_swap_bio(gfp_t gfp_flags,
> >> struct page *page, bio_end_io_t end_io)
> >> {
> >> - int i, nr = hpage_nr_pages(page);
> >> struct bio *bio;
> >>
> >> - bio = bio_alloc(gfp_flags, nr);
> >> + bio = bio_alloc(gfp_flags, 1);
> >> if (bio) {
> >> struct block_device *bdev;
> >>
> >> @@ -41,9 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
> >> bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
> >> bio->bi_end_io = end_io;
> >>
> >> - for (i = 0; i < nr; i++)
> >> - bio_add_page(bio, page + i, PAGE_SIZE, 0);
> >
> > bio_add_page() supposes to work, just wondering why it doesn't recently.
>
> Yes. Just checked and bio_add_page() works too. I should have used
> that. The problem isn't bio_add_page(), but bio_alloc(), because nr ==
> 512 > 256, mempool cannot be used during swapout, so swapout will fail.
Then we can pass 1 to bio_alloc(), together with single bio_add_page()
for making the code more readable.
thanks,
Ming
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -mm] mm, swap: Fix THP swap out
2019-06-24 7:28 ` Ming Lei
@ 2019-06-24 7:31 ` Huang, Ying
0 siblings, 0 replies; 5+ messages in thread
From: Huang, Ying @ 2019-06-24 7:31 UTC (permalink / raw)
To: Ming Lei
Cc: Andrew Morton, linux-mm, linux-kernel, Michal Hocko,
Johannes Weiner, Hugh Dickins, Minchan Kim, Rik van Riel,
Daniel Jordan
Ming Lei <ming.lei@redhat.com> writes:
> On Mon, Jun 24, 2019 at 12:44:41PM +0800, Huang, Ying wrote:
>> Ming Lei <ming.lei@redhat.com> writes:
>>
>> > Hi Huang Ying,
>> >
>> > On Mon, Jun 24, 2019 at 10:23:36AM +0800, Huang, Ying wrote:
>> >> From: Huang Ying <ying.huang@intel.com>
>> >>
>> >> 0-Day test system reported some OOM regressions for several
>> >> THP (Transparent Huge Page) swap test cases. These regressions are
>> >> bisected to 6861428921b5 ("block: always define BIO_MAX_PAGES as
>> >> 256"). In the commit, BIO_MAX_PAGES is set to 256 even when THP swap
>> >> is enabled. So the bio_alloc(gfp_flags, 512) in get_swap_bio() may
>> >> fail when swapping out THP. That causes the OOM.
>> >>
>> >> As in the patch description of 6861428921b5 ("block: always define
>> >> BIO_MAX_PAGES as 256"), THP swap should use multi-page bvec to write
>> >> THP to swap space. So the issue is fixed via doing that in
>> >> get_swap_bio().
>> >>
>> >> BTW: I remember I have checked the THP swap code when
>> >> 6861428921b5 ("block: always define BIO_MAX_PAGES as 256") was merged,
>> >> and thought the THP swap code needn't to be changed. But apparently,
>> >> I was wrong. I should have done this at that time.
>> >>
>> >> Fixes: 6861428921b5 ("block: always define BIO_MAX_PAGES as 256")
>> >> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
>> >> Cc: Ming Lei <ming.lei@redhat.com>
>> >> Cc: Michal Hocko <mhocko@kernel.org>
>> >> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> >> Cc: Hugh Dickins <hughd@google.com>
>> >> Cc: Minchan Kim <minchan@kernel.org>
>> >> Cc: Rik van Riel <riel@redhat.com>
>> >> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
>> >> ---
>> >> mm/page_io.c | 7 ++-----
>> >> 1 file changed, 2 insertions(+), 5 deletions(-)
>> >>
>> >> diff --git a/mm/page_io.c b/mm/page_io.c
>> >> index 2e8019d0e048..4ab997f84061 100644
>> >> --- a/mm/page_io.c
>> >> +++ b/mm/page_io.c
>> >> @@ -29,10 +29,9 @@
>> >> static struct bio *get_swap_bio(gfp_t gfp_flags,
>> >> struct page *page, bio_end_io_t end_io)
>> >> {
>> >> - int i, nr = hpage_nr_pages(page);
>> >> struct bio *bio;
>> >>
>> >> - bio = bio_alloc(gfp_flags, nr);
>> >> + bio = bio_alloc(gfp_flags, 1);
>> >> if (bio) {
>> >> struct block_device *bdev;
>> >>
>> >> @@ -41,9 +40,7 @@ static struct bio *get_swap_bio(gfp_t gfp_flags,
>> >> bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
>> >> bio->bi_end_io = end_io;
>> >>
>> >> - for (i = 0; i < nr; i++)
>> >> - bio_add_page(bio, page + i, PAGE_SIZE, 0);
>> >
>> > bio_add_page() supposes to work, just wondering why it doesn't recently.
>>
>> Yes. Just checked and bio_add_page() works too. I should have used
>> that. The problem isn't bio_add_page(), but bio_alloc(), because nr ==
>> 512 > 256, mempool cannot be used during swapout, so swapout will fail.
>
> Then we can pass 1 to bio_alloc(), together with single bio_add_page()
> for making the code more readable.
>
Yes. Will send out v2 to replace __bio_add_page() with bio_add_page().
Best Regards,
Huang, Ying
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-24 7:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 2:23 [PATCH -mm] mm, swap: Fix THP swap out Huang, Ying
2019-06-24 3:34 ` Ming Lei
2019-06-24 4:44 ` Huang, Ying
2019-06-24 7:28 ` Ming Lei
2019-06-24 7:31 ` Huang, Ying
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).