Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4550732imb; Wed, 6 Mar 2019 16:41:31 -0800 (PST) X-Google-Smtp-Source: APXvYqyMkcAT+MwX/mz90f8m9ebdrwV7goOxtNSHsozMwImu+jZzQtB+wPh/SQZePOCwY08FppOU X-Received: by 2002:a65:4547:: with SMTP id x7mr1338442pgr.350.1551919291188; Wed, 06 Mar 2019 16:41:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551919291; cv=none; d=google.com; s=arc-20160816; b=Ht0Pc5sNNxkdIq2Ytjv4vQwGQQyDbQB8XjUN0+VJ2Y7P+shwS+nitwk+Lq6nkBG12K St3ns9BMuCur7HB3cO7l+mEBC2q2m4TyytGpfoRl0gkrjwVDq5sysuvpkpvY3QR5mKQF AnGHYukbu9Nb3hK4Y/ZGG0Sa0ncAnKxPvxrBq2eQaoOGXEEQP8is/m1F8LJUBeBO4b+k lWR4vZYc/hyznEAIgw48btt9gEctNPFIlyuUajyWFInSpmVWLa1O9P1RMCyq/sKNX/Dx kGHeQfVWI1z9KNS/bF8qvTh9fHoTa2JDMfSAkNuHghDKhH2M8A3O69nFy5o+aF1sUk6R wUpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=XCmbGIXK9VORoIc+UM5FEN48dSgza63HkuNymhdproE=; b=kUX3jw9Rw9Qi2Zr1KH4g+42G5oXi3qIhHeBG+HSRzrah4XEuVFbfoj4Fy3BWDvvt2D lRy9ZVcjobuSnkulpLrg0sYInRvv15ZlTBWjElyJdndIEy+rdO1PaMigWZNLrxF9o6nt v6ZmDKhYXdiXYNi/86EA/mabRhCQLeGzJs4tbVXm7O8w8IKZR+Ep+HQcVJTI4cHHlWc7 fqfC7ZTsFd0I4ffH2pE73WsLvqRDE9vD3LEkFJdYnn9TyJb4YNFnRtoGAgXuE9AUsR0a iW5qSW773DSabVJhldYilmD3pApy3mOz1wuuUg0GB1KFf90dTyh50FjuSenB405JGiH5 zQhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q88si2817168pfa.222.2019.03.06.16.41.14; Wed, 06 Mar 2019 16:41:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbfCGAky (ORCPT + 99 others); Wed, 6 Mar 2019 19:40:54 -0500 Received: from nautica.notk.org ([91.121.71.147]:56907 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbfCGAkx (ORCPT ); Wed, 6 Mar 2019 19:40:53 -0500 Received: by nautica.notk.org (Postfix, from userid 1001) id A4A33C009; Thu, 7 Mar 2019 01:40:51 +0100 (CET) Date: Thu, 7 Mar 2019 01:40:36 +0100 From: Dominique Martinet To: Jiri Kosina Cc: Andrew Morton , Vlastimil Babka , Linus Torvalds , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Peter Zijlstra , Greg KH , Jann Horn , Andy Lutomirski , Dave Chinner , Kevin Easton , Matthew Wilcox , Cyril Hrubis , Tejun Heo , "Kirill A . Shutemov" , Daniel Gruss Subject: Re: [PATCH 1/3] mm/mincore: make mincore() more conservative Message-ID: <20190307004036.GA16785@nautica> References: <20190130124420.1834-1-vbabka@suse.cz> <20190130124420.1834-2-vbabka@suse.cz> <20190306151351.f8ae1acae51ccad1a3537284@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jiri Kosina wrote on Thu, Mar 07, 2019: > > I'm not sure this is correct in all cases. If > > > > addr = 4095 > > vma->vm_end = 4096 > > pages = 1000 > > > > then `end' is 4096 and `(end - addr) << PAGE_SHIFT' is zero, but it > > should have been 1. > > Good catch! It should rather be something like > > unsigned long pages = (end >> PAGE_SHIFT) - (addr >> PAGE_SHIFT); That would be 0 for addr = 0 and vma->vm_end = 1; I assume we would still want to count that as one page. I'm not too familiar with this area of the code, but I think there's a handy macro we can use for this, perhaps DIV_ROUND_UP(end - addr, PAGE_SIZE) ? kernel/kexec_core.c has defined PAGE_COUNT() which seems more appropriate but I do not see a global equivalent #define PAGE_COUNT(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT) -- Dominique