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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B2D10C433EF for ; Wed, 8 Sep 2021 14:58:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 478DC610FF for ; Wed, 8 Sep 2021 14:58:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 478DC610FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C03296B006C; Wed, 8 Sep 2021 10:58:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB3736B0071; Wed, 8 Sep 2021 10:58:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7A286B0072; Wed, 8 Sep 2021 10:58:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 99F2C6B006C for ; Wed, 8 Sep 2021 10:58:48 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4623B1807CAA4 for ; Wed, 8 Sep 2021 14:58:48 +0000 (UTC) X-FDA: 78564713136.12.3235E20 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by imf26.hostedemail.com (Postfix) with ESMTP id EBB6A20019C6 for ; Wed, 8 Sep 2021 14:58:47 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id m4so4012612ljq.8 for ; Wed, 08 Sep 2021 07:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7ctzyqeUORnBgzeTvVfI+qTP2OEJKYVtguuxCX7NuxM=; b=zFA0ZaBgmO5LxN1vr2QeBoXbpnRWzRS0LHNbEmhSdjv4YQmk8kdw7UioMtotKRf9RP Y7lTMX7xmKkcvYRKt6xW9JeAjFHC0+VgNR3FjdWQs8QT7CxVpticq1ts+ZkIKv6wHYxj 8O9hfsakmeTwu20Lhu883yh2hFmfbI30eEpyJGkkL06J/Dv9Xg9AmNP/GyZf2nmgjnSi wlmusu2SUFJTsosf9oGy7szL6oCIgYivENkT8UzxUD33T6oPU+6hHF3mVlKRE9KkeuYi N0yfNwEeCsciTZaHQ6DWGsYSo84lyV7USAi+2enL1SlyJmlybf3dTXQzJeiQ4c2ndGMa PD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7ctzyqeUORnBgzeTvVfI+qTP2OEJKYVtguuxCX7NuxM=; b=bxmEg+l/ohhtHSGG8u2BiBECt6dDFpJanwjB5X1XHjTk3FWwJPriZv4aeEau0Tx3uO CU9Y6XpzRItB+bbcTNlKjhDC50iDXhRH3j5AorbytrfiIpH9QjvC8RGtGRntaX+Asfze Gqqe/EaYldsTNg8pFN2zBnJhi3SKvHRxpFD0yZMlCEgbnp5XcELyjU6Yw9zTICmh6ZUc FkQz5F6P0hkCBJQ8GBKiwGF87Beo9X83udJvzw8MAPIfsRsEsPVv5FxR05oyoHuLvpuy /g4aEs5Z3Cg0D9VOUzdfb+c4k9Voyn6/Ba0A+KVDq4BLF79KFAB8YfssIg+PC7WGRdBT 2P+g== X-Gm-Message-State: AOAM531/HzA6RfwEAy1OTkAFemw8luDp8i7AnNvZACloWEuO2nENnZPD 4yOzz2pDcYR7minSIo4Ej218HQ== X-Google-Smtp-Source: ABdhPJyTH3Ocl2mWgKQz+uDdKdKdPGDlx7IKI6iwhxK2uCiTqm0MmvrkHlwK0IL46lI19PhlSIadsA== X-Received: by 2002:a2e:b8d2:: with SMTP id s18mr3085498ljp.529.1631113126303; Wed, 08 Sep 2021 07:58:46 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n25sm212456lfe.125.2021.09.08.07.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 07:58:45 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 7BD21102F38; Wed, 8 Sep 2021 17:58:44 +0300 (+03) Date: Wed, 8 Sep 2021 17:58:44 +0300 From: "Kirill A. Shutemov" To: Liu Yuntao Cc: hughd@google.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, wuxu.wu@huawei.com, liusirui@huawei.com, windspectator@gmail.com Subject: Re: [PATCH] fix judgment error in shmem_is_huge() Message-ID: <20210908145844.wqkyfuizqaj5mmrj@box> References: <20210908102648.2326917-1-liuyuntao10@huawei.com> <20210908102648.2326917-2-liuyuntao10@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210908102648.2326917-2-liuyuntao10@huawei.com> Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=zFA0ZaBg; spf=none (imf26.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.172) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EBB6A20019C6 X-Stat-Signature: znmepqp5ktitut85h1xdi3fg9a1zrhzk X-HE-Tag: 1631113127-937209 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 Wed, Sep 08, 2021 at 06:26:48PM +0800, Liu Yuntao wrote: > 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) With the change, the condition can be simplified to if (i_size >> PAGE_SHIFT >= index) right? > return true; > -- > 2.23.0 > -- Kirill A. Shutemov