Message ID | 20221101022840.1351163-3-tgsp002@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2681099wru; Mon, 31 Oct 2022 19:33:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5JCoEXoBcGaMxNTCGTsRWkrmZlstzuC7X9achkTQDUpn1vDS60pOfOzhEZqLDt0Pv/o+bE X-Received: by 2002:a17:906:9c84:b0:7ad:90d9:a6cf with SMTP id fj4-20020a1709069c8400b007ad90d9a6cfmr15757289ejc.595.1667270007929; Mon, 31 Oct 2022 19:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667270007; cv=none; d=google.com; s=arc-20160816; b=FewzhMpouqnItuTQ6oYJwOWsXG1ztZ6eQprHXM+KYM0K9ZxVfzb2Kana3BSflj9yQd p7LBsCHGOGwQ4DOL+tpf0ccb8sUkfmYEvyBpdMmZuW+vfKCriBxOCw45uAeq610T0HDO A2vbt0lxQ6eg1rAhsLHujAxjhQg26dnRrbK9kfe2pn2zixrLWRT/S+MWNtSpmjZKn2TS lwYJhexrlcstHiaXm7gqH7WNA3juZDkR7LNGqkstDDmRAQ8fFcS5/IRSK/ExFUQYxtBG 4f0f1WbLyW6uEZzlPabMj8kSu5H7WOl4UBlYiqgmX6kVUCod9oqT5IjpWdpCGjezA05j Gf5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GitM46EFRM9nH6tIDAppCJX9q32SAFXaMRLIqIakjjU=; b=zk5UOwRn2OGSbSG02Cp4kTkT0H++kzqQdhpkjXo3IaZ8wTT3Alj0I5mcLqzi/4QQBW pMeELzXVD6Zs7O6X8ZHtNCImvt9yqRxyk9eux5Cj/iN2QucI+ZWzQlP1RKtm6jhhp1Ew W8tq3idzmnhyjUqsKavE34SwgSY7p978nizZxuuMbCscX43SB2rLA+0dckjvUJ0cvJ2K xTx6k5qyJl1eys9YX4JeBqMEzqMq07Uc9+BrV4ETNMi+SaEKhZoQPwGMDtM+h7IPSwaB dEhhDPJR4W+4tIhE1/nbnxBNRK6/RIfZG8B4obKYq09/mDbnvYGfQr8KlvsjXkDwc0Hg r7gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jH3NvDCy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho18-20020a1709070e9200b007879e9a7451si12087761ejc.816.2022.10.31.19.33.04; Mon, 31 Oct 2022 19:33:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jH3NvDCy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbiKAC3E (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Mon, 31 Oct 2022 22:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbiKAC2w (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Oct 2022 22:28:52 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2321D13E; Mon, 31 Oct 2022 19:28:50 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id p21so8493768plr.7; Mon, 31 Oct 2022 19:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GitM46EFRM9nH6tIDAppCJX9q32SAFXaMRLIqIakjjU=; b=jH3NvDCyBGXMBaUTMBOvkNef8p9Z0VL8qnWhCvi1CTp9CmZfiFm2mNXMFVRACIbxqw cwWoyLGSHOe3qVRquSR8VN5C4hCEK1au5oRDOi+Bd5HG9wi9gMNcgbk4g8rd/ceqFBbk IN4dQ3PK03TQyCZk8aguSBzrkCq7hwpNcDik2LXJdWnwMq0hJ89pqAMzo7y6eqwdJ2KF PsUG1EoGlPHx4F46ITYdA4ePouSbjaley6tLhKljI6o/a1/snxg6BTiU/RkitsV1fAuX 7w43sG0PPrzHFGX44CI9BqAeC7CTCa/D18yPOiRKN3Nm4v6kvyzK+I7Fn00X+ZZh2m5v XHHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GitM46EFRM9nH6tIDAppCJX9q32SAFXaMRLIqIakjjU=; b=E+mZb8vtiZUf/NL5IbK6iVkMGnl38hfPZGb4X/ryfJSIribWgQWrsS3bNwgNgy7M8m uPK2xJAiEfZ4D3WiVe/nCA8HwYt1AmCDFqjrHQR3OSuH7tcTGThWcPZJ8zBKNbkVz/w6 bH6kX9TVMm2iyCtNKUyUyT4P/1F5GLZMT6Z90tAXXq9vdwwH0/Ryw44K5imq/fFEx2xr ETSqPB1IKD+61G7FyF+0PQJzqPH8JSEqleJx5p4Pd4wV2TNLx3EQmhdvNDVRnz7WzNwG djVtITh3msVwZxS/ApAZnopvkiW2Dc53z0BfMtbAwZ90GncabZJQNsPyZ16804Iu+KAV 3N+A== X-Gm-Message-State: ACrzQf0t0KfSWjn1REnM4BUf3Dvte1keu7fBFAeSpVP2l7BJoLv/lUIh f9MqPhBITplEzE8GuzfnsTo= X-Received: by 2002:a17:90a:13:b0:212:d139:748a with SMTP id 19-20020a17090a001300b00212d139748amr17340844pja.182.1667269730416; Mon, 31 Oct 2022 19:28:50 -0700 (PDT) Received: from localhost.localdomain ([116.128.244.169]) by smtp.gmail.com with ESMTPSA id t5-20020a625f05000000b005385e2e86eesm5126925pfb.18.2022.10.31.19.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 19:28:50 -0700 (PDT) From: TGSP <tgsp002@gmail.com> To: rafael@kernel.org, len.brown@intel.com, pavel@ucw.cz, huanglei@kylinos.cn Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, xiongxin <xiongxin@kylinos.cn>, stable@vger.kernel.org Subject: [PATCH -next 2/2] PM: hibernate: add check of preallocate mem for image size pages Date: Tue, 1 Nov 2022 10:28:40 +0800 Message-Id: <20221101022840.1351163-3-tgsp002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101022840.1351163-1-tgsp002@gmail.com> References: <20221101022840.1351163-1-tgsp002@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748259316061575048?= X-GMAIL-MSGID: =?utf-8?q?1748259316061575048?= |
Series |
Fixes to the hibernate_preallocate_memory()
|
|
Commit Message
TGSP
Nov. 1, 2022, 2:28 a.m. UTC
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(-)
Comments
Hi TGSP, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on next-20221031] url: https://github.com/intel-lab-lkp/linux/commits/TGSP/Fixes-to-the-hibernate_preallocate_memory/20221101-105416 patch link: https://lore.kernel.org/r/20221101022840.1351163-3-tgsp002%40gmail.com patch subject: [PATCH -next 2/2] PM: hibernate: add check of preallocate mem for image size pages config: i386-randconfig-a011 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/1c277961f43154d671520086d9626e081e072b90 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review TGSP/Fixes-to-the-hibernate_preallocate_memory/20221101-105416 git checkout 1c277961f43154d671520086d9626e081e072b90 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/power/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> kernel/power/snapshot.c:1867:3: warning: variable 'size_highmem' is uninitialized when used here [-Wuninitialized] size_highmem += preallocate_image_highmem(alloc - size); ^~~~~~~~~~~~ kernel/power/snapshot.c:1741:28: note: initialize the variable 'size_highmem' to silence this warning unsigned long size_highmem; ^ = 0 1 warning generated. vim +/size_highmem +1867 kernel/power/snapshot.c 1713 1714 /** 1715 * hibernate_preallocate_memory - Preallocate memory for hibernation image. 1716 * 1717 * To create a hibernation image it is necessary to make a copy of every page 1718 * frame in use. We also need a number of page frames to be free during 1719 * hibernation for allocations made while saving the image and for device 1720 * drivers, in case they need to allocate memory from their hibernation 1721 * callbacks (these two numbers are given by PAGES_FOR_IO (which is a rough 1722 * estimate) and reserved_size divided by PAGE_SIZE (which is tunable through 1723 * /sys/power/reserved_size, respectively). To make this happen, we compute the 1724 * total number of available page frames and allocate at least 1725 * 1726 * ([page frames total] - PAGES_FOR_IO - [metadata pages]) / 2 1727 * - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE) 1728 * 1729 * of them, which corresponds to the maximum size of a hibernation image. 1730 * 1731 * If image_size is set below the number following from the above formula, 1732 * the preallocation of memory is continued until the total number of saveable 1733 * pages in the system is below the requested image size or the minimum 1734 * acceptable image size returned by minimum_image_size(), whichever is greater. 1735 */ 1736 int hibernate_preallocate_memory(void) 1737 { 1738 struct zone *zone; 1739 unsigned long saveable, size, max_size, count, highmem, pages = 0; 1740 unsigned long alloc, save_highmem, pages_highmem, avail_normal; 1741 unsigned long size_highmem; 1742 ktime_t start, stop; 1743 int error; 1744 1745 pr_info("Preallocating image memory\n"); 1746 start = ktime_get(); 1747 1748 error = memory_bm_create(&orig_bm, GFP_IMAGE, PG_ANY); 1749 if (error) { 1750 pr_err("Cannot allocate original bitmap\n"); 1751 goto err_out; 1752 } 1753 1754 error = memory_bm_create(©_bm, GFP_IMAGE, PG_ANY); 1755 if (error) { 1756 pr_err("Cannot allocate copy bitmap\n"); 1757 goto err_out; 1758 } 1759 1760 alloc_normal = 0; 1761 alloc_highmem = 0; 1762 1763 /* Count the number of saveable data pages. */ 1764 save_highmem = count_highmem_pages(); 1765 saveable = count_data_pages(); 1766 1767 /* 1768 * Compute the total number of page frames we can use (count) and the 1769 * number of pages needed for image metadata (size). 1770 */ 1771 count = saveable; 1772 saveable += save_highmem; 1773 highmem = save_highmem; 1774 size = 0; 1775 for_each_populated_zone(zone) { 1776 size += snapshot_additional_pages(zone); 1777 if (is_highmem(zone)) 1778 highmem += zone_page_state(zone, NR_FREE_PAGES); 1779 else 1780 count += zone_page_state(zone, NR_FREE_PAGES); 1781 } 1782 avail_normal = count; 1783 count += highmem; 1784 count -= totalreserve_pages; 1785 1786 /* Compute the maximum number of saveable pages to leave in memory. */ 1787 max_size = (count - (size + PAGES_FOR_IO)) / 2 1788 - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE); 1789 /* Compute the desired number of image pages specified by image_size. */ 1790 size = DIV_ROUND_UP(image_size, PAGE_SIZE); 1791 if (size > max_size) 1792 size = max_size; 1793 /* 1794 * If the desired number of image pages is at least as large as the 1795 * current number of saveable pages in memory, allocate page frames for 1796 * the image and we're done. 1797 */ 1798 if (size >= saveable) { 1799 pages = preallocate_image_highmem(save_highmem); 1800 pages += preallocate_image_memory(saveable - pages, avail_normal); 1801 goto out; 1802 } 1803 1804 /* Estimate the minimum size of the image. */ 1805 pages = minimum_image_size(saveable); 1806 /* 1807 * To avoid excessive pressure on the normal zone, leave room in it to 1808 * accommodate an image of the minimum size (unless it's already too 1809 * small, in which case don't preallocate pages from it at all). 1810 */ 1811 if (avail_normal > pages) 1812 avail_normal -= pages; 1813 else 1814 avail_normal = 0; 1815 if (size < pages) 1816 size = min_t(unsigned long, pages, max_size); 1817 1818 /* 1819 * Let the memory management subsystem know that we're going to need a 1820 * large number of page frames to allocate and make it free some memory. 1821 * NOTE: If this is not done, performance will be hurt badly in some 1822 * test cases. 1823 */ 1824 shrink_all_memory(saveable - size); 1825 1826 /* 1827 * The number of saveable pages in memory was too high, so apply some 1828 * pressure to decrease it. First, make room for the largest possible 1829 * image and fail if that doesn't work. Next, try to decrease the size 1830 * of the image as much as indicated by 'size' using allocations from 1831 * highmem and non-highmem zones separately. 1832 */ 1833 pages_highmem = preallocate_image_highmem(highmem / 2); 1834 alloc = count - max_size; 1835 if (alloc > pages_highmem) 1836 alloc -= pages_highmem; 1837 else 1838 alloc = 0; 1839 pages = preallocate_image_memory(alloc, avail_normal); 1840 if (pages < alloc) { 1841 /* We have exhausted non-highmem pages, try highmem. */ 1842 alloc -= pages; 1843 pages += pages_highmem; 1844 pages_highmem = preallocate_image_highmem(alloc); 1845 if (pages_highmem < alloc) { 1846 pr_err("Image allocation is %lu pages short\n", 1847 alloc - pages_highmem); 1848 goto err_out; 1849 } 1850 pages += pages_highmem; 1851 /* 1852 * size is the desired number of saveable pages to leave in 1853 * memory, so try to preallocate (all memory - size) pages. 1854 */ 1855 alloc = (count - pages) - size; 1856 pages += preallocate_image_highmem(alloc); 1857 } else { 1858 /* 1859 * There are approximately max_size saveable pages at this point 1860 * and we want to reduce this number down to size. 1861 */ 1862 alloc = max_size - size; 1863 size = preallocate_highmem_fraction(alloc, highmem, count); 1864 pages_highmem += size; 1865 alloc -= size; 1866 size = preallocate_image_memory(alloc, avail_normal); > 1867 size_highmem += preallocate_image_highmem(alloc - size); 1868 if (size_highmem < (alloc - size)) { 1869 pr_err("Image allocation is %lu pages short, exit\n", 1870 alloc - size - pages_highmem); 1871 goto err_out; 1872 } 1873 pages_highmem += size_highmem; 1874 pages += pages_highmem + size; 1875 } 1876 1877 /* 1878 * We only need as many page frames for the image as there are saveable 1879 * pages in memory, but we have allocated more. Release the excessive 1880 * ones now. 1881 */ 1882 pages -= free_unnecessary_pages(); 1883 1884 out: 1885 stop = ktime_get(); 1886 pr_info("Allocated %lu pages for snapshot\n", pages); 1887 swsusp_show_speed(start, stop, pages, "Allocated"); 1888 1889 return 0; 1890 1891 err_out: 1892 swsusp_free(); 1893 return -ENOMEM; 1894 } 1895
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. > 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); 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.
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.
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; So I'm not sure what the problem is. Can you please explain it in more detail? The if (pages < alloc) appears to be false in your case, so there should be enough free pages to create an image. Maybe reserved_size is too low?
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; ktime_t start, stop; int error; @@ -1863,7 +1864,13 @@ int hibernate_preallocate_memory(void) pages_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); + if (size_highmem < (alloc - size)) { + 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; }