From patchwork Sat Jun 25 09:28:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12895282 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 3CE65C43334 for ; Sat, 25 Jun 2022 09:28:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B82D68E0297; Sat, 25 Jun 2022 05:28:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0A8E8E0296; Sat, 25 Jun 2022 05:28:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 982558E0297; Sat, 25 Jun 2022 05:28:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 844098E0296 for ; Sat, 25 Jun 2022 05:28:25 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 57B3DA22 for ; Sat, 25 Jun 2022 09:28:25 +0000 (UTC) X-FDA: 79616232570.12.89D60DD Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf21.hostedemail.com (Postfix) with ESMTP id 13FA01C0005 for ; Sat, 25 Jun 2022 09:28:23 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LVTCY3TJdzkWZJ; Sat, 25 Jun 2022 17:27:05 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 25 Jun 2022 17:28:20 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 4/7] mm/khugepaged: minor cleanup for collapse_file Date: Sat, 25 Jun 2022 17:28:13 +0800 Message-ID: <20220625092816.4856-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220625092816.4856-1-linmiaohe@huawei.com> References: <20220625092816.4856-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656149304; 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:in-reply-to:references:references; bh=MigINiVCYf6Y+PJ3jdEJsTuZ9pc4e7YYCuwmgzejF0Q=; b=ckOrk9wv6pKvQCdUOlC/PQP25gjS83RIlgWvsAWVg9hRdjifTsbkIUHGrttAVQQP8ro60P 04R+sYaetezs5JnNAnL2R6D2NXtVsYiLkn41CWUGn82sKrySBp2cRfZY5PTcKZ54u3ZlZq DUW2IIdtzMy2h53lQf3AYXn32UJEgvY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656149304; a=rsa-sha256; cv=none; b=UNxbPRya2+1JyGQz2a1uD4lHf9lFHblYv8CIQGWlDqpSmIF5iemozmUPEt4Cd6yrC0EuzV zVGZf4Qp7ZlqoLEVpMNP8dF/MUjxqFNNrhmSDleIQ1JnScqJZCKoqGKzNHpivLXF+mJfqY r349a/o37thiFLuwM5gcjl48MYiXfEw= X-Rspamd-Queue-Id: 13FA01C0005 Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5syxzihmqnjgn4dw3yntwyh8ir11xsdc X-HE-Tag: 1656149303-631221 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: nr_none is always 0 for non-shmem case because the page can be read from the backend store. So when nr_none ! = 0, it must be in is_shmem case. Also only adjust the nrpages and uncharge shmem when nr_none != 0 to save cpu cycles. Signed-off-by: Miaohe Lin Reviewed-by: Zach O'Keefe --- mm/khugepaged.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a36d9746c321..47514f2fabb9 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1852,8 +1852,8 @@ static void collapse_file(struct mm_struct *mm, if (nr_none) { __mod_lruvec_page_state(new_page, NR_FILE_PAGES, nr_none); - if (is_shmem) - __mod_lruvec_page_state(new_page, NR_SHMEM, nr_none); + /* nr_none is always 0 for non-shmem. */ + __mod_lruvec_page_state(new_page, NR_SHMEM, nr_none); } /* Join all the small entries into a single multi-index entry */ @@ -1917,10 +1917,10 @@ static void collapse_file(struct mm_struct *mm, /* Something went wrong: roll back page cache changes */ xas_lock_irq(&xas); - mapping->nrpages -= nr_none; - - if (is_shmem) + if (nr_none) { + mapping->nrpages -= nr_none; shmem_uncharge(mapping->host, nr_none); + } xas_set(&xas, start); xas_for_each(&xas, page, end - 1) {