From patchwork Tue Nov 1 02:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TGSP X-Patchwork-Id: 13504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2681157wru; Mon, 31 Oct 2022 19:33:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5fKko49ufR2a35HAPsnJ8jqsPTery88T30FDdphpIFuYRIgLytb7XRtUdOM0wQnmIx45/k X-Received: by 2002:a17:906:5e14:b0:7ad:cb09:ccbd with SMTP id n20-20020a1709065e1400b007adcb09ccbdmr9289470eju.245.1667270015086; Mon, 31 Oct 2022 19:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667270015; cv=none; d=google.com; s=arc-20160816; b=AED8HqOVTsTMk3Xx83U0eouVsFsc82Hh3f+PmgXGRL814smB++haTret4tOdnEAU9x BddU39uuaHk52UAqt50/XdHkAXVGBx6wnJQvoWNDt2TDezFyUVp5TRWDy8QzWY1wCjRG nOoFj2YPAOSow3dOb12kucw13cEVqinSzJ+A+9XXy5Q3t3sYb7R49PbBljYAM5Wmouhy /4STWz1qaMSZas1K7AG3jzmyn5sxoEIOpKiS9kuGgYkRruWgnTYNBPXCUtBEMGRzpZi6 mMOgagjRGz6vvV3nQEIlUSQfmsCOBjlwfXuOZDDtIipK4d5QMJXhvTezk8VNqFDhWBgB LCcQ== 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=S9+wd/d26nPzxPMD3za/Xjqe3tTkigkq7OyKBI7dvzc=; b=bLmBD2xntrHXx8E9bjzaHO1V9VowZf1v2LCncKc1QOq75HRTKhIZdgeeiZhqAcdWyP Dgeocm/FJfcmqQVWbMG1jTFHeY4UJAStgEEXmcr+5aaKw67jujW5ZckzDNkHZ62XcGRW DVeTEBEHltLsWfCBL7p3jbXstpRslCxFbT4Ov/F1eXc5lFO0oB1WpZZ8F0SGOVl0OxiD Ul4zxlqUoKW5yg26gxX9fAN8wmHbglXaFVR0gnNWo1WbW1v3qG34py/ncoSYdU4GDBtD 6Pj3qB92p9BUx6IZnuBDYdlhuPdWFpGLF2c0EVoP9eTDhS5O+VlNwvF8O0Eeh0XBGAPU AgGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CatEbRow; 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 hw19-20020a170907a0d300b0079dccbbf0c0si8023055ejc.146.2022.10.31.19.33.11; Mon, 31 Oct 2022 19:33:35 -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=CatEbRow; 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 S229894AbiKAC24 (ORCPT + 99 others); Mon, 31 Oct 2022 22:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbiKAC2u (ORCPT ); Mon, 31 Oct 2022 22:28:50 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 723F317898; Mon, 31 Oct 2022 19:28:48 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id l22-20020a17090a3f1600b00212fbbcfb78so17583664pjc.3; Mon, 31 Oct 2022 19:28:48 -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=S9+wd/d26nPzxPMD3za/Xjqe3tTkigkq7OyKBI7dvzc=; b=CatEbRowU2ywt45dREKrkgA7CaFmvOdufAQ0prUMQblLdiEr+iKFatlv66jcBINXKt BApC7Xq10xrVvUJNyzzsYb6w7UYCDm2ZU0ICuFiPFNJPBCJEhs7jSZJMZf5E8fDvxhfn b/0TFgJlISYH/Kr/0JJ3sk9+ibPyMsgWoxKqBCcs/xMqGEcji1pxsNIT18YQGcJCQM9S uE4bHHtz6pUYZ9M9S9Y9n/j6NOuCxwkh7gnIFO2bGXnEc5MRBGK3IE6IbtEzFAWf/2Jj rVRvpfP6nbazaH5dSuFOdExlFpHQAlRezOlx6BviCcu5q9ogFYyKl2F1kGL5GZUYK2Is JsXg== 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=S9+wd/d26nPzxPMD3za/Xjqe3tTkigkq7OyKBI7dvzc=; b=QLsPe0pCkMYmQ68yQgK+vzDLzo/8D4dsKoFypv782Cyze/yNLqZ91c+/G58Sd8l+9G 5ANMS0qnj0Zq3MDAYI4eZP5MwNO8eoQEM1bwLagln2BAViFRAyMa6PEYGIe/Dlifc7BL 0WIRQV6+lJ+4Jo5/lnJaXm2APu2jt3oXklEN5Ajl/Ht6bzDfcJiR2EDu9ypve/c3nEWE tgKNWNdwpuUVFbaMGr51/HJ9uSBry3Pt9X1BcSxr3xKBadDDMNRxQjrOGGXlUioDApTB 1iperZOyOJo6UdWggsoj1viXUcC7DXVLHvJT6BipVa+JTiw2gWY6OpI9VwjrIDy3ygf8 wXhg== X-Gm-Message-State: ACrzQf2pnW+tWXlqBfavPjnb8XKrfru4Z9hm+33CsCdPzSdsutJYizV7 GHK6ZA+O7ES6HYylM4hk+zw= X-Received: by 2002:a17:902:f686:b0:187:16a0:fd2b with SMTP id l6-20020a170902f68600b0018716a0fd2bmr11499574plg.91.1667269728041; Mon, 31 Oct 2022 19:28:48 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 19:28:47 -0700 (PDT) From: TGSP 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 , stable@vger.kernel.org Subject: [PATCH -next 1/2] PM: hibernate: fix spelling mistake for annotation Date: Tue, 1 Nov 2022 10:28:39 +0800 Message-Id: <20221101022840.1351163-2-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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748259323751742322?= X-GMAIL-MSGID: =?utf-8?q?1748259323751742322?= From: xiongxin The actual calculation formula in the code below is: max_size = (count - (size + PAGES_FOR_IO)) / 2 - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE); But function comments are written differently, the comment is wrong? By the way, what exactly do the "/ 2" and "2 *" mean? Cc: stable@vger.kernel.org Signed-off-by: xiongxin --- kernel/power/snapshot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 2a406753af90..c20ca5fb9adc 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1723,8 +1723,8 @@ static unsigned long minimum_image_size(unsigned long saveable) * /sys/power/reserved_size, respectively). To make this happen, we compute the * total number of available page frames and allocate at least * - * ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 - * + 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE) + * ([page frames total] - PAGES_FOR_IO - [metadata pages]) / 2 + * - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE) * * of them, which corresponds to the maximum size of a hibernation image. * From patchwork Tue Nov 1 02:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TGSP X-Patchwork-Id: 13503 Return-Path: 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 + 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 ); 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 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 , 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 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: 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?= From: xiongxin 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 Signed-off-by: huanglei --- 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; 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; }