From patchwork Mon May 22 05:43:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: BaoJun Luo X-Patchwork-Id: 9739615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C1E5760388 for ; Mon, 22 May 2017 05:44:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A67F228638 for ; Mon, 22 May 2017 05:44:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97B9728625; Mon, 22 May 2017 05:44:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00, MSGID_MULTIPLE_AT, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E87B728625 for ; Mon, 22 May 2017 05:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbdEVFoS convert rfc822-to-8bit (ORCPT ); Mon, 22 May 2017 01:44:18 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:42978 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751670AbdEVFoR (ORCPT ); Mon, 22 May 2017 01:44:17 -0400 Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20170522054415epoutp03fd10d335ea311f20c2768cfb8ca9ea14~A11lyIElK0508205082epoutp03V; Mon, 22 May 2017 05:44:15 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.42.57]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170522054415epcas1p33731460680cda91d995961e8de470551~A11ln2xRF1036010360epcas1p3c; Mon, 22 May 2017 05:44:15 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id FA.77.03717.FAA72295; Mon, 22 May 2017 14:44:15 +0900 (KST) Received: from epsmgms2p1.samsung.com (unknown [182.195.42.79]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170522054414epcas1p38b221b576b6f304c911a196457e248fe~A11lXA1oZ2898528985epcas1p38; Mon, 22 May 2017 05:44:14 +0000 (GMT) X-AuditID: b6c32a39-f790c6d000000e85-e5-59227aaf863d Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 92.3A.02179.EAA72295; Mon, 22 May 2017 14:44:14 +0900 (KST) Received: from luobaojun ([109.123.103.41]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OQC00HZTAK5TF00@mmp2.samsung.com>; Mon, 22 May 2017 14:44:14 +0900 (KST) From: BaoJun Luo To: rjw@rjwysocki.net, pavel@ucw.cz Cc: linux-pm@vger.kernel.org Subject: [PATCH] PM/hibernate: Free memory occupied by the memory bitmap when hibernation failed Date: Mon, 22 May 2017 13:43:17 +0800 Message-id: <"002101d2d2be$71fc1210$55f43630$@luo"@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: 8BIT X-Mailer: Microsoft Office Outlook 12.0 Thread-index: AdLSvkye4hoDLZPUTAOm9hLmKRXoSQ== Content-language: zh-cn x-cr-hashedpuzzle: Bjhb BlcY Fkij Gp09 HZeQ IrUu RTIJ WfSo ZyVS aY4/ b7Y3 d9un e46Q fRtv gUlr jkrP; 3; bABpAG4AdQB4AC0AcABtAEAAdgBnAGUAcgAuAGsAZQByAG4AZQBsAC4AbwByAGcAOwBwAGEAdgBlAGwAQAB1AGMAdwAuAGMAegA7AHIAagB3AEAAcgBqAHcAeQBzAG8AYwBrAGkALgBuAGUAdAA=; Sosha1_v1; 7; {2FD9E783-F027-45B9-B1E1-167EA78C7CD8}; YgBhAG8AagB1AG4ALgBsAHUAbwBAAHMAYQBtAHMAdQBuAGcALgBjAG8AbQA=; Mon, 22 May 2017 05:43:11 GMT; WwBQAEEAVABDAEgAXQAgAFAATQAvAGgAaQBiAGUAcgBuAGEAdABlADoAIABGAHIAZQBlACAAbQBlAG0AbwByAHkAIABvAGMAYwB1AHAAaQBlAGQAIABiAHkAIAB0AGgAZQAgAG0AZQBtAG8AcgB5ACAAYgBpAHQAbQBhAHAAIAB3AGgAZQBuACAAaABpAGIAZQByAG4AYQB0AGkAbwBuACAAZgBhAGkAbABlAGQA x-cr-puzzleid: {2FD9E783-F027-45B9-B1E1-167EA78C7CD8} X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmleLIzCtJLcpLzFFi42LZdlhTT3d9lVKkwe+X/Bafe48wWtw9dZTN 4szpS6wOzB5brrazeKxY/Z3d4/MmuQDmKC6blNSczLLUIn27BK6M9ucP2AomyFSs3XKWqYFx s3gXIyeHhICJxMtDqxghbDGJC/fWs3UxcnEICexglLi89yaU85lR4vGnBkaYjrudjewgtpDA WkaJu++LIIreMkocaljHBJJgE9CUmH5yJ5gtIqAs8ernbhYQm1lARuL3i0XMXYwcHMICSRIf upJAwiwCqhJP320Fm8krYC9xfy3EGF4BQYkfk+9BtWpKbN29nh3C1pZ48u4CK8gYCQF1iUd/ dUFMEQE9iR1dfBAV4hIbj9xiAblMQuAHi8Tbh5vZIM43lVh6dA0rRKKdXeLdzNlMEHNkJTYd YIaocZH40/CWCcIWlnh1fAs7hC0l0fjyIRNEbzejxOodV5khnCmMEtOv3WaFqLKW2LzmF9Sh fBLvvvZAHcor0dEmBFHiIfH38iPWCYxKs5C8OQvJm7OQvDkLyUMLGFlWMYqlFhTnpqcWGxaY 6hUn5haX5qXr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brM7KZrfAvfLjO64fSQq+hkG/H3VxPZGLPXg9+fd1Tif9jWtNBFaUKUx6eeqQssSy GaWGsf8yJi9Jmmnxd5v33M2bviuxFGckGmoxFxUnAgAslkVuvwIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170522054414epcas1p38b221b576b6f304c911a196457e248fe X-Msg-Generator: CA X-Sender-IP: 182.195.42.79 X-Local-Sender: =?UTF-8?B?6aqG5a6d5L+KG1NSQy1OYW5qaW5nLU1vYmlsZSBTb2x1dGlv?= =?UTF-8?B?biBMYWIb7IK87ISx7KCE7J6QG+mrmOe0muW3peeoi+W4iA==?= X-Global-Sender: =?UTF-8?B?QmFvanVuIEx1bxtTUkMtTmFuamluZy1Nb2JpbGUgU29sdXRp?= =?UTF-8?B?b24gTGFiG1NhbXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG0NIURtDMTBFRDAzRUQwMzAzMjk=?= CMS-TYPE: 101P X-CMS-RootMailID: 20170522054414epcas1p38b221b576b6f304c911a196457e248fe X-RootMTR: 20170522054414epcas1p38b221b576b6f304c911a196457e248fe References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From 17f24d918f4c2ac292ec2aaeb13a527a10b91f80 Mon Sep 17 00:00:00 2001 From: "baojun.luo" Date: Fri, 19 May 2017 17:58:21 +0800 Subject: [PATCH] PM/hibernate: Free memory bitmap by orig_bm/copy_bm hold when hibernation failed During prepare for hibernation operation, if there is an error, the image bitmap memory needs to be released. This patch will make sure the bitmap memory be released when hibernation error Signed-off-by: baojun.luo --- kernel/power/hibernate.c | 1 + kernel/power/power.h | 1 + kernel/power/snapshot.c | 50 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 9 deletions(-) -- 1.9.1 diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a8b978c..e54ef08 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -743,6 +743,7 @@ int hibernate(void) } Free_bitmaps: + free_image_memory_bitmaps(); free_basic_memory_bitmaps(); Thaw: unlock_device_hotplug(); diff --git a/kernel/power/power.h b/kernel/power/power.h index 7fdc40d..0393bc8 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -108,6 +108,7 @@ static inline void hibernate_image_size_init(void) {} extern int create_basic_memory_bitmaps(void); extern void free_basic_memory_bitmaps(void); +extern void free_image_memory_bitmaps(void); extern int hibernate_preallocate_memory(void); extern void clear_free_pages(void); diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 3b1e0f3..d96c939 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1441,6 +1441,46 @@ static void copy_data_pages(struct memory_bitmap *copy_bm, */ static struct memory_bitmap copy_bm; +/* Helper functions used for the shrinking of memory. */ + +#define GFP_IMAGE (GFP_KERNEL | __GFP_NOWARN) + +/** + * create_image_memory_bitmaps - Create bitmaps to hold image page information. + * + */ +int create_image_memory_bitmaps(void) +{ + int error = 0; + + error = memory_bm_create(&orig_bm, GFP_IMAGE, PG_ANY); + if (error) + goto err_out; + + memset(©_bm, 0, sizeof(struct memory_bitmap)); + error = memory_bm_create(©_bm, GFP_IMAGE, PG_ANY); + if (error) { + memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR); + goto err_out; + } + return 0; +err_out: + return -ENOMEM; +} + +/** + * free_image_memory_bitmaps - Free memory bitmaps holding image page information. + * + */ +void free_image_memory_bitmaps(void) +{ + if(copy_bm.p_list) { + memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR); + memory_bm_free(©_bm, PG_UNSAFE_CLEAR); + pr_debug("PM: Image memory bitmaps freed\n"); + } +} + /** * swsusp_free - Free pages allocated for hibernation image. * @@ -1492,10 +1532,6 @@ void swsusp_free(void) hibernate_restore_protection_end(); } -/* Helper functions used for the shrinking of memory. */ - -#define GFP_IMAGE (GFP_KERNEL | __GFP_NOWARN) - /** * preallocate_image_pages - Allocate a number of pages for hibernation image. * @nr_pages: Number of page frames to allocate. @@ -1695,11 +1731,7 @@ int hibernate_preallocate_memory(void) printk(KERN_INFO "PM: Preallocating image memory... "); start = ktime_get(); - error = memory_bm_create(&orig_bm, GFP_IMAGE, PG_ANY); - if (error) - goto err_out; - - error = memory_bm_create(©_bm, GFP_IMAGE, PG_ANY); + error = create_image_memory_bitmaps(); if (error) goto err_out;