From patchwork Thu Aug 3 12:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13339888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F833C04E69 for ; Thu, 3 Aug 2023 12:04:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA40828023E; Thu, 3 Aug 2023 08:04:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A54BC28022C; Thu, 3 Aug 2023 08:04:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 969B728023E; Thu, 3 Aug 2023 08:04:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 886EA28022C for ; Thu, 3 Aug 2023 08:04:17 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 48DE616115E for ; Thu, 3 Aug 2023 12:04:17 +0000 (UTC) X-FDA: 81082660554.26.10CA2FD Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf02.hostedemail.com (Postfix) with ESMTP id DBFB7800DE for ; Thu, 3 Aug 2023 12:04:06 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691064247; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=3n5RrrRHazgX5xAmcfCJMWLv1KaNlhDaODqebMN3exM=; b=cgO99vYxDLmJoriaRny+cSPu35K/AQScAkq3F3w5n/iK+4xtRw0nKkmYxZ73kuEERlcnaS zZ8t+y3NLgQGnRAlawcF8HtWSB29okyqyaTIV+6vLsYTZhR7aCcxk+xGuNCemUUvyAhajd 5hRgxzeZVbleVlmTFcL3KsAdiUfZglE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691064247; a=rsa-sha256; cv=none; b=jA5mUB0K+HqORUnsKb10v5ia0qEnRKPRugMvD9DjD2oqVI6Z9I/kHrl3vDg+B1BsDlzQwH gLSzDG2bqlOlMsk0WVnGSy+6ac546E1RgmZi58N0QEGT8VrYFmGgaRzgDaRZwaG1HfgEvk ptqm5Wvs2KGrdqcHNfbYGRwK94K32HQ= Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RGnVz6jWBzJr9H; Thu, 3 Aug 2023 20:01:15 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 3 Aug 2023 20:03:59 +0800 From: Ruan Jinjie To: , Mike Kravetz , Muchun Song , Andrew Morton CC: Subject: [PATCH -next] mm: use helper function put_resv_map() Date: Thu, 3 Aug 2023 20:03:12 +0800 Message-ID: <20230803120312.945774-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: DBFB7800DE X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 8gbybaty48hxwpjusc753qq9io7rpggq X-HE-Tag: 1691064246-462187 X-HE-Meta: U2FsdGVkX18kMBk5yVoLPiNmWxmnJ3Xg86dcFSvY6PwzSg1901lr6Y39oLWB8d8xvI8NRIN7NmpOjBbmq5wK3jA5zvhhDs7/gogNZW6EeIOiyWMjfg0MNzSoNu4yslpy+r6BmRtTUV9RjZMsXTZUE4tw6SXhogd4rz5bl4n/c4CmdP0tqu9a2OsTA7gttw8b2218fdY2j4IVIPftN6Zarv8hB0jOYyxynznSGZ43q4I5FWD6VN2nDaPAZSdynha8rvXJ0V8wndCJkAjrueGeL3r5EpXWye92LDDGJ4Si5ttkQIQUPNzy7TU3A3cHK7lDxyUdlBwKg1ZBUIqI5DNbudjfFioGXytrb8rx8T1V8HII59Bs71ul+nIrX0NxvbVvGQXRjG/UIYQ4iwTkekpCr31EOHXemFaTYEn24IHfxBNXNo43ObdIsVlYqRBqU5/2Y3lwImfLweVyUzQytJmLkqom2ecm7XmqIYfTkS9YxFP6EGK4aom1uE1h6XGOOKfUCfq001rxybE4/6G6+DvMPn7ZO2wS0PF902X/1zCh59rxAq0U0/+yU8ZyZtE2MvPfgUdBA00ETrN9OmdnLWN2tLdyMhs0G+0oqkselXDHCPO0HOFsvSGWvqnC3cnCDlPE5oJ+2tvmfbJfxLU4KNJbJw615Ty/5ZJWo0pE5nZ6bGDJOE7FOuzbTk6Exo244T/EpxuaDQZ0z1ReyCpizAw2HQkmn7PFsQ+plyqIQRQhL1R/GWQJnV/nGTvbfOs8H/yk1GihxrEszv5GhmVhI+y9lAkgGVFnkge39wIuNrbHas7SNTNEjTQCvYo/lzjU5ETouFj1w7x2dlIjDw1AaSszoKuZSrTIXgSABN40Ws+ieeVjHVh2K1UNHMoYi1rWWBLyEjEt9LU2SqrGecqPKkznanDOKNRlFxi4albwnQqUd8PPdlEzIV814EmKW805XZY3KKRsWF8svacU6N11aD6 DfIP4k1x hljtOXxN8nswG657DBGpM1Tp2XF7Eo4mv0x5z29yaqE7jMQSe+xo2B2I+yFuzishpBgYGEO0yARcqfxfXiW5z50ra9tw+044R3sjCMBXMdmsUWBKrYvZ31j7mT8sVEVmPj4jLVZys3MFB36QgZ/SdmIVIOCEANRqEvY6jZhqDf5pmjr6tJDC8irGW+pUOSZhOFEpiPHuaXZHXv8nwsIX3G8GWLgYKTMoV+8fX X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This code is already duplicated 3 times, use helper function put_resv_map() to release reserved and allocated regions instead of open code it to help improve code readability a bit. No functional change involved. Signed-off-by: Ruan Jinjie --- mm/hugetlb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e327a5a7602c..bf1c900b753b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1100,6 +1100,11 @@ void resv_map_release(struct kref *ref) kfree(resv_map); } +static inline int put_resv_map(struct resv_map *resv) +{ + return kref_put(&resv->refs, resv_map_release); +} + static inline struct resv_map *inode_resv_map(struct inode *inode) { /* @@ -1201,7 +1206,7 @@ void clear_vma_resv_huge_pages(struct vm_area_struct *vma) if (reservations && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) { resv_map_put_hugetlb_cgroup_uncharge_info(reservations); - kref_put(&reservations->refs, resv_map_release); + put_resv_map(reservations); } hugetlb_dup_vma_private(vma); @@ -4905,7 +4910,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma) hugetlb_acct_memory(h, -gbl_reserve); } - kref_put(&resv->refs, resv_map_release); + put_resv_map(resv); } static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr) @@ -6850,7 +6855,7 @@ bool hugetlb_reserve_pages(struct inode *inode, if (chg >= 0 && add < 0) region_abort(resv_map, from, to, regions_needed); if (vma && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) - kref_put(&resv_map->refs, resv_map_release); + put_resv_map(resv_map); return false; }