Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp385488pxb; Wed, 8 Sep 2021 03:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAv4MskTo6HUhm6EZB3BwKwVRdtqA0efyVm2nbWLeerBVcoVWiTJT1jkcTH5zRRCFsX2pn X-Received: by 2002:a05:6e02:1568:: with SMTP id k8mr2359095ilu.34.1631097111839; Wed, 08 Sep 2021 03:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631097111; cv=none; d=google.com; s=arc-20160816; b=JwdDA+oNGpnAvR/qFI2c9GwHe2xn4XMJT8OaVauct3pM4T2eJba7EcvTlNfk105iKE 77wiEn/WFH9Z4EKEfxdqJJ2kssAVRswcI6lCEHIKRARTbNsMB4j+8jzPiXvzmB8B/77t fOKIUL+5wV+NjXrsu1xcJgxrxSrqYfptAaIntD0HU3H4edcMOVPtzsuF4Te0cvRqIkxd +0N4e9XfzF7tyj6de/soZowZz8VN4LGLxCOHTN9qd+SG256LVcDHI/L/zx7wIafSgmUi dvvCFcCoqnUvt8BhqRgdjegTY+W7VGi0O4mUNDvXJ5JkSNsxrNlTJOjhSSKTlNrnUiKL /YWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+gtLRC4nyTurw+8+xQ3tqQ8QcwUjCTATwG6psx8Da/E=; b=FgpoKkrDURwKotypn8wHI7a/kFBP6UpzbuE45raT5ywr5hejJ6ePDz6Z97Nonnr+kf fVDAfDjZINApS6xD8q5i2dJKFNBB5X49K73wR6ID9FGTJJ0kGY8h1g89yS0Q2MagvhNN ZnXZLlRBC0thEg98Rf5TC6jSU4S13661x/o4tKwiXekwqkoo4LG6ZDqwuR3/jl/HMgsL 3zPGpAoKFNvqdI6bcdlaZL5CSbotV5rv3mDtp0YicgmemASzXgUKZP9ZuSDu8oPSzZme U0yFwTobRS0sw9PkB2toxaGVexQE/bQqOKrczPxPPrKJ3JBlSg/fOsqoEN5ABg6P5eTc nhSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si1523881ilo.64.2021.09.08.03.31.10; Wed, 08 Sep 2021 03:31:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348888AbhIHKaH (ORCPT + 99 others); Wed, 8 Sep 2021 06:30:07 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:9015 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245727AbhIHKaF (ORCPT ); Wed, 8 Sep 2021 06:30:05 -0400 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.23.0