linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: TGSP <tgsp002@gmail.com>
Cc: rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz,
	huanglei@kylinos.cn, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, xiongxin <xiongxin@kylinos.cn>,
	stable@vger.kernel.org
Subject: Re: [PATCH -next 2/2] PM: hibernate: add check of preallocate mem for image size pages
Date: Thu, 3 Nov 2022 17:57:04 +0100	[thread overview]
Message-ID: <CAJZ5v0h82YpaG9a1mmavVnm4WwjDV5iU_Qof6dN_PqP1UR-OUQ@mail.gmail.com> (raw)
In-Reply-To: <CAJZ5v0hXSnx0NqPwTRm=5ewg+P08-HaYc0ERQ6Uebrop8BfkdA@mail.gmail.com>

On Thu, Nov 3, 2022 at 5:47 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Tue, Nov 1, 2022 at 3:28 AM TGSP <tgsp002@gmail.com> wrote:
> >
> > From: xiongxin <xiongxin@kylinos.cn>
> >
> > Added a check on the return value of preallocate_image_highmem(). If
> > memory preallocate is insufficient, S4 cannot be done;
> >
> > I am playing 4K video on a machine with AMD or other graphics card and
> > only 8GiB memory, and the kernel is not configured with CONFIG_HIGHMEM.
> > When doing the S4 test, the analysis found that when the pages get from
> > minimum_image_size() is large enough, The preallocate_image_memory() and
> > preallocate_image_highmem() calls failed to obtain enough memory. Add
> > the judgment that memory preallocate is insufficient;
> >
> > "pages -= free_unnecessary_pages()" below will let pages to drop a lot,
> > so I wonder if it makes sense to add a judgment here.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: xiongxin <xiongxin@kylinos.cn>
> > Signed-off-by: huanglei <huanglei@kylinos.cn>
> > ---
> >  kernel/power/snapshot.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
> > index c20ca5fb9adc..670abf89cf31 100644
> > --- a/kernel/power/snapshot.c
> > +++ b/kernel/power/snapshot.c
> > @@ -1738,6 +1738,7 @@ int hibernate_preallocate_memory(void)
> >         struct zone *zone;
> >         unsigned long saveable, size, max_size, count, highmem, pages = 0;
> >         unsigned long alloc, save_highmem, pages_highmem, avail_normal;
> > +       unsigned long size_highmem;
>
> Please define this in the block where it will be used.
>
> >         ktime_t start, stop;
> >         int error;
> >
> > @@ -1863,7 +1864,13 @@ int hibernate_preallocate_memory(void)
> >                 pages_highmem += size;
>
> The line above can be dropped.

Not really, it needs to be replaced with

        size_highmem = size ;

> >                 alloc -= size;
> >                 size = preallocate_image_memory(alloc, avail_normal);
> > -               pages_highmem += preallocate_image_highmem(alloc - size);
> > +               size_highmem += preallocate_image_highmem(alloc - size);
>
> Did you mean "="?
>
> Assuming you did, this could be
>
>         size_highmem = size + preallocate_image_highmem(alloc - size);

And here

                  size_highmem += preallocate_image_highmem(alloc - size);

which is what you had in the original patch.

>         if (size_highmem < alloc) {
>
> > +               if (size_highmem < (alloc - size)) {
>
> The inner parens were not necessary.
>
> > +                       pr_err("Image allocation is %lu pages short, exit\n",
> > +                               alloc - size - pages_highmem);
> > +                       goto err_out;
> > +               }
> > +               pages_highmem += size_highmem;
> >                 pages += pages_highmem + size;
> >         }
> >
> > --
>
> But overall it would be better to avoid bailing out.

  reply	other threads:[~2022-11-03 16:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01  2:28 [PATCH -next 0/2] Fixes to the hibernate_preallocate_memory() TGSP
2022-11-01  2:28 ` [PATCH -next 1/2] PM: hibernate: fix spelling mistake for annotation TGSP
2022-11-01 12:45   ` Bagas Sanjaya
2022-11-03 16:25   ` Rafael J. Wysocki
2022-11-04  7:31     ` TGSP
2022-11-05 18:09       ` Rafael J. Wysocki
2022-11-01  2:28 ` [PATCH -next 2/2] PM: hibernate: add check of preallocate mem for image size pages TGSP
2022-11-01 21:23   ` kernel test robot
2022-11-03 16:47   ` Rafael J. Wysocki
2022-11-03 16:57     ` Rafael J. Wysocki [this message]
2022-11-03 17:11   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJZ5v0h82YpaG9a1mmavVnm4WwjDV5iU_Qof6dN_PqP1UR-OUQ@mail.gmail.com \
    --to=rafael@kernel.org \
    --cc=huanglei@kylinos.cn \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=stable@vger.kernel.org \
    --cc=tgsp002@gmail.com \
    --cc=xiongxin@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).