From patchwork Fri Nov 4 05:41:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TGSP X-Patchwork-Id: 15336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp188694wru; Thu, 3 Nov 2022 22:45:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Udiw0pXkKahtCpOkExzCyCwFV0dBtTL0Vl93l9HJQYMNd5qpmsHOsqYgPa26JessiofGb X-Received: by 2002:a50:fb95:0:b0:463:526:308b with SMTP id e21-20020a50fb95000000b004630526308bmr31747379edq.424.1667540702889; Thu, 03 Nov 2022 22:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667540702; cv=none; d=google.com; s=arc-20160816; b=UvQshoMph6jZa+RKy5rr6alBQGiniGHMhQrP/dw64DrEvplaEexQ07eEETVRkINd72 fgioP7Hx4mFJT3L3h/AaQ7JB5GhOFl+GPp1ACiqXQASgMcxNxdPslK0DfQPgpsAdGbIh 7WqdQXhOe+S35NjxxM5IvFdYNAwYgSx6FJgCdYUWS4l8E7AL4fuHEaVWV8+XsRqFpXlB +sRPCf4jjY9hg3LHbVFxAkZhcy5DBrkJKS4uO7ZUm78BgBpwYmX05nvfeJUg+RNF6/NM CI7d9EGJb3K+M01xP4xkGl8ft4pRulT2Gz0vEJLxMwVWmXPQe8fUgiEa76s+ARuDZ/rj nAMw== 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=rzCWzfF0/mYgWecclSdVrDPtltwjC7OC0NIgqB+4+a+VnTeccSEjjOJVsIOHj+QIcn jlg8V9EinBPRTsN0TYX2wMQAEgUhBtoBe3kcDtC+fK+x9uJfNQ+mUDvs2hcJn+nIJRAi U6iNknUGUCNuCK/bNPXkdV9+ltFtuFTsGhKBWpG9SADDQnYbr49XJ65/fqhz7ZkZeWM/ ncMvAdBlvkbk3u7p9bzGWUsS8qciLX1Rx9mSv3n2objOHNtLKDU4anV9vtlNFDstLaHd JpGT7eU/31UEPNhnSRsZHIJm3+O3ukfHueU/LIPbybZZgNgI2sCOotILqnGQql6gm6Gg MU0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pNnLMLpB; 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 p11-20020a056402500b00b0045b265a1712si3597295eda.595.2022.11.03.22.44.39; Thu, 03 Nov 2022 22:45:02 -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=pNnLMLpB; 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 S231243AbiKDFld (ORCPT + 99 others); Fri, 4 Nov 2022 01:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbiKDFl3 (ORCPT ); Fri, 4 Nov 2022 01:41:29 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C94A8275CD; Thu, 3 Nov 2022 22:41:28 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id k22so3615158pfd.3; Thu, 03 Nov 2022 22:41:28 -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=pNnLMLpBzc+72sVwLQ4rebigm5zWOx4LYczRbHPQpI7CDybS5XeVsceGIwLeSpM7iT qikW5kfEFH0tn4B3m0b8GBR+xb64tfFFQN1sBE+4ZpNe5FrTozqrXThq5FeSgqctCGUV sEDRCq5byPTXSz/yigP8CyE+iM/G76pQ9LoveN4Aod8jUCYpqpCddm7oPxlT7HipBHsA 9KL6bCRRbkZFLXEbagVgott+y+tlk5CIcRDsxFpxOFGUJjiwjvRyzLJjLcXZ0uPpc5nE mu20rOG63OERUuwa7Obmq+ZPzK2Td0Os0Q0BhxdusOoJ4ecigPbuXx7txImUyGbkrc6I 8H2A== 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=UTZEJIPHdhV+6FXCPXDqC1FtpvJQzsR4YlCTlQxq1+TqvuoAaJCzJIpZ85NMTg4jSx qvNqjzYYLEG/YNg1CNaYnCn92ZShEmCn8F1YB6ioXQwUhzw0MCUGFJ1b8elCroKxMuO+ G3YGFZhMtH5BbFmwHmG9XqwFIJYnAZh5odfp+yjt8iem7f+RHOg1dWU8S+Xd/9iJIIZv Dv1FtYvrg0YAqXk8foMrGnFUQajlV2bGY63ubFsQcsig1NxkWjsPdh1Caqmtqq9Kc2A2 NKMOp5F0lYV/Bx08RrJVXu0uWYxlvLftfmeatD+krOwzJ9JGz19DgTU2vSyJ4HAXAT5Q yeXw== X-Gm-Message-State: ACrzQf005+rrUEhGcnFTsyrNPvnMPNBMZ6z91tzkgdBTlZqm1Y3pD21x p+HmbCNSm0Sd1Nk8+qv1P8U= X-Received: by 2002:a05:6a00:1905:b0:566:2a02:e1a1 with SMTP id y5-20020a056a00190500b005662a02e1a1mr34370199pfi.1.1667540488374; Thu, 03 Nov 2022 22:41:28 -0700 (PDT) Received: from localhost.localdomain ([116.128.244.169]) by smtp.gmail.com with ESMTPSA id q15-20020aa7960f000000b0056bdc3f5b29sm1684043pfg.186.2022.11.03.22.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 22:41:27 -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 v2 1/2] PM: hibernate: fix spelling mistake for annotation Date: Fri, 4 Nov 2022 13:41:18 +0800 Message-Id: <20221104054119.1946073-2-tgsp002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221104054119.1946073-1-tgsp002@gmail.com> References: <20221104054119.1946073-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?1748543160104622678?= X-GMAIL-MSGID: =?utf-8?q?1748543160104622678?= 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 Fri Nov 4 05:41:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TGSP X-Patchwork-Id: 15337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp188858wru; Thu, 3 Nov 2022 22:45:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GP+uL9Ptu2ajzDlQjXlBWdNBV+s/k9dE3kql5q4sqJ5AE34wis+RGiJ2CgeZBfqrQ2AHD X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr35105343edb.347.1667540735776; Thu, 03 Nov 2022 22:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667540735; cv=none; d=google.com; s=arc-20160816; b=tfL2P4zhepBBuNxKYnjntrqI7TtmGPCVtfoIX4L4osYPan02RhtjVmS69MVv5F5bbR ACQau+H68ksl6ARDJRE2q+GnqIOifXThD1YpIzayPYERWp12pmF7+Bin+jOfAzv9fRyV L5wqMmF7t8K76lfOe7IuMjUaLdiHkY0OWH7b3BbAHDAbZRNUMtkEe9jo1TyU0tqcvO5W n4ecBlzZThjnL4tuvj4rwIqNyBdk16VinkgNVfAJJ4AOwsbzU2uxepnjraKE3b6kMtDY 9Ts22H1hNFs++NzuzAEet+4mP7qtPVrh2NhDgSwuKq/aYh9cSC0OkN2sYOZqTSkMtt/Y TbPQ== 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=M77Wzzy8TacgRzejR5rXO6K4BybMH7Jtom+GhKe2B0U=; b=YCo33Y77nLQK6zIW49vlLKQ+6eS4Fd2f5Lh4PHDGkmKwC48J3K0IwT9KYilbLANVCj l5MUVu47lN2f4jF3EkSOry3xKuLyaVXV0rBxKDWHTW5iSUB50LGKQjgJBB79qf/T7yIy RJorWtf9mghQKOOoyCanngrFy0LANuErrF7sD3nyPkxpMhxZ2EXaMWX37Qam2uWdp7Mj jxZI1OCSsABeOEHS0ZichJwscyGUOM8Kb4kqO8oJArpKt/Z9lF6l80vDVmdeF+cqsn4X QOxrcjre3rCsji9uA5bhqqvA2kedMcg/eFAT8a5OXjERBQwjnwd0jsT/OyPNS/jDp5NH +k2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cEnfOXHV; 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 i7-20020a50fc07000000b0045bfaaab6d1si3170647edr.48.2022.11.03.22.45.12; Thu, 03 Nov 2022 22:45: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=cEnfOXHV; 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 S231278AbiKDFlh (ORCPT + 99 others); Fri, 4 Nov 2022 01:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbiKDFlc (ORCPT ); Fri, 4 Nov 2022 01:41:32 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45B0E275E4; Thu, 3 Nov 2022 22:41:31 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id q1so3513562pgl.11; Thu, 03 Nov 2022 22:41:31 -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=M77Wzzy8TacgRzejR5rXO6K4BybMH7Jtom+GhKe2B0U=; b=cEnfOXHV0UQH6PZUCLoulKGFACo4g6/DhhbZr/eJ2Jo25T+ShstQwJm6SEdcOSe+NA JkLsoIjzKq0TffGczU7CyPA0RRjLSjNChFcIVlzpJfymO0M4B0bY77IHoatM7HEhOLE5 YlKou+aGOHiHqpIhov+Dz/OcnAwRzCHCwcJ5Lxu8yHWX8dlizr2Te0sToIiVlDVHVubE MUFzXJkySFvE11h1x6U4NwkkXh8Gk78Yxc33+NgMtkUW6pdHmy5AUIA/McaPbiux2UEx y8TH03zQ9+GzAlIxHUSqEGVNcJUklHoiXBO2yaGTy8U7Yu4oc6OewJaAQ9alofsVkSdX FeDg== 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=M77Wzzy8TacgRzejR5rXO6K4BybMH7Jtom+GhKe2B0U=; b=ox7UAoDKIJu2UbCj312cHQdUpvRaYbFqjOd5wuwNzEKobQgC2IBRz28xDAG4GdQPtO RqFQpbrrUSu8TbVcKQCeAy5RKGoav7JGYe8kByq1agyxLfTvM4k9y7gKpRabnPVn13Ch +qlTfO7d82fsh4Mpb8F0VGf1McTfL6/xegp79nPKhxh9XKwDzqAYzAHNAdui/3eQDuvd oikSOuEXywGOJgblItM2Ulcli+jES2Ei0NgrITlhvOwCM9HAH3r9SItmrrpKT6Ki4ikU ++XGo04v59znN1bUDW+arXbb/Tt7CGcvxZg1nNYYjFwTu0CvnJGAdE7iASNEFpi0dNtD AMAw== X-Gm-Message-State: ACrzQf3vzhPXNXdhb53E8XAvzJ4WyLP40IxvdixA6CcJXSTuFQxLTeRR o+c4eRLYhZFybjhwOIFB0I4= X-Received: by 2002:aa7:9e85:0:b0:56c:683b:d31f with SMTP id p5-20020aa79e85000000b0056c683bd31fmr34165085pfq.48.1667540490781; Thu, 03 Nov 2022 22:41:30 -0700 (PDT) Received: from localhost.localdomain ([116.128.244.169]) by smtp.gmail.com with ESMTPSA id q15-20020aa7960f000000b0056bdc3f5b29sm1684043pfg.186.2022.11.03.22.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 22:41:30 -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 v2 2/2] PM: hibernate: add check of preallocate mem for image size pages Date: Fri, 4 Nov 2022 13:41:19 +0800 Message-Id: <20221104054119.1946073-3-tgsp002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221104054119.1946073-1-tgsp002@gmail.com> References: <20221104054119.1946073-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?1748543194304118151?= X-GMAIL-MSGID: =?utf-8?q?1748543194304118151?= 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; The detailed debugging data is as follows: image_size: 3225923584, totalram_pages: 1968948 in hibernate_reserved_size_init(); in hibernate_preallocate_memory(): code pages = minimum_image_size(saveable) = 717992, at this time(line): count: 2030858 avail_normal: 2053753 highmem: 0 totalreserve_pages: 22895 max_size: 1013336 size: 787579 saveable: 1819905 When the code executes to: pages = preallocate_image_memory(alloc, avail_normal), at that time(line): pages_highmem: 0 avail_normal: 1335761 alloc: 1017522 pages: 1017522 So enter the else branch judged by (pages < alloc), When executed to size = preallocate_image_memory(alloc, avail_normal): alloc = max_size - size = 225757; size = preallocate_image_memory(alloc, avail_normal) = 168671, That is, preallocate_image_memory() does not apply for all alloc memory pages, because highmem is not enabled, and size_highmem will return 0 here, so there is a memory page that has not been preallocated, so I think a judgment needs to be added here. But what I can't understand is that although pages are not preallocated enough, "pages -= free_unnecessary_pages()" in the code below can also discard some pages that have been preallocated, so I am not sure whether it is appropriate to add a judgment here. Cc: stable@vger.kernel.org Signed-off-by: xiongxin Signed-off-by: huanglei --- kernel/power/snapshot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index c20ca5fb9adc..546d544cf7de 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1854,6 +1854,8 @@ int hibernate_preallocate_memory(void) alloc = (count - pages) - size; pages += preallocate_image_highmem(alloc); } else { + unsigned long size_highmem = 0; + /* * There are approximately max_size saveable pages at this point * and we want to reduce this number down to size. @@ -1863,8 +1865,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); - pages += pages_highmem + 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 += pages_highmem + size_highmem + size; } /*