From mboxrd@z Thu Jan 1 00:00:00 1970 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 6C02BC433EF for ; Thu, 16 Jun 2022 06:10:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C8386B0073; Thu, 16 Jun 2022 02:10:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 078238D0002; Thu, 16 Jun 2022 02:10:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA9908D0001; Thu, 16 Jun 2022 02:10:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DCEB86B0073 for ; Thu, 16 Jun 2022 02:10:56 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A06756146F for ; Thu, 16 Jun 2022 06:10:56 +0000 (UTC) X-FDA: 79583075712.19.7DCA60C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf09.hostedemail.com (Postfix) with ESMTP id AEAB2140041 for ; Thu, 16 Jun 2022 06:10:55 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LNsFT1qy1zjYCb; Thu, 16 Jun 2022 14:09:17 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) 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; Thu, 16 Jun 2022 14:10:48 +0800 Subject: Re: [PATCH 4/7] mm/khugepaged: minor cleanup for collapse_file To: Yang Shi , Zach O'Keefe CC: Andrew Morton , Andrea Arcangeli , Matthew Wilcox , Vlastimil Babka , David Howells , NeilBrown , Alistair Popple , David Hildenbrand , Suren Baghdasaryan , Peter Xu , Linux MM , Linux Kernel Mailing List References: <20220611084731.55155-1-linmiaohe@huawei.com> <20220611084731.55155-5-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Thu, 16 Jun 2022 14:10:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655359856; a=rsa-sha256; cv=none; b=SNOivsnpwjml3XtnD537sryAM8ie2aPnEOBcSYxB3EBzzErsBZtSnhI2sJ6djR1BwvUpTU WaOA2ucmLY9ViJNoZbeRue6YkXaXlwX40acGOof+wFjHP5IwSGFJDkyYPVjg/wnLZE9qso la/gHpUTUllFa7luT2awTtjtPeVa4Ag= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655359856; 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=87M6zM76xBEf+9r2sSkXJRAd8L38EpnPX6GMQTggwgo=; b=Blr9gjpZo86Q4lX1KvdhOQll28Bu6AAXRxlCD5gEsnYKX8djkmBarRjROQ1uZGW4f05DlC NFLhOZOKj4uJFDLfpJwii6ONjXhZDY+r+SaEpVjhGLLyLQlaaJTzhJ0XFKaSG2PsEWfSdK y4WIMRXEoQh4iArLWsTnH8s86hxSuGI= X-Stat-Signature: 3gyassgmwwbw87pog8ag5kd6s71zrfho X-Rspamd-Queue-Id: AEAB2140041 Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1655359855-811349 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: On 2022/6/16 2:18, Yang Shi wrote: > On Wed, Jun 15, 2022 at 8:55 AM Zach O'Keefe wrote: >> >> On 11 Jun 16:47, Miaohe Lin wrote: >>> 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 >>> --- >>> mm/khugepaged.c | 9 ++++----- >>> 1 file changed, 4 insertions(+), 5 deletions(-) >>> >>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >>> index 1b5dd3820eac..8e6fad7c7bd9 100644 >>> --- a/mm/khugepaged.c >>> +++ b/mm/khugepaged.c >>> @@ -1885,8 +1885,7 @@ 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); >>> + __mod_lruvec_page_state(new_page, NR_SHMEM, nr_none); >>> } >> >> >> Might be worth a small comment here - even though folks can see in above code >> that this is only incremented in shmem path, might be nice to say why it's >> always 0 for non-shmem (or conversely, why it's only possible to be non 0 on >> shmem). > > Agreed, better to have some comments in the code. Will try to add comments in next version. Thanks both! > >> >>> >>> /* Join all the small entries into a single multi-index entry */ >>> @@ -1950,10 +1949,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) { >>> -- >>> 2.23.0 >>> >>> >> >> Otherwise, >> >> Reviewed-by: Zach O'Keefe >> > . >