From patchwork Wed Sep 8 10:26:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuyuntao X-Patchwork-Id: 12480847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7212BC4332F for ; Wed, 8 Sep 2021 10:29:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E766D60F01 for ; Wed, 8 Sep 2021 10:29:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E766D60F01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D6AD76B0071; Wed, 8 Sep 2021 06:29:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1A366B0072; Wed, 8 Sep 2021 06:29:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C089B900002; Wed, 8 Sep 2021 06:29:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id B20246B0071 for ; Wed, 8 Sep 2021 06:29:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 778FE2A4A8 for ; Wed, 8 Sep 2021 10:29:01 +0000 (UTC) X-FDA: 78564033282.20.38A45BC Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf05.hostedemail.com (Postfix) with ESMTP id DDD85504D32D for ; Wed, 8 Sep 2021 10:29:00 +0000 (UTC) Received: from dggeml765-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H4JHm3rVyzVrqv; Wed, 8 Sep 2021 18:28:04 +0800 (CST) Received: from huawei.com (10.175.124.27) by dggeml765-chm.china.huawei.com (10.1.199.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 8 Sep 2021 18:28:55 +0800 From: Liu Yuntao To: , , CC: , , , , Subject: [PATCH] fix judgment error in shmem_is_huge() Date: Wed, 8 Sep 2021 18:26:48 +0800 Message-ID: <20210908102648.2326917-2-liuyuntao10@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210908102648.2326917-1-liuyuntao10@huawei.com> References: <20210908102648.2326917-1-liuyuntao10@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 dggeml765-chm.china.huawei.com (10.1.199.175) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: DDD85504D32D Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of liuyuntao10@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liuyuntao10@huawei.com X-Rspamd-Server: rspam01 X-Stat-Signature: kqrdpj6wikbhbeq9uc3awnhpkad9f13s X-HE-Tag: 1631096940-566436 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: In the case of SHMEM_HUGE_WITHIN_SIZE, the page index is not rounded up correctly. When the page index points to the first page in a huge page, round_up() cannot bring it to the end of the huge page, but to the end of the previous one. an example: HPAGE_PMD_NR on my machine is 512(2 MB huge page size). After allcoating a 3000 KB buffer, I access it at location 2050 KB. In shmem_is_huge(), the corresponding index happens to be 512. After rounded up by HPAGE_PMD_NR, it will still be 512 which is smaller than i_size, and shmem_is_huge() will return true. As a result, my buffer takes an additional huge page, and that shouldn't happen when shmem_enabled is set to within_size. Fixes: f3f0e1d2150b2b ("khugepaged: add support of collapse for tmpfs/shmem pages") Signed-off-by: Liu Yuntao --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 88742953532c..5747572859d1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -490,7 +490,7 @@ bool shmem_is_huge(struct vm_area_struct *vma, case SHMEM_HUGE_ALWAYS: return true; case SHMEM_HUGE_WITHIN_SIZE: - index = round_up(index, HPAGE_PMD_NR); + index = round_up(index + 1, HPAGE_PMD_NR); i_size = round_up(i_size_read(inode), PAGE_SIZE); if (i_size >= HPAGE_PMD_SIZE && (i_size >> PAGE_SHIFT) >= index) return true;